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

  1. Inspect the chunk printed in the exception to see which field is absent
  2. If 'model' or 'created' is missing, check the endpoint's response format; external models may need a different provider mapping in litellm config
  3. Upgrade litellm — chunk translation robustness for Databricks variants improves across versions
  4. 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

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


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/8795da6dd6160c01. Report an issue: GitHub.