{"record":{"id":"329d4366fe340243","repo":"FoundationAgents/MetaGPT","slug":"request-timed-out","errorCode":null,"errorMessage":"Request timed out","messagePattern":"Request timed out","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"metagpt/provider/general_api_requestor.py","lineNumber":128,"sourceCode":"        Returns:\n            Tuple[Union[OpenAIResponse, AsyncGenerator[OpenAIResponse, None]], bool]: A tuple containing the response content and a boolean indicating if it is a stream.\n        \"\"\"\n        content_type = result.headers.get(\"Content-Type\", \"\")\n        if stream and (\n            \"text/event-stream\" in content_type or \"application/x-ndjson\" in content_type or content_type == \"\"\n        ):\n            return (\n                (\n                    self._interpret_response_line(line, result.status, result.headers, stream=True)\n                    async for line in result.content\n                ),\n                True,\n            )\n        else:\n            try:\n                response_content = await result.read()\n            except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as e:\n                raise TimeoutError(\"Request timed out\") from e\n            except aiohttp.ClientError as exp:\n                logger.warning(f\"response: {result}, exp: {exp}\")\n                response_content = b\"\"\n            return (\n                self._interpret_response_line(\n                    response_content,  # let the caller decode the msg\n                    result.status,\n                    result.headers,\n                    stream=False,\n                ),\n                False,\n            )\n","sourceCodeStart":110,"sourceCodeEnd":141,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/provider/general_api_requestor.py#L110-L141","documentation":"MetaGPT's async requestor converts aiohttp.ServerTimeoutError or asyncio.TimeoutError raised while reading the (already-received) response body into a plain Python TimeoutError with the message 'Request timed out'. The connect/read timeout that was set on the request (e.g. the provider's timeout config or USE_CONFIG_TIMEOUT) was exceeded during body read, so the call is aborted.","triggerScenarios":"Non-streaming async completion (_achat_completion) where the server accepts the request but streams the body too slowly: await result.read() exceeds the configured read timeout; long generations with a small timeout value, or a proxy/network that stalls mid-body.","commonSituations":"Default timeouts too short for large completions or slow reasoning models, congested corporate proxies, streaming disabled (non-stream path forces a single body read), or LLM_API_TIMEOUT misconfigured in config2.yaml.","solutions":["Increase the request timeout, e.g. set LLM_API_TIMEOUT (or the provider's timeout argument) to 300+ seconds.","Use streaming mode (_achat_completion_stream / stream=True) where supported; MetaGPT's default providers often route long completions through streaming for this reason.","Retry the request with backoff; read timeouts are frequently transient under network congestion.","Check proxy/network health if timeouts recur across all models."],"exampleFix":"# before\nawait provider._achat_completion(messages, timeout=30)  # too short for big outputs\n\n# after\nawait provider._achat_completion(messages, timeout=600)\n# or in config2.yaml: LLM_API_TIMEOUT: 600","handlingStrategy":"retry","validationCode":"timeout = provider.get_timeout(USE_CONFIG_TIMEOUT)\nif timeout and timeout < 120 and expected_large_output:\n    timeout = 300  # raise for large completions","typeGuard":null,"tryCatchPattern":"import asyncio\n\nfor attempt in range(3):\n    try:\n        rsp = await provider._achat_completion(messages, timeout=600)\n        break\n    except TimeoutError:\n        if attempt == 2:\n            raise\n        await asyncio.sleep(2 ** attempt)\n# note: aiohttp errors were already wrapped into builtin TimeoutError","preventionTips":["Set LLM_API_TIMEOUT generously (>= 300s) for long generations","Prefer streaming mode for big outputs","Wrap completions in bounded retry with backoff for read timeouts"],"tags":["network","timeout","async","aiohttp","transient"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}