{"record":{"id":"fffc4c98e6773253","repo":"BerriAI/litellm","slug":"error-in-response-raw-response-error","errorCode":null,"errorMessage":"Error in response: {raw_response.error}","messagePattern":"Error in response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/completion_extras/litellm_responses_transformation/transformation.py","lineNumber":747,"sourceCode":"        model_response: \"ModelResponse\",\n        logging_obj: \"LiteLLMLoggingObj\",\n        request_data: dict,\n        messages: list[\"AllMessageValues\"],\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: object,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> \"ModelResponse\":\n        \"\"\"Transform Responses API response to chat completion response\"\"\"\n        from litellm.responses.utils import ResponseAPILoggingUtils\n        from litellm.types.llms.openai import ResponsesAPIResponse\n\n        if not isinstance(raw_response, ResponsesAPIResponse):\n            raise ValueError(f\"Unexpected response type: {type(raw_response)}\")\n\n        if raw_response.error is not None:\n            raise ValueError(f\"Error in response: {raw_response.error}\")\n\n        output_items = raw_response.output\n        if len(output_items) == 0:\n            recovered_output_items: Final = self._recover_output_items_from_logging(logging_obj)\n            if recovered_output_items:\n                output_items = cast(Any, recovered_output_items)\n                raw_response.output = cast(Any, recovered_output_items)\n                verbose_logger.warning(\n                    \"Recovered empty Responses API output from raw SSE for model=%s\",\n                    model,\n                )\n\n        # Convert response output to choices using the static helper\n        choices: Final = self._convert_response_output_to_choices(\n            output_items=output_items,\n            handle_raw_dict_callback=self._handle_raw_dict_response_item,\n        )\n","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/completion_extras/litellm_responses_transformation/transformation.py#L729-L765","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nresp = litellm.completion(model=\"openai/gpt-5\", messages=msgs)  # ValueError: Error in response: {\"message\":\"Incorrect API key provided ...\"}\n\n// after\nimport os\nresp = litellm.completion(model=\"openai/gpt-5\", messages=msgs,\n                          api_key=os.environ[\"OPENAI_API_KEY\"])  # valid key","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=m, messages=msgs)\nexcept ValueError as e:\n    if \"Error in response:\" in str(e):\n        provider_error = str(e).split(\"Error in response:\", 1)[1]\n        logger.error(\"provider in-band error: %s\", provider_error)\n        raise RuntimeError(provider_error) from e\n    raise","preventionTips":["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"],"tags":["provider-error","responses-api","auth","api-configuration"],"backgroundTag":"api-error-in-response-payload","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}