BerriAI/litellm · error · OpenAIError

{message}

Error message

{message}

What it means

Raised by LiteLLM's Groq streaming chunk parser when a streamed SSE chunk from Groq contains an 'error' object instead of completion data. Groq reports some failures (rate limits, model overloaded, invalid arguments) mid-stream after the HTTP 200 connection is already open; LiteLLM surfaces them by raising OpenAIError with the chunk's code, message, and body. The '{message}' placeholder is filled with Groq's own error text, so the wording varies by failure mode.

Solutions

  1. Read the raised OpenAIError's message and status_code first — it is Groq's own error text (rate limit, overloaded, etc.) and identifies the cause
  2. If rate limited: slow down the request rate, add exponential backoff, or raise your Groq rate limits
  3. Verify the model id against Groq's current model list — deprecated models are removed and only fail at request time
  4. Reduce prompt size if the message mentions token/context limits
  5. Check Groq's status page if the failures are transient 'overloaded' errors

Example fix

// before
response = litellm.completion(
    model="groq/llama-3.3-70b-versatile", messages=msgs, stream=True
)
for chunk in response:
    print(chunk.choices[0].delta.content)

// after
from litellm.llms.openai.common_utils import OpenAIError

try:
    response = litellm.completion(
        model="groq/llama-3.3-70b-versatile", messages=msgs, stream=True
    )
    for chunk in response:
        print(chunk.choices[0].delta.content)
except OpenAIError as e:
    print("Groq stream failed:", e.status_code, e.message)
Defensive patterns

Strategy: try-catch

Try / catch

Wrap the whole chunk-iteration loop, not just the completion() call — the error is raised while consuming the stream generator. Catch OpenAIError (or litellm's LiteLLMError base) and branch on status_code: 429 → exponential backoff and re-issue the full request; 404/400 → stop and fix model id/params; overloaded/5xx → retry with jitter or route to a fallback model via litellm Router. Accumulate already-streamed text so partial output is not lost.

Prevention

When it happens

Trigger: Calling litellm.completion(model='groq/<model>', ..., stream=True) and iterating chunks when Groq injects {'error': {...}} into the stream: rate limit exceeded, model overloaded or deprecated, context length exceeded, or an invalid model id that Groq only rejects after streaming begins. The error surfaces while consuming the chunk generator, not at call time.

Common situations: Hitting Groq free-tier RPM/TPM limits during batch jobs; using a deprecated/renamed Groq model id; sending an oversized prompt; transient Groq incidents. Developers are often confused because the request initially succeeds (HTTP 200) and tokens stream before the exception fires mid-iteration.

Related errors


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

Appendix: source

Thrown at litellm/llms/groq/chat/transformation.py:352

            return ()

    def _map_groq_service_tier(self, original_service_tier: str | None) -> Literal["auto", "default", "flex"]:
        """
        Ensure groq service tier is OpenAI compatible.
        """
        if original_service_tier is None:
            return "auto"
        if original_service_tier not in ["auto", "default", "flex"]:
            return "auto"

        return cast(Literal["auto", "default", "flex"], original_service_tier)


class GroqChatCompletionStreamingHandler(OpenAIChatCompletionStreamingHandler):
    def chunk_parser(self, chunk: dict) -> ModelResponseStream:
        error: Final = chunk.get("error")
        if error:
            raise OpenAIError(status_code=error.get("code"), message=error.get("message"), body=error)

        # Map Groq's 'reasoning' field to LiteLLM's 'reasoning_content' field
        # Groq returns delta.reasoning, but LiteLLM expects delta.reasoning_content
        choices: Final = chunk.get("choices", [])
        for choice in choices:
            delta = choice.get("delta", {})
            if "reasoning" in delta:
                delta["reasoning_content"] = delta.pop("reasoning")

        return super().chunk_parser(chunk)

View on GitHub (pinned to 77b7c6c40c)