{"record":{"id":"ab9c321cd5c97cc9","repo":"BerriAI/litellm","slug":"error-text-ab9c32","errorCode":null,"errorMessage":"error_text","messagePattern":"error_text","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/completion/handler.py","lineNumber":163,"sourceCode":"                logging_obj.post_call(\n                    api_key=api_key,\n                    original_response=response_json,\n                    additional_args={\n                        \"headers\": headers,\n                        \"api_base\": api_base,\n                    },\n                )\n\n                ## RESPONSE OBJECT\n                return TextCompletionResponse(**response_json)\n        except Exception as e:\n            status_code: Final = getattr(e, \"status_code\", 500)\n            error_headers = getattr(e, \"headers\", None)\n            error_text: Final = getattr(e, \"text\", str(e))\n            error_response: Final = getattr(e, \"response\", None)\n            if error_headers is None and error_response:\n                error_headers = getattr(error_response, \"headers\", None)\n            raise OpenAIError(status_code=status_code, message=error_text, headers=error_headers)\n\n    async def acompletion(\n        self,\n        logging_obj,\n        api_base: str,\n        data: dict,\n        headers: dict,\n        model_response: ModelResponse,\n        api_key: str,\n        model: str,\n        timeout: float,\n        max_retries: int,\n        organization: str | None = None,\n        client=None,\n    ):\n        try:\n            if client is None:\n                openai_aclient = AsyncOpenAI(","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/openai/completion/handler.py#L145-L181","documentation":"The text-completion completion() wraps everything in try/except and converts any exception into an OpenAIError: status from e.status_code (default 500), headers from e.headers or e.response.headers, message from e.text if present else str(e). So this error is the normalized re-raise of any downstream failure — HTTP errors from the server, timeouts, or the 422 missing-params error above.","triggerScenarios":"Any failure inside the OpenAI text-completion request path: upstream 4xx/5xx (httpx.HTTPStatusError carries .text), connection errors (message becomes the exception string), timeouts, or the 'Missing model or messages' validation error.","commonSituations":"Users seeing a wrapped error lose the original exception type; e.g. a 401 from the server shows as OpenAIError with the server's error body text. Common when debugging auth failures, bad api_base, or rate limits on the text-completion path.","solutions":["Read the message: if it contains JSON error body text, that is the upstream server's error — act on it (auth, quota, params).","If the message is an exception string (e.g. 'Connection refused.'), fix network/api_base issues.","Catch OpenAIError and inspect .status_code and .headers to branch on auth (401) vs rate limit (429) vs server (5xx).","Reproduce with curl against the same api_base/key to confirm the upstream behavior."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.text_completion(model=model, prompt=prompt, api_base=base)\nexcept litellm.exceptions.OpenAIError as e:\n    code = getattr(e, \"status_code\", 500)\n    if code == 429:\n        retry_with_backoff()\n    elif code in (401, 403):\n        refresh_credentials()\n    elif code == 422:\n        fix_request_params(e)  # e.g. Missing model or messages\n    else:\n        raise","preventionTips":["Branch on e.status_code, not on message text","Remember the original exception type is lost — log headers too","Reproduce with curl when the message contains an upstream JSON error body"],"tags":["openai","text-completion","error-wrapping","http"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}