Streaming requests with large context (~220k+ tokens) hang 5–12+ minutes with zero bytes before dropping
Summary
When sending streaming OpenAI-compatible /v1/chat/completions requests with large contexts (~220k+ tokens), aistudio2api.exe sometimes accepts the HTTP request and holds the SSE connection open for 5–12+ minutes without sending any response tokens or closing the stream, before finally dropping the stream with no content (or later returning 503 Service unavailable: AIStudio2API generation service stopped).
Environment
- Binary:
aistudio2api.exeon Windows (http://127.0.0.1:2048/v1,openai-completionsstreaming) - Model:
gemini-4-neon(reasoning enabled) - Context size: ~228k tokens (~57% of 400k window)
Observed Timeline (UTC)
From client session logs against http://127.0.0.1:2048/v1:
14:04:40Z -> 14:09:28Z(4m 48s): Request held open with zero tokens, then stream ended before any response content or stop signal (stream_drop).14:13:57Z -> 14:25:14Z(11m 16s): Request held open with zero tokens, thenstream_drop(ended before any content or stop signal).14:25:14Z -> 14:33:55Z(8m 42s): Automatic retry held open with zero tokens until manually aborted.14:38:16Z -> 14:40:24Z(2m 08s): Held open with zero tokens, thenstream_drop, followed immediately by:503 Service unavailable: AIStudio2API generation service stopped: click "Start service" in the console
Expected Behavior
- If the upstream AI Studio generation fails to start or stalls with no first token within a reasonable timeout (e.g. 60–90s),
aistudio2apishould fail fast and return an HTTP error (e.g.503/504) instead of holding the SSE connection open for 5–12+ minutes before dropping it. - If the generation service stops while a request is in flight, in-flight SSE connections should be closed immediately with an error rather than hanging.
The stop part is fixed in Mag1cFall/AIStudio2API#216 · fix: 停止生成服务时进行中的请求返回生成服务已停止, in-flight requests now end right away with service_stopped instead of context canceled. The long zero-byte waits come from upstream, Gemini 4 sometimes takes 2~10 min before the first token and still finishes normally (hundreds of those in my logs), so a fixed 60~90s cutoff would kill those too; the next release adds FIRST_EVENT_TIMEOUT (off by default) to drop a stalled attempt and switch accounts, and REQUEST_TIMEOUT also counts the wait before the first token.