BerriAI/litellm · error · OpenAIError

error_message

Error message

error_message

What it means

Extracted error message from an SSE chunk emitted by OpenAI-compatible backends (vLLM, sglang) that return HTTP 200 streams whose payloads carry an error object instead of deltas. The message is the provider's own error text (or a JSON dump of the non-string error), paired with a status code derived from the payload's 'code' field or defaulted to 500.

Solutions

  1. Read the error message included in the exception and correct the OpenAI request accordingly.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/openai/chat/gpt_transformation.py:794 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/llms/openai/chat/gpt_transformation.py:794

        """OpenAI-compatible backends (vLLM, sglang) can return an HTTP 200
        stream whose body carries an error payload, e.g.
        ``data: {"error": {"message": "...", "code": 400}}``."""
        error: Final = chunk.get("error")
        if not error:
            return None
        if not isinstance(error, dict):
            return str(error), 500
        message: Final = error.get("message")
        code: Final = error.get("code")
        status_code: Final = code if isinstance(code, int) and 400 <= code < 600 else 500
        return (message if isinstance(message, str) else json.dumps(error)), status_code

    def chunk_parser(self, chunk: dict) -> ModelResponseStream:
        try:
            error_details: Final = self._extract_error_from_chunk(chunk)
            if error_details is not None:
                error_message, error_status_code = error_details
                raise OpenAIError(
                    status_code=error_status_code,
                    message=error_message,
                )
            choices = chunk.get("choices", [])
            choices = self._map_reasoning_to_reasoning_content(choices)

            kwargs: Final[dict[str, Any]] = {
                "id": chunk.get("id"),
                "object": "chat.completion.chunk",
                "created": chunk.get("created"),
                "model": chunk.get("model"),
                "choices": choices,
            }
            if "usage" in chunk and chunk["usage"] is not None:
                kwargs["usage"] = chunk["usage"]
            return ModelResponseStream(**kwargs)
        except Exception as e:
            raise e

View on GitHub (pinned to 77b7c6c40c)