{"record":{"id":"464f795389029ad5","repo":"BerriAI/litellm","slug":"streaming-request-failed-error-text-decode","errorCode":null,"errorMessage":"Streaming request failed: {error_text.decode()}","messagePattern":"Streaming request failed: (.+?)","errorType":"http","errorClass":"AzureAIAgentsError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/agents/handler.py","lineNumber":543,"sourceCode":"        url: Final = self._build_create_thread_and_run_url(api_base, api_version)\n        verbose_logger.debug(\"Azure AI Agents streaming - URL: %s\", url)\n\n        # Use LiteLLM's async HTTP client for streaming\n        client: Final = get_async_httpx_client(\n            llm_provider=litellm.LlmProviders.AZURE_AI,\n            params={\"ssl_verify\": litellm_params.get(\"ssl_verify\", None)},\n        )\n\n        response: Final = await client.post(\n            url=url,\n            headers=headers,\n            data=json.dumps(payload),\n            stream=True,\n        )\n\n        if response.status_code not in [200, 201]:\n            error_text: Final = await response.aread()\n            raise AzureAIAgentsError(\n                status_code=response.status_code,\n                message=f\"Streaming request failed: {error_text.decode()}\",\n            )\n\n        async for chunk in self._process_sse_stream(response, model):\n            yield chunk\n\n    async def _process_sse_stream(\n        self,\n        response: httpx.Response,\n        model: str,\n    ) -> AsyncIterator:\n        \"\"\"Process SSE stream and yield OpenAI-compatible streaming chunks.\"\"\"\n        from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices\n\n        response_id: Final = f\"chatcmpl-{uuid.uuid4().hex[:8]}\"\n        created: Final = int(time.time())\n        thread_id = None","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/agents/handler.py#L525-L561","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the status_code and the JSON body inside the exception message — Azure states the exact fault.","401: regenerate the token (az account get-access-token --resource https://ai.azure.com) or fix the service-principal env vars.","404: align api_base with the Foundry project that owns the agent id in the model string.","429: retry with exponential backoff and honor Retry-After."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_stream_request_failure(e: BaseException) -> bool:\n    return type(e).__name__ == 'AzureAIAgentsError' and 'Streaming request failed' in str(e)","tryCatchPattern":"try:\n    async for chunk in litellm.acompletion(model=..., stream=True):\n        ...\nexcept Exception as e:\n    if is_stream_request_failure(e) and e.status_code in (429, 500, 502, 503):\n        async for chunk in retry_with_backoff():\n            ...\n    else:\n        raise","preventionTips":["Validate token freshness before opening streams — mid-stream auth can't be retried transparently.","Verify the Foundry project endpoint with a non-streaming call first when wiring new environments.","Parse the embedded response body for the real Azure error code before choosing a retry policy."],"tags":["azure","agents","streaming","http-error","auth"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}