{"record":{"id":"c8bc45365c8b4cb7","repo":"BerriAI/litellm","slug":"error-message","errorCode":null,"errorMessage":"{error_message}","messagePattern":"\\{error_message\\}","errorType":"http","errorClass":"BaseLLMException","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/interactions/transformation.py","lineNumber":278,"sourceCode":"        self,\n        raw_response: httpx.Response,\n        logging_obj: LiteLLMLoggingObj,\n    ) -> CancelInteractionResult:\n        \"\"\"\n        Transform the cancel interaction response.\n        \"\"\"\n\n    # =========================================================\n    # ERROR HANDLING\n    # =========================================================\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        \"\"\"\n        Get the appropriate exception class for an error.\n        \"\"\"\n        from ..chat.transformation import BaseLLMException\n\n        raise BaseLLMException(\n            status_code=status_code,\n            message=error_message,\n            headers=headers,\n        )\n\n    def should_fake_stream(\n        self,\n        model: str | None,\n        stream: bool | None,\n        custom_llm_provider: str | None = None,\n    ) -> bool:\n        \"\"\"\n        Returns True if litellm should fake a stream for the given model.\n\n        Override in subclasses if the provider doesn't support native streaming.\n        \"\"\"\n        return False\n","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/interactions/transformation.py#L260-L296","documentation":"This is not a standalone error but the base error-mapping hook: get_error_class packages a provider's HTTP error into BaseLLMException(status_code, message=error_message, headers). When you see this exception from the interactions path, the literal '{error_message}' template means the provider returned an error response and the generic mapper forwarded its message/status verbatim.","triggerScenarios":"Provider returns 4xx/5xx on an interactions request (invalid API key 401, rate limit 429, bad request 400); the response handler detects the error status and calls get_error_class with the provider's error body, which then surfaces as an exception the caller must catch.","commonSituations":"Auth failures against custom interaction endpoints; upstream 5xx; malformed request payloads the provider rejects; expired tokens on self-hosted gateways.","solutions":["Read the status_code and message on the caught BaseLLMException — they mirror the provider's response (fix the underlying auth/payload issue).","Retry with backoff for 429/5xx status codes.","Verify api_key, api_base and request payload for 4xx codes.","Subclass: override get_error_class to map provider errors to litellm-specific exception types for cleaner handling."],"exampleFix":"# before\ntry:\n    litellm.interactions(...)\nexcept Exception as e:\n    pass  # generic, loses status code\n\n# after\nfrom litellm.llms.base_llm.chat.transformation import BaseLLMException\ntry:\n    litellm.interactions(...)\nexcept BaseLLMException as e:\n    if e.status_code == 429:\n        time.sleep(2); litellm.interactions(...)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_retryable_base_llm_exception(exc: BaseException) -> bool:\n    return isinstance(exc, BaseLLMException) and exc.status_code in (408, 429, 500, 502, 503, 504)","tryCatchPattern":"for attempt in range(3):\n    try:\n        return await litellm.ainteractions(...)\n    except BaseLLMException as e:\n        if e.status_code in (408, 429, 503) and attempt < 2:\n            await asyncio.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Always catch BaseLLMException (not bare Exception) for provider errors so status_code is available.","Retry only idempotent requests and only on 408/429/5xx with backoff.","Log status_code + headers to correlate with upstream incidents."],"tags":["interactions","http-error","error-mapping","upstream"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}