BerriAI/litellm · error · AzureAIAgentsError

Streaming request failed: {error_text.decode()}

Error message

Streaming request failed: {error_text.decode()}

What it means

In the native SSE streaming path for Azure AI Agents, LiteLLM POSTs the run request with stream=True and requires HTTP 200 or 201. Any other status raises AzureAIAgentsError with that status code and the full response body decoded into the message ('Streaming request failed: <body>'). The body is Azure's raw error JSON and identifies the real problem.

Source

Thrown at litellm/llms/azure_ai/agents/handler.py:543

        url: Final = self._build_create_thread_and_run_url(api_base, api_version)
        verbose_logger.debug("Azure AI Agents streaming - URL: %s", url)

        # Use LiteLLM's async HTTP client for streaming
        client: Final = get_async_httpx_client(
            llm_provider=litellm.LlmProviders.AZURE_AI,
            params={"ssl_verify": litellm_params.get("ssl_verify", None)},
        )

        response: Final = await client.post(
            url=url,
            headers=headers,
            data=json.dumps(payload),
            stream=True,
        )

        if response.status_code not in [200, 201]:
            error_text: Final = await response.aread()
            raise AzureAIAgentsError(
                status_code=response.status_code,
                message=f"Streaming request failed: {error_text.decode()}",
            )

        async for chunk in self._process_sse_stream(response, model):
            yield chunk

    async def _process_sse_stream(
        self,
        response: httpx.Response,
        model: str,
    ) -> AsyncIterator:
        """Process SSE stream and yield OpenAI-compatible streaming chunks."""
        from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices

        response_id: Final = f"chatcmpl-{uuid.uuid4().hex[:8]}"
        created: Final = int(time.time())
        thread_id = None

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the status_code and the JSON body inside the exception message — Azure states the exact fault.
  2. 401: regenerate the token (az account get-access-token --resource https://ai.azure.com) or fix the service-principal env vars.
  3. 404: align api_base with the Foundry project that owns the agent id in the model string.
  4. 429: retry with exponential backoff and honor Retry-After.
Defensive patterns

Strategy: retry

Type guard

def is_stream_request_failure(e: BaseException) -> bool:
    return type(e).__name__ == 'AzureAIAgentsError' and 'Streaming request failed' in str(e)

Try / catch

try:
    async for chunk in litellm.acompletion(model=..., stream=True):
        ...
except Exception as e:
    if is_stream_request_failure(e) and e.status_code in (429, 500, 502, 503):
        async for chunk in retry_with_backoff():
            ...
    else:
        raise

Prevention

When it happens

Trigger: litellm.completion(..., stream=True) on an azure_ai_agents model with: expired/invalid Azure AD token (401), wrong project api_base (404), model/agent id typo (404), payload rejected (400, e.g. bad metadata or unsupported streaming parameter), or throttling (429).

Common situations: Streaming works locally but breaks in prod because the managed identity/token differs; endpoint from a different Azure AI Foundry project; beta streaming API changed after api_version pin drift.

Related errors


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