HTTP 504 Gateway Stream Timeout — Streaming & Timeout Fix
Common when disabling streaming (stream: false) on long reasoning or generation tasks, causing proxies or clients to time out before the full payload finishes.
Need resilient routing with automatic multi-upstream failover and full request telemetry on API Store Hub?
Error runbook
| HTTP Status | 504 |
|---|---|
| Error type | gateway_timeout |
| Retry policy | Retryable |
Common when disabling streaming (stream: false) on long reasoning or generation tasks, causing proxies or clients to time out before the full payload finishes.
Metadata & root causes
- Synchronous non-streaming requests producing thousands of tokens over 60–90+ seconds.
- Application reverse proxy (Nginx, CDN, ALB) has a read timeout shorter than model generation time.
- Deep reasoning phase delayed time-to-first-token past the client socket deadline.
3 steps to resolve
- Immediate diagnosis: Enable stream: true to receive SSE chunks continuously as soon as the first token arrives.
- Apply standard fix: Raise HTTP client/SDK read timeout to at least 120 seconds for complex analysis or code generation.
- Prevent recurrence in production: For ultra-low-latency UX (chatbots/realtime), route to high-speed models like Haiku, Gemini, or DeepSeek.
Production retry & recovery snippet
cURL
curl -N --max-time 180 https://apistorehub.com/v1/chat/completions \
-H "Authorization: Bearer sk-ash-your_key" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-5-5","stream":true,"messages":[{"role":"user","content":"Write a concise architecture checklist"}]}'Python
import httpx, os
from openai import OpenAI
client = OpenAI(
base_url="https://apistorehub.com/v1",
api_key=os.environ["API_KEY"],
timeout=httpx.Timeout(180.0, connect=10.0),
)
with client.chat.completions.stream(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Analyze this architecture."}],
) as stream:
for event in stream:
if event.type == "content.delta":
print(event.delta, end="", flush=True)Frequently asked questions
- Am I billed on API Store Hub when an HTTP 504 (gateway_timeout) error occurs?
- No. Atomic pre-hold settlement on API Store Hub automatically releases any reserved amount for failed requests that return no valid completion.
- How do I tell whether the error originated from my client or upstream?
- 4xx codes (except 429) usually point to auth headers, wallet quota, or request payload formatting; 429/502/504/529 indicate load or transient upstream conditions visible on /status.
- Can I fall back to another model without changing SDKs?
- Yes. Pass the fallback model ID (e.g. across Claude, GPT, DeepSeek, or Gemini) inside your retry catch block using your existing sk-ash- API key.