BerriAI/litellm · error · OVHCloudException

KeyError: {e}, Got unexpected response from CometAPI: {chunk

Error message

KeyError: {e}, Got unexpected response from CometAPI: {chunk}

What it means

While constructing the ModelResponseStream from an OVHCloud SSE chunk, a required key ('id', 'created', 'model', or 'choices') is missing and the resulting KeyError is converted into an OVHCloudException with status 400. The message text says 'CometAPI' - this is a copy-paste artifact in litellm; the failing provider is OVHCloud, and the offending chunk is embedded in the message for diagnosis.

Source

Thrown at litellm/llms/ovhcloud/chat/transformation.py:111

                    # `reasoning_content` is replaced by `reasoning`.
                    # Normalise to `reasoning_content` so downstream consumers
                    # see a consistent key during the transition window.
                    reasoning_new = delta.get("reasoning")
                    reasoning_legacy = delta.get("reasoning_content")
                    if reasoning_new is not None and reasoning_legacy is None:
                        delta["reasoning_content"] = reasoning_new
                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 OVHCloudException(
                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 77b7c6c40c)

Solutions

  1. Log the exception message - it embeds the exact chunk that failed, revealing which key was missing
  2. Upgrade litellm; parser gaps for non-standard chunks are usually patched upstream
  3. File a litellm issue - the 'CometAPI' wording confirms the bug lives in the OVHCloud chunk parser
  4. As a workaround, retry non-streaming so the full payload arrives as one JSON body
Defensive patterns

Strategy: fallback

Try / catch

Catch OVHCloudException; when the message contains 'KeyError', fall back to a non-streaming retry for that request so the full JSON body is parsed in one piece, and report the offending chunk (embedded in the message) upstream.

Prevention

When it happens

Trigger: OVHCloud sends a non-standard chunk in the stream: usage-only final chunks lacking id/model, keep-alive or heartbeat objects, or any SSE event that is not a full chat.completion.chunk dict with all four required keys.

Common situations: OVH changes stream framing (e.g., appending usage chunks without standard fields); proxies injecting heartbeat lines into the SSE stream; schema drift after OVH API updates.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/ac80b4361658142e. Report an issue: GitHub.