BerriAI/litellm · error · BytezError

response.text

Error message

response.text

What it means

The synchronous streaming path checks the POST response explicitly: any status other than 200 raises BytezError with that status code and response.text as the message. This is the normal route by which non-200s on stream=True bytez calls surface, since httpx does not raise HTTPStatusError by itself.

Source

Thrown at litellm/llms/bytez/chat/transformation.py:277

        signed_json_body: bytes | None = None,
    ) -> "BytezCustomStreamWrapper":
        if client is None or isinstance(client, AsyncHTTPHandler):
            client = _get_httpx_client(params={})

        try:
            response: Final = client.post(
                api_base,
                headers=headers,
                data=json.dumps(data),
                stream=True,
                logging_obj=logging_obj,
                timeout=STREAMING_TIMEOUT,
            )
        except httpx.HTTPStatusError as e:
            raise BytezError(status_code=e.response.status_code, message=e.response.text)

        if response.status_code != 200:
            raise BytezError(status_code=response.status_code, message=response.text)

        completion_stream: Final = response.iter_text()

        streaming_response: Final = BytezCustomStreamWrapper(
            completion_stream=completion_stream,
            model=model,
            custom_llm_provider=custom_llm_provider,
            logging_obj=logging_obj,
        )
        return streaming_response

    @track_llm_api_timing()
    async def get_async_custom_stream_wrapper(
        self,
        model: str,
        custom_llm_provider: str,
        logging_obj: LiteLLMLoggingObj,
        api_base: str,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Catch BytezError and switch on status_code: refresh key on 401, back off on 429/5xx, fix URL/model on 404.
  2. Retry with exponential backoff and jitter for 429/5xx.
  3. Verify api_base and model path when 404 persists.
  4. Truncate e.message before writing it to logs.
Defensive patterns

Strategy: try-catch

Try / catch

from litellm.llms.bytez.common_utils import BytezError

try:
    stream = litellm.completion(model="bytez/org/model", messages=msgs, stream=True)
    for chunk in stream:
        ...
except BytezError as e:
    if e.status_code == 429:
        backoff_and_retry()
    elif e.status_code == 401:
        refresh_bytez_key()
    else:
        raise

Prevention

When it happens

Trigger: stream=True bytez completion returning 401 (invalid key), 404 (bad model/api_base), 429 (rate limit), 500/502/503 (server or gateway); the response body (error page or JSON) becomes the message verbatim.

Common situations: Batch/agent workloads tripping 429s; misconfigured api_base; Bytez outages; error bodies that are HTML, making exception messages long and noisy in logs.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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