{"record":{"id":"8795da6dd6160c01","repo":"BerriAI/litellm","slug":"keyerror-e-got-unexpected-response-from-databr","errorCode":null,"errorMessage":"KeyError: {e}, Got unexpected response from Databricks: {chunk}","messagePattern":"KeyError: (.+?), Got unexpected response from Databricks: (.+?)","errorType":"exception","errorClass":"DatabricksException","httpStatus":400,"severity":"error","filePath":"litellm/llms/databricks/chat/transformation.py","lineNumber":739,"sourceCode":"                (\n                    reasoning_content,\n                    thinking_blocks,\n                ) = DatabricksConfig.extract_reasoning_content(choice[\"delta\"].get(\"content\"))\n\n                choice[\"delta\"][\"content\"] = content_str\n                choice[\"delta\"][\"reasoning_content\"] = reasoning_content\n                choice[\"delta\"][\"thinking_blocks\"] = thinking_blocks\n                translated_choices.append(choice)\n            return ModelResponseStream(\n                id=chunk[\"id\"],\n                object=\"chat.completion.chunk\",\n                created=chunk[\"created\"],\n                model=chunk[\"model\"],\n                choices=translated_choices,\n                usage=chunk.get(\"usage\"),\n            )\n        except KeyError as e:\n            raise DatabricksException(\n                message=f\"KeyError: {e}, Got unexpected response from Databricks: {chunk}\",\n                status_code=400,\n            )\n        except Exception as e:\n            raise e\n","sourceCodeStart":721,"sourceCodeEnd":745,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/databricks/chat/transformation.py#L721-L745","documentation":"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.","triggerScenarios":"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.","commonSituations":"External/foundation model gateways emitting minimal chunk shapes; intermediary inserting heartbeat frames; serving API version differences dropping fields LiteLLM treats as required.","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"],"exampleFix":"# before\nresp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=True)  # KeyError chunk\n\n# after — degrade to non-streaming when the stream schema breaks\ntry:\n    resp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=True)\nexcept litellm.exceptions.APIError as e:\n    if 'Got unexpected response from Databricks' in str(e):\n        resp = litellm.completion(model='databricks/my-endpoint', messages=msgs, stream=False)\n    else:\n        raise","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    stream = litellm.completion(model='databricks/my-ep', messages=msgs, stream=True)\n    for chunk in stream:\n        handle(chunk)\nexcept Exception as e:\n    if 'Got unexpected response from Databricks' in str(e):\n        resp = litellm.completion(model='databricks/my-ep', messages=msgs, stream=False)\n        handle(resp)\n    else:\n        raise","preventionTips":["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"],"tags":["databricks","streaming","chunk-parsing","keyerror"],"backgroundTag":"unexpected-response-schema","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}