BerriAI/litellm · error · ValueError
Error in response
Error message
Error in response: {raw_response.error} What it means
The Responses API returned a response object whose top-level 'error' field is populated — the provider embedded an error in an otherwise structured response. The bridge refuses to convert an errored response into a chat completion and re-raises the error content verbatim. The original provider error message (auth, quota, model access, content policy) appears after the colon.
Solutions
- Read the text after 'Error in response:' — it is the provider's own error message and names the real cause
- Verify api_key, api_base, and that the model is enabled for the Responses API on your account/deployment
- For Azure, confirm the deployment supports the responses API surface and the URL is correct
- Retry only after fixing the underlying cause; this is not a transient-network error by itself
- If a gateway is inlining errors, switch to one that maps them to proper HTTP error codes
Example fix
// before
resp = litellm.completion(model="openai/gpt-5", messages=msgs) # ValueError: Error in response: {"message":"Incorrect API key provided ..."}
// after
import os
resp = litellm.completion(model="openai/gpt-5", messages=msgs,
api_key=os.environ["OPENAI_API_KEY"]) # valid key Defensive patterns
Strategy: try-catch
Validate before calling
null
Try / catch
try:
resp = litellm.completion(model=m, messages=msgs)
except ValueError as e:
if "Error in response:" in str(e):
provider_error = str(e).split("Error in response:", 1)[1]
logger.error("provider in-band error: %s", provider_error)
raise RuntimeError(provider_error) from e
raise Prevention
- Fail fast on configuration: verify api_key/api_base before the loop, not inside it
- Do not blind-retry in-band errors — they repeat until the cause is fixed
- Log the text after 'Error in response:' separately; it carries the real provider message
When it happens
Trigger: Calls through the chat-to-responses bridge where the provider returns an error object in the response payload: invalid or expired API key on some gateways, model not enabled for the Responses API, org-level restrictions, or upstream failures surfaced as in-band errors rather than HTTP error statuses.
Common situations: Misconfigured api_key or api_base for the provider; using a model name the account cannot access via /v1/responses; Azure OpenAI deployments without responses support; third-party gateways that inline errors into 200 responses.
Related errors
- api_base not set for Hosted VLLM responses API. Set via…
- api_base not set for LiteLLM Proxy responses API. Set via…
- Authentication failed. Check your GitLab token and…
- Batch record for /v1/responses is missing required `input`…
- BFL initial request failed
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fffc4c98e6773253.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/completion_extras/litellm_responses_transformation/transformation.py:747
model_response: "ModelResponse",
logging_obj: "LiteLLMLoggingObj",
request_data: dict,
messages: list["AllMessageValues"],
optional_params: dict,
litellm_params: dict,
encoding: object,
api_key: str | None = None,
json_mode: bool | None = None,
) -> "ModelResponse":
"""Transform Responses API response to chat completion response"""
from litellm.responses.utils import ResponseAPILoggingUtils
from litellm.types.llms.openai import ResponsesAPIResponse
if not isinstance(raw_response, ResponsesAPIResponse):
raise ValueError(f"Unexpected response type: {type(raw_response)}")
if raw_response.error is not None:
raise ValueError(f"Error in response: {raw_response.error}")
output_items = raw_response.output
if len(output_items) == 0:
recovered_output_items: Final = self._recover_output_items_from_logging(logging_obj)
if recovered_output_items:
output_items = cast(Any, recovered_output_items)
raw_response.output = cast(Any, recovered_output_items)
verbose_logger.warning(
"Recovered empty Responses API output from raw SSE for model=%s",
model,
)
# Convert response output to choices using the static helper
choices: Final = self._convert_response_output_to_choices(
output_items=output_items,
handle_raw_dict_callback=self._handle_raw_dict_response_item,
)
View on GitHub (pinned to 77b7c6c40c)