HKUDS/DeepTutor · error · LLMAPIError
Network error connecting to {binding} API: {e}
Error message
Network error connecting to {binding} API: {e} What it means
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.
Source
Thrown at deeptutor/services/llm/cloud_provider.py:442
)
else:
raise LLMAPIError(
f"OpenAI API error: {error_text}",
status_code=resp.status,
provider=binding or "openai",
)
except aiohttp.ClientError as e:
# Handle connection errors with more specific messages
if "forcibly closed" in str(e).lower() or "10054" in str(e):
raise LLMAPIError(
f"Connection to {binding} API was forcibly closed. "
"This may indicate network issues or server-side problems. "
"Please check your internet connection and try again.",
status_code=0,
provider=binding or "openai",
) from e
else:
raise LLMAPIError(
f"Network error connecting to {binding} API: {e}",
status_code=0,
provider=binding or "openai",
) from e
if content is not None:
# Clean thinking tags from response using unified utility
return clean_thinking_tags(content, binding, model)
raise LLMConfigError("Cloud completion failed: no valid configuration")
async def _openai_stream(
model: str,
prompt: str,
system_prompt: str,
api_key: str | None,
base_url: str | None,View on GitHub (pinned to 3e82f13042)
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.
Example fix
// before resp = await complete(prompt=p, model="llama3", base_url="http://localhost:11434") # after # ensure Ollama is running first: `ollama serve` resp = await complete(prompt=p, model="llama3", base_url="http://localhost:11434/v1")
Defensive patterns
Strategy: try-catch
Validate before calling
import socket host = urlparse(base_url or "https://api.openai.com").hostname socket.getaddrinfo(host, 443) # DNS sanity check before the call
Try / catch
try:
out = await complete(prompt=p, model=m, base_url=u)
except LLMAPIError as e:
if e.status_code == 0 and e.__cause__ is not None:
log.warning("transport failure: %r", e.__cause__)
# distinguish DNS vs refused vs TLS from the cause type
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Connection to {binding} API was forcibly closed. This may in
- OpenAI SDK connection error: {exc}
- result.error or "Could not connect to the LightRAG server."
- Channel onboarding provider request failed ({type(exc).__nam
- This model is not assigned to your account.
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/2ffcf4a6a9cba0bd.
Report an issue: GitHub.