BerriAI/litellm · error · OllamaError
KeyError: , Got unexpected response from Ollama
Error message
KeyError: {e}, Got unexpected response from Ollama: {chunk} What it means
Error "KeyError: {e}, Got unexpected response from Ollama: {chunk}" thrown in BerriAI/litellm.
Solutions
- Inspect the unexpected Ollama chunk in the message; upgrade the Ollama server or litellm so the response schema matches.
When it happens
Trigger: Thrown at litellm/llms/ollama/chat/transformation.py:541 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/5cd8663657cbb1ba.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/ollama/chat/transformation.py:541
)
]
usage: Final = ChatCompletionUsageBlock(
prompt_tokens=chunk.get("prompt_eval_count", 0),
completion_tokens=chunk.get("eval_count", 0),
total_tokens=chunk.get("prompt_eval_count", 0) + chunk.get("eval_count", 0),
)
return ModelResponseStream(
id=str(uuid.uuid4()),
object="chat.completion.chunk",
created=int(time.time()), # ollama created_at is in UTC
usage=usage,
model=chunk["model"],
choices=choices,
)
except KeyError as e:
raise OllamaError(
message=f"KeyError: {e}, Got unexpected response from Ollama: {chunk}",
status_code=400,
headers={"Content-Type": "application/json"},
)
except Exception as e:
raise e
View on GitHub (pinned to 77b7c6c40c)