{"record":{"id":"5bb3061f989befea","repo":"BerriAI/litellm","slug":"keyerror-e-got-unexpected-response-from-openro","errorCode":null,"errorMessage":"KeyError: {e}, Got unexpected response from OpenRouter: {chunk}","messagePattern":"KeyError: (.+?), Got unexpected response from OpenRouter: (.+?)","errorType":"http","errorClass":"OpenRouterException","httpStatus":400,"severity":"error","filePath":"litellm/llms/openrouter/chat/transformation.py","lineNumber":282,"sourceCode":"                    message=error_message[\"message\"],\n                    status_code=error_message[\"code\"],\n                    headers=error_message[\"metadata\"].get(\"headers\", {}),\n                )\n\n            new_choices: Final = []\n            for choice in chunk[\"choices\"]:\n                choice[\"delta\"][\"reasoning_content\"] = choice[\"delta\"].get(\"reasoning\")\n                new_choices.append(choice)\n            return ModelResponseStream(\n                id=chunk[\"id\"],\n                object=\"chat.completion.chunk\",\n                created=chunk[\"created\"],\n                usage=chunk.get(\"usage\"),\n                model=chunk[\"model\"],\n                choices=new_choices,\n            )\n        except KeyError as e:\n            raise OpenRouterException(\n                message=f\"KeyError: {e}, Got unexpected response from OpenRouter: {chunk}\",\n                status_code=400,\n                headers={\"Content-Type\": \"application/json\"},\n            )\n        except Exception as e:\n            raise e\n","sourceCodeStart":264,"sourceCodeEnd":289,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openrouter/chat/transformation.py#L264-L289","documentation":"The streaming chunk from OpenRouter lacks expected keys (choices/delta/id), so chunk parsing raised KeyError; the raw chunk is embedded in the error because the response deviates from the documented streaming schema.","triggerScenarios":"Thrown at litellm/llms/openrouter/chat/transformation.py:282 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the unexpected OpenRouter chunk in the message; retry and, if persistent, check OpenRouter status or adjust the model."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}