{"record":{"id":"760dc51a37ab4b9d","repo":"BerriAI/litellm","slug":"run-timed-out-waiting-for-completion","errorCode":null,"errorMessage":"Run timed out waiting for completion","messagePattern":"Run timed out waiting for completion","errorType":"http","errorClass":"AzureAIAgentsError","httpStatus":408,"severity":"error","filePath":"litellm/llms/azure_ai/agents/handler.py","lineNumber":348,"sourceCode":"\n        # Step 4: Poll for completion\n        status_url: Final = self._build_run_status_url(api_base, thread_id, run_id, api_version)\n        for _ in range(self.config.MAX_POLL_ATTEMPTS):\n            response = make_request(\"GET\", status_url)\n            self._check_response(response, [200], \"Failed to get run status\")\n\n            status = response.json().get(\"status\")\n            verbose_logger.debug(\"Run status: %s\", status)\n\n            if status == \"completed\":\n                break\n            elif status in [\"failed\", \"cancelled\", \"expired\"]:\n                error_msg = response.json().get(\"last_error\", {}).get(\"message\", \"Unknown error\")\n                raise AzureAIAgentsError(status_code=500, message=f\"Run {status}: {error_msg}\")\n\n            time.sleep(self.config.POLL_INTERVAL_SECONDS)\n        else:\n            raise AzureAIAgentsError(status_code=408, message=\"Run timed out waiting for completion\")\n\n        # Step 5: Get messages\n        response = make_request(\"GET\", self._build_list_messages_url(api_base, thread_id, api_version))\n        self._check_response(response, [200], \"Failed to get messages\")\n\n        content, annotations = self._extract_content_from_messages(response.json())\n        return thread_id, content, annotations\n\n    # -------------------------------------------------------------------------\n    # Async Completion\n    # -------------------------------------------------------------------------\n    async def acompletion(\n        self,\n        model: str,\n        messages: list[dict[str, Any]],\n        api_base: str,\n        api_key: str,\n        model_response: ModelResponse,","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/agents/handler.py#L330-L366","documentation":"In the sync (non-streaming) Azure AI Agents path, LiteLLM polls the run status up to MAX_POLL_ATTEMPTS times, sleeping POLL_INTERVAL_SECONDS between polls. If the run never reaches 'completed' within that budget, the for-loop's else clause raises AzureAIAgentsError with status_code 408 and message 'Run timed out waiting for completion'. The run may still be executing on Azure — this is a client-side give-up, not proof of failure.","triggerScenarios":"Long-running agent runs (big documents, multi-step tool chains, code interpreter) whose total time exceeds MAX_POLL_ATTEMPTS * POLL_INTERVAL_SECONDS; Azure under heavy load with slow run scheduling; a stuck run that stays 'queued'/'in_progress' indefinitely.","commonSituations":"Switching a prototype agent to a production workload with much longer prompts; region capacity issues making runs slow to start; polling defaults tuned for short chat runs and never adjusted.","solutions":["Catch the 408 and poll the thread's run yourself via the Azure SDK/REST (you still have thread_id and run_id) instead of assuming failure.","Shorten run time: trim input, split work into multiple runs, or disable unnecessary tools.","Use the streaming path (stream=True), which receives events as they happen rather than polling to a deadline.","Check Azure Foundry metrics/portal for run latency spikes if timeouts are new."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = litellm.completion(model='azure_ai_agents/agent', messages=m)\nexcept Exception as e:\n    if type(e).__name__ == 'AzureAIAgentsError' and getattr(e, 'status_code', None) == 408:\n        result = poll_run_via_azure_sdk(thread_id, run_id)  # run may still complete\n    else:\n        raise","preventionTips":["Prefer stream=True for any agent expected to run longer than a few seconds.","Alert on 408 rate — sustained timeouts mean agent/tool slowness, not client bugs.","Keep thread_id/run_id around so a 408 is recoverable, not a dead end."],"tags":["azure","agents","timeout","polling","long-running"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}