BerriAI/litellm · error · OpenRouterException

Message: {}, Metadata: {}, User ID: {}

Error message

Message: {}, Metadata: {}, User ID: {}

What it means

Streaming error-chunk formatter in the OpenRouter handler: an in-stream 'error' object arrived (OpenRouter reports mid-stream failures this way), and this message template packs the error's message, metadata, and user_id into the raised exception text.

Source

Thrown at litellm/llms/openrouter/chat/transformation.py:263

        )


class OpenRouterChatCompletionStreamingHandler(BaseModelResponseIterator):
    def chunk_parser(self, chunk: dict) -> ModelResponseStream:
        try:
            ## HANDLE ERROR IN CHUNK ##
            if "error" in chunk:
                error_chunk: Final = chunk["error"]
                error_message: Final = OpenRouterErrorMessage(
                    message="Message: {}, Metadata: {}, User ID: {}".format(
                        error_chunk["message"],
                        error_chunk.get("metadata", {}),
                        error_chunk.get("user_id", ""),
                    ),
                    code=error_chunk["code"],
                    metadata=error_chunk.get("metadata", {}),
                )
                raise OpenRouterException(
                    message=error_message["message"],
                    status_code=error_message["code"],
                    headers=error_message["metadata"].get("headers", {}),
                )

            new_choices: Final = []
            for choice in chunk["choices"]:
                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:

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Read the OpenRouter error message/metadata in the exception; common causes are insufficient credits, invalid model slug, or moderation refusal.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at litellm/llms/openrouter/chat/transformation.py:263 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/f27e2d587614578d. Report an issue: GitHub.