BerriAI/litellm · error · CometAPIException
KeyError: {e}, Got unexpected response from CometAPI: {chunk
Error message
KeyError: {e}, Got unexpected response from CometAPI: {chunk} What it means
Error "KeyError: {e}, Got unexpected response from CometAPI: {chunk}" thrown in BerriAI/litellm.
Source
Thrown at litellm/llms/cometapi/chat/transformation.py:189
# Process choices
new_choices: Final = []
for choice in chunk["choices"]:
# Handle reasoning content if present
if "delta" in choice and "reasoning" in choice["delta"]:
choice["delta"]["reasoning_content"] = choice["delta"].get("reasoning")
new_choices.append(choice)
return ModelResponseStream(
id=chunk["id"],
object="chat.completion.chunk",
created=chunk["created"],
usage=chunk.get("usage"),
model=chunk["model"],
choices=new_choices,
)
except KeyError as e:
raise CometAPIException(
message=f"KeyError: {e}, Got unexpected response from CometAPI: {chunk}",
status_code=400,
headers={"Content-Type": "application/json"},
)
except Exception as e:
raise e
View on GitHub (pinned to 6c2dcb801b)
Solutions
- The CometAPI response chunk had an unexpected shape; check the provider response.
When it happens
Trigger: Thrown at litellm/llms/cometapi/chat/transformation.py:189 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/9fa4f0f3f542ede3.
Report an issue: GitHub.