{"record":{"id":"2ffcf4a6a9cba0bd","repo":"HKUDS/DeepTutor","slug":"network-error-connecting-to-binding-api-e","errorCode":null,"errorMessage":"Network error connecting to {binding} API: {e}","messagePattern":"Network error connecting to (.+?) API: (.+?)","errorType":"http","errorClass":"LLMAPIError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/llm/cloud_provider.py","lineNumber":442,"sourceCode":"                                )\n                    else:\n                        raise LLMAPIError(\n                            f\"OpenAI API error: {error_text}\",\n                            status_code=resp.status,\n                            provider=binding or \"openai\",\n                        )\n        except aiohttp.ClientError as e:\n            # Handle connection errors with more specific messages\n            if \"forcibly closed\" in str(e).lower() or \"10054\" in str(e):\n                raise LLMAPIError(\n                    f\"Connection to {binding} API was forcibly closed. \"\n                    \"This may indicate network issues or server-side problems. \"\n                    \"Please check your internet connection and try again.\",\n                    status_code=0,\n                    provider=binding or \"openai\",\n                ) from e\n            else:\n                raise LLMAPIError(\n                    f\"Network error connecting to {binding} API: {e}\",\n                    status_code=0,\n                    provider=binding or \"openai\",\n                ) from e\n\n    if content is not None:\n        # Clean thinking tags from response using unified utility\n        return clean_thinking_tags(content, binding, model)\n\n    raise LLMConfigError(\"Cloud completion failed: no valid configuration\")\n\n\nasync def _openai_stream(\n    model: str,\n    prompt: str,\n    system_prompt: str,\n    api_key: str | None,\n    base_url: str | None,","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/llm/cloud_provider.py#L424-L460","documentation":"The generic branch of the aiohttp.ClientError handler in _openai_complete: any client-side transport failure that is not a 'forcibly closed' reset (DNS failure, connection refused, SSL errors, timeouts surfacing as ClientError) is wrapped as LLMAPIError with status_code=0 and the original exception text. The `from e` chain preserves the underlying cause for debugging.","triggerScenarios":"DNS cannot resolve the provider host; endpoint port not listening (local Ollama/vLLM not started); TLS certificate verification failure; proxy misconfiguration since trust_env=True honors HTTP_PROXY/HTTPS_PROXY.","commonSituations":"Local LLM server not running before the call; corporate proxy env vars routing the API call wrongly; self-signed certs on a private gateway; container missing CA certificates.","solutions":["Inspect the chained cause (`e.__cause__`) to identify DNS/refused/SSL precisely.","Verify the service is up: curl the base_url; for local backends, start Ollama/vLLM first.","Unset or correct HTTP_PROXY/HTTPS_PROXY if a proxy intercepts the call.","For SSL issues on private gateways, install the CA cert into the trust store rather than disabling verification."],"exampleFix":"// before\nresp = await complete(prompt=p, model=\"llama3\", base_url=\"http://localhost:11434\")\n\n# after\n# ensure Ollama is running first: `ollama serve`\nresp = await complete(prompt=p, model=\"llama3\", base_url=\"http://localhost:11434/v1\")","handlingStrategy":"try-catch","validationCode":"import socket\nhost = urlparse(base_url or \"https://api.openai.com\").hostname\nsocket.getaddrinfo(host, 443)  # DNS sanity check before the call","typeGuard":null,"tryCatchPattern":"try:\n    out = await complete(prompt=p, model=m, base_url=u)\nexcept LLMAPIError as e:\n    if e.status_code == 0 and e.__cause__ is not None:\n        log.warning(\"transport failure: %r\", e.__cause__)\n        # distinguish DNS vs refused vs TLS from the cause type\n    raise","preventionTips":["For local backends, verify the server is listening before calling (curl the base_url).","Audit HTTP_PROXY/HTTPS_PROXY when behind corporate networks.","Keep CA certificates current in containers."],"tags":["llm","network","aiohttp","dns","connection-refused"],"backgroundTag":"connection-refused","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}