{"record":{"id":"5cd8663657cbb1ba","repo":"BerriAI/litellm","slug":"keyerror-e-got-unexpected-response-from-ollama","errorCode":null,"errorMessage":"KeyError: {e}, Got unexpected response from Ollama: {chunk}","messagePattern":"KeyError: (.+?), Got unexpected response from Ollama: (.+?)","errorType":"exception","errorClass":"OllamaError","httpStatus":400,"severity":"error","filePath":"litellm/llms/ollama/chat/transformation.py","lineNumber":541,"sourceCode":"                    )\n                ]\n\n            usage: Final = ChatCompletionUsageBlock(\n                prompt_tokens=chunk.get(\"prompt_eval_count\", 0),\n                completion_tokens=chunk.get(\"eval_count\", 0),\n                total_tokens=chunk.get(\"prompt_eval_count\", 0) + chunk.get(\"eval_count\", 0),\n            )\n\n            return ModelResponseStream(\n                id=str(uuid.uuid4()),\n                object=\"chat.completion.chunk\",\n                created=int(time.time()),  # ollama created_at is in UTC\n                usage=usage,\n                model=chunk[\"model\"],\n                choices=choices,\n            )\n        except KeyError as e:\n            raise OllamaError(\n                message=f\"KeyError: {e}, Got unexpected response from Ollama: {chunk}\",\n                status_code=400,\n                headers={\"Content-Type\": \"application/json\"},\n            )\n        except Exception as e:\n            raise e\n","sourceCodeStart":523,"sourceCodeEnd":548,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/ollama/chat/transformation.py#L523-L548","documentation":"Error \"KeyError: {e}, Got unexpected response from Ollama: {chunk}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/ollama/chat/transformation.py:541 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the unexpected Ollama chunk in the message; upgrade the Ollama server or litellm so the response schema matches."],"exampleFix":null,"handlingStrategy":null,"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-23T08:17:48.524Z"}