NousResearch/hermes-agent · error · GeminiAPIError
gemini_stream_error
gemini_stream_error
Error message
Gemini streaming request failed: {exc} What it means
The streaming Gemini request (streamGenerateContent?alt=sse) failed with an httpx.HTTPError — connection error, timeout, or protocol-level failure during the SSE stream — before or while yielding chunks. It is wrapped in GeminiAPIError with code 'gemini_stream_error'. HTTP-status errors inside the stream are handled separately (gemini_http_error), so this code specifically means transport failure.
Source
Thrown at agent/gemini_native_adapter.py:1088
return translate_gemini_response(payload, model=model)
def _stream_completion(self, *, model: str, request: Dict[str, Any], timeout: Any = None) -> Iterator[_GeminiStreamChunk]:
url = f"{self.base_url}/models/{model}:streamGenerateContent?alt=sse"
stream_headers = dict(self._headers())
stream_headers["Accept"] = "text/event-stream"
def _generator() -> Iterator[_GeminiStreamChunk]:
try:
with self._http.stream("POST", url, json=request, headers=stream_headers, timeout=timeout) as response:
if response.status_code != 200:
body_text = read_streaming_error_body(response)
raise gemini_http_error(response, body_text=body_text)
tool_call_indices: Dict[str, Dict[str, Any]] = {}
for event in _iter_sse_events(response):
for chunk in translate_stream_event(event, model, tool_call_indices):
yield chunk
except httpx.HTTPError as exc:
raise GeminiAPIError(
f"Gemini streaming request failed: {exc}",
code="gemini_stream_error",
) from exc
return _generator()
class AsyncGeminiNativeClient:
"""Async wrapper used by auxiliary_client for native Gemini calls."""
def __init__(self, sync_client: GeminiNativeClient):
self._sync = sync_client
self.api_key = sync_client.api_key
self.base_url = sync_client.base_url
self.chat = _AsyncGeminiChatNamespace(self)
# Expose the underlying sync client as _real_client so the auxiliary
# cache's eviction-by-leaf-client helper (#23482) can find and drop
# this async entry when the sync GeminiNativeClient is poisoned.View on GitHub (pinned to c896c09c42)
Solutions
- Retry the request — transient resets during long streams are common and usually succeed on retry.
- Increase the client timeout passed to the adapter if failures cluster at a consistent elapsed time (timeout too small).
- Check network stability (VPN/proxy) if streams consistently die mid-generation.
- If persistent, capture the underlying httpx error message to distinguish connect vs read failures.
Example fix
# caller-side retry for transient stream transport errors
from agent.gemini_native_adapter import GeminiAPIError
for attempt in range(3):
try:
chunks = list(client.chat.completions.create(model=m, messages=msgs, stream=True))
break
except GeminiAPIError as e:
if e.code != "gemini_stream_error" or attempt == 2:
raise Defensive patterns
Strategy: retry
Try / catch
from agent.gemini_native_adapter import GeminiAPIError
for attempt in range(3):
try:
chunks = list(client.chat.completions.create(model=m, messages=msgs, stream=True))
break
except GeminiAPIError as e:
if e.code != 'gemini_stream_error' or attempt == 2:
raise Prevention
- Retry transient stream transport failures once or twice before failing
- Size timeouts for slow generations to avoid read timeouts mid-stream
- Stabilize network (VPN/proxy) when streams consistently drop
When it happens
Trigger: Any httpx.HTTPError raised inside the stream generator: DNS/connect failure, connection reset mid-stream, read timeout while waiting for SSE events, TLS errors.
Common situations: Flaky network or VPN drops during long streaming generations; Google API transient resets; local firewall killing long-lived SSE connections; timeout configured too aggressively for slow generations.
Related errors
- Gateway did not return a WS ticket.
- Reached the gateway over HTTP, but the live WebSocket (/api/
- Extension "${id}" was not found on the Marketplace.
- Could not fetch image: ${response.status}
- Could not refresh the remote gateway WebSocket ticket.
AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14).
Data as JSON: /api/errors/f428bd143d4f180e.
Report an issue: GitHub.