BerriAI/litellm · error · OpenAIError
error_text
Error message
error_text
What it means
Best-effort extraction of an error body from an arbitrary exception caught in the OpenAI completion handler: it pulls 'text' off the exception (falling back to a default) so the raised error carries the upstream response body. It represents a failed completion call where the provider exception is normalized into an OpenAIError with status, headers, and body text.
Solutions
- Inspect the error text in the message; fix the request (auth, model, payload) as indicated.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/llms/openai/completion/handler.py:163 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/ab9c321cd5c97cc9.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/openai/completion/handler.py:163
logging_obj.post_call(
api_key=api_key,
original_response=response_json,
additional_args={
"headers": headers,
"api_base": api_base,
},
)
## RESPONSE OBJECT
return TextCompletionResponse(**response_json)
except Exception as e:
status_code: Final = getattr(e, "status_code", 500)
error_headers = getattr(e, "headers", None)
error_text: Final = getattr(e, "text", str(e))
error_response: Final = getattr(e, "response", None)
if error_headers is None and error_response:
error_headers = getattr(error_response, "headers", None)
raise OpenAIError(status_code=status_code, message=error_text, headers=error_headers)
async def acompletion(
self,
logging_obj,
api_base: str,
data: dict,
headers: dict,
model_response: ModelResponse,
api_key: str,
model: str,
timeout: float,
max_retries: int,
organization: str | None = None,
client=None,
):
try:
if client is None:
openai_aclient = AsyncOpenAI(View on GitHub (pinned to 77b7c6c40c)