{"record":{"id":"ed3c2aac6c1eb437","repo":"BerriAI/litellm","slug":"error-message-ed3c2a","errorCode":null,"errorMessage":"{error_message}","messagePattern":"\\{error_message\\}","errorType":"http","errorClass":"BaseLLMException","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/rerank/transformation.py","lineNumber":93,"sourceCode":"    def map_cohere_rerank_params(\n        self,\n        non_default_params: dict,\n        model: str,\n        drop_params: bool,\n        query: str,\n        documents: list[str | dict[str, Any]],\n        custom_llm_provider: str | None = None,\n        top_n: int | None = None,\n        rank_fields: list[str] | None = None,\n        return_documents: bool | None = True,\n        max_chunks_per_doc: int | None = None,\n        max_tokens_per_doc: int | None = None,\n        instruction: str | None = None,\n    ) -> dict:\n        pass\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        raise BaseLLMException(\n            status_code=status_code,\n            message=error_message,\n            headers=headers,\n        )\n\n    def calculate_rerank_cost(\n        self,\n        model: str,\n        custom_llm_provider: str | None = None,\n        billed_units: RerankBilledUnits | None = None,\n        model_info: ModelInfo | None = None,\n    ) -> tuple[float, float]:\n        \"\"\"\n        Calculates the cost per query for a given rerank model.\n\n        Input:\n            - model: str, the model name without provider prefix\n            - custom_llm_provider: str, the provider used for the model. If provided, used to check if the litellm model info is for that provider.","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/rerank/transformation.py#L75-L111","documentation":"The rerank error-mapping hook: get_error_class wraps a provider's rerank HTTP error into BaseLLMException(status_code, message=error_message, headers). The literal '{error_message}' is the template — at runtime the exception carries the provider's actual error text, status code and headers from the failed rerank request.","triggerScenarios":"litellm.rerank() against a provider returning 4xx/5xx: bad/missing COHERE_API_KEY (401), wrong model name (404), rate limit (429), malformed documents array (400); the response handler converts the non-2xx into BaseLLMException.","commonSituations":"Missing provider API keys for rerank models; passing documents with mixed invalid types; free-tier rate limits; proxy rerank routes hitting an upstream outage.","solutions":["Catch BaseLLMException and branch on status_code: fix auth for 401/403, model name for 404, backoff for 429/5xx.","Verify the rerank provider env keys (e.g. COHERE_API_KEY) are set for the model in use.","Validate documents are non-empty strings/valid dicts before the call.","Check litellm proxy team settings allow the rerank route and model."],"exampleFix":"# before\ntry:\n    litellm.rerank(model='cohere/rerank-v3.5', query='q', documents=docs)\nexcept Exception as e:\n    print(e)\n\n# after\nfrom litellm.llms.base_llm.chat.transformation import BaseLLMException\ntry:\n    litellm.rerank(model='cohere/rerank-v3.5', query='q', documents=docs)\nexcept BaseLLMException as e:\n    if e.status_code == 429:\n        time.sleep(float(e.headers.get('retry-after', 1)) if e.headers else 1)\n    else:\n        raise","handlingStrategy":"retry","validationCode":"def validate_rerank_inputs(query: str, documents: list) -> None:\n    if not query or not isinstance(query, str):\n        raise ValueError('query must be a non-empty string')\n    if not documents or not all(isinstance(d, (str, dict)) for d in documents):\n        raise ValueError('documents must be non-empty strings or dicts')","typeGuard":"def is_retryable_rerank_error(exc: BaseException) -> bool:\n    return isinstance(exc, BaseLLMException) and exc.status_code in (429, 500, 502, 503, 504)","tryCatchPattern":"try:\n    return litellm.rerank(model=model, query=query, documents=documents)\nexcept BaseLLMException as e:\n    if e.status_code == 429:\n        time.sleep(2)\n        return litellm.rerank(model=model, query=query, documents=documents)\n    if e.status_code in (400, 404):\n        raise ValueError(f'bad rerank request: {e.message}') from e\n    raise","preventionTips":["Pre-validate query/documents shapes before calling rerank.","Set provider API keys in one place and verify at startup.","Wrap rerank calls with jittered backoff for 429s and alert on repeated 5xx."],"tags":["rerank","error-mapping","http-error","upstream"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}