BerriAI/litellm · error · DatabricksException
KeyError: {e}, Got unexpected response from Databricks: {chu
Error message
KeyError: {e}, Got unexpected response from Databricks: {chunk} What it means
Raised while translating a Databricks streaming chunk into LiteLLM's ModelResponseStream: a required key ('id', 'created', 'model', or a choice field) is missing from the chunk dict, causing a KeyError. The exception includes the missing key and the entire chunk, with status_code 400.
Source
Thrown at litellm/llms/databricks/chat/transformation.py:738
# extract the reasoning content
(
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,
)
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 6c2dcb801b)
Solutions
- Inspect the chunk printed in the exception to see which field is absent
- If 'model' or 'created' is missing, check the endpoint's response format; external models may need a different provider mapping in litellm config
- Upgrade litellm — chunk translation robustness for Databricks variants improves across versions
- As a workaround, use non-streaming completion for the affected endpoint
Defensive patterns
Strategy: fallback
Try / catch
try:
chunks = [c for c in litellm.completion(model=m, messages=msgs, stream=True)]
except Exception as e:
if "Got unexpected response from Databricks" in str(e):
logger.warning("streaming unsupported shape, retrying without stream")
return [litellm.completion(model=m, messages=msgs, stream=False)]
raise Prevention
- Test streaming against each new Databricks endpoint type before enabling it in production
- Keep a non-streaming fallback path for endpoints with non-standard chunk schemas
- Stay current on litellm patches, which frequently harden Databricks chunk translation
When it happens
Trigger: Streaming a completion from a Databricks serving endpoint whose chunk format deviates from expected: custom/foundation-model endpoints emitting minimal chunks, or DBRX/external-model variations that omit fields like 'model' in continuation chunks.
Common situations: Serving an external model (e.g. via Databricks external models) or a custom model whose SSE chunks lack standard fields; version drift after Databricks changes its serving response format.
Related errors
- Unable to get json response - {e}, Original Response: {raw_r
- Failed to decode JSON from chunk: {chunk}
- Error receiving chunk from stream: {e}
- Braintrust API error: {e.response.text}
- Failed to connect to Braintrust API: {str(e)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/8795da6dd6160c01.
Report an issue: GitHub.