{"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":"http","errorClass":"DatabricksException","httpStatus":400,"severity":"error","filePath":"litellm/llms/databricks/chat/transformation.py","lineNumber":738,"sourceCode":"                # extract the reasoning content\n                (\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            )\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":720,"sourceCodeEnd":744,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/databricks/chat/transformation.py#L720-L744","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    chunks = [c for c in litellm.completion(model=m, messages=msgs, stream=True)]\nexcept Exception as e:\n    if \"Got unexpected response from Databricks\" in str(e):\n        logger.warning(\"streaming unsupported shape, retrying without stream\")\n        return [litellm.completion(model=m, messages=msgs, stream=False)]\n    raise","preventionTips":["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"],"tags":["databricks","streaming","response-schema"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}