BerriAI/litellm · error · DatabricksException
KeyError: , Got unexpected response from Databricks
Error message
KeyError: {e}, Got unexpected response from Databricks: {chunk} What it means
The Databricks streaming chunk translator indexes chunk['id'], chunk['created'], chunk['model'] and choice['delta'] directly when building ModelResponseStream. A chunk missing any of those keys raises KeyError, re-raised as DatabricksException (status 400) naming the missing key and echoing the offending chunk. The stream contained a chunk whose shape the parser assumes but that chunk did not carry.
Solutions
- Log the chunk from the message — it names the missing key and the exact payload; compare with the OpenAI streaming chunk schema
- Ensure the endpoint is served OpenAI-compatible and reached via the databricks provider's expected invocations path
- Retry the same call with stream=False — if it succeeds, the issue is chunk-shape-specific to streaming
- Update LiteLLM (chunk translation is hardened frequently); if the payload matches Databricks docs, file an issue with the logged chunk
Example fix
# before
resp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=True) # KeyError chunk
# after — degrade to non-streaming when the stream schema breaks
try:
resp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=True)
except litellm.exceptions.APIError as e:
if 'Got unexpected response from Databricks' in str(e):
resp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=False)
else:
raise Defensive patterns
Strategy: fallback
Try / catch
try:
stream = litellm.completion(model='databricks/my-ep', messages=msgs, stream=True)
for chunk in stream:
handle(chunk)
except Exception as e:
if 'Got unexpected response from Databricks' in str(e):
resp = litellm.completion(model='databricks/my-ep', messages=msgs, stream=False)
handle(resp)
else:
raise Prevention
- Integration-test streaming against every new endpoint/model before production traffic
- Keep a non-streaming fallback path for databricks endpoints that emit non-standard chunks
When it happens
Trigger: Streaming from a Databricks serving endpoint whose chunks omit 'model' or 'created' (seen with some external-model gateways); an interleaved usage/keep-alive chunk without id; routing a non-OpenAI-compatible model through the databricks provider's streaming path.
Common situations: External/foundation model gateways emitting minimal chunk shapes; intermediary inserting heartbeat frames; serving API version differences dropping fields LiteLLM treats as required.
Related errors
- Failed to decode JSON from chunk
- Error receiving chunk from stream
- A2A send_message_streaming failed: no response received…
- AgentCore: Failed to read/parse JSON response body
- api_base is required for Pydantic AI agents
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/8795da6dd6160c01.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/databricks/chat/transformation.py:739
(
reasoning_content,
thinking_blocks,
) = DatabricksConfig.extract_reasoning_content(choice["delta"].get("content"))
choice["delta"]["content"] = content_str
choice["delta"]["reasoning_content"] = reasoning_content
choice["delta"]["thinking_blocks"] = thinking_blocks
translated_choices.append(choice)
return ModelResponseStream(
id=chunk["id"],
object="chat.completion.chunk",
created=chunk["created"],
model=chunk["model"],
choices=translated_choices,
usage=chunk.get("usage"),
)
except KeyError as e:
raise DatabricksException(
message=f"KeyError: {e}, Got unexpected response from Databricks: {chunk}",
status_code=400,
)
except Exception as e:
raise e
View on GitHub (pinned to 77b7c6c40c)