BerriAI/litellm · error · BytezError

{response.text}

Error message

{response.text}

What it means

In the synchronous streaming path, the httpx POST to Bytez is wrapped in a try/except for httpx.HTTPStatusError; if httpx raises one, it is converted to BytezError with the upstream status code and response text. This surfaces transport-level HTTP failures (4xx/5xx) that raise during the request call.

Source

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

        messages: list,
        client: HTTPHandler | AsyncHTTPHandler | None = None,
        json_mode: bool | None = None,
        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,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the embedded response text for the upstream reason.
  2. Verify api_base (if overridden) points at Bytez's chat completions endpoint.
  3. Check/refresh BYTEZ_API_KEY for 401s.
  4. Retry with backoff for 5xx; check Bytez status pages if persistent.
Defensive patterns

Strategy: retry

Try / catch

try:
    stream = litellm.completion(model="bytez/...", messages=m, stream=True)
except BytezError as e:
    if e.status_code >= 500 or e.status_code == 429:
        time.sleep(2 ** attempt); retry()
    elif e.status_code == 401:
        rotate_key_and_alert()
    else:
        raise

Prevention

When it happens

Trigger: stream=True litellm.completion to a bytez/ model where the initial POST raises httpx.HTTPStatusError — auth failures, 404 endpoints (bad api_base/model path), 5xx from Bytez — during connection/request handling.

Common situations: Custom/wrong api_base; expired API key producing 401 at connect time; Bytez outages returning 502/503 at request start.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/83ab83e308baba4e. Report an issue: GitHub.