Beginner Q&A: Will retrying a streaming request after a 504 charge me twice?
A 504 says a gateway did not receive an upstream response in time; it does not prove the request never ran. Identify whether failure occurred before connection, before the first byte or mid-stream, then check request and billing records before retrying.
The short answer
Do not blindly resend a request after a 504. RFC 9110 defines 504 as a gateway or proxy failing to receive a timely response from an upstream server needed to complete the request. It describes what happened while the gateway was waiting; it does not prove that the model never received the request or that generation never began. 1
For ordinary text generation, resending may create a second call and a second charge. For an agent that uses tools, also consider whether the first request already triggered an external action. First determine whether the failure happened before the request was established, while waiting for a response, or after some streaming output arrived. Then decide whether to retry or query the request's status. The safe rule is: when the outcome is unknown, check first; do not treat 504 as proof of non-execution.
504, 502 and a broken stream are different
- 504 Gateway Timeout: a gateway or proxy did not receive an upstream response in time. The status alone does not show where processing stopped. 1
- 502 Bad Gateway: a gateway received an invalid response from upstream, a different kind of upstream interaction failure. The response body and service logs still matter. 2
- A streaming connection break: the client may have received several pieces of output before the connection dropped. The model may have generated more, or may have finished; not receiving the final event does not prove the server cancelled the task. Streaming APIs commonly send events incrementally over SSE, and the Responses API can emit distinct text-delta, completion and error events. 3
Keep three things separate: HTTP status, connection state and business completion state. A client message that merely says “timeout” cannot establish whether billing or a tool side effect has occurred.
Questions and answers
Q: If a 504 appears immediately after I send a request, does that guarantee there was no charge?
A: No. Confirm whether the request reached the gateway, whether it was forwarded, and whether the provider can look up a processing record by request ID. A failure during local DNS, TLS or connection setup differs from a timeout after the request reached upstream, but client-side error text alone may not distinguish them. You may need transport logs or server-side tracing.
Q: I saw a few text chunks, then the stream dropped. Can I start over?
A: A restart may create a duplicate full call. Save the received text and event sequence, and check whether a completion event such as response.completed arrived. If there is no terminal event, record the request time, model, request ID and last received output, then check server status or billing. If you must retry, treat it as a potentially second call and keep both attempts linked in your records.
Q: Can I automatically retry a request that contains a tool call after a 504?
A: Do not do so by default. The model may already have emitted a tool call, and an external system may have completed the action even though the response timed out on its way back. For actions with side effects—payments, messages or resource creation—use an idempotency key, business reference or status lookup at the tool service. Model-request retry logic is not a substitute for tool-side idempotency.
Q: When is retrying after a 504 reasonable?
A: Retry automatically only when you have evidence that the previous attempt produced no result or side effect, the provider gives a safe-retry signal, or the operation has reliable idempotency. Even for safe read-only requests, use a small retry limit, exponential backoff and an overall time budget so many clients do not amplify congestion by replaying together.
A practical investigation order
- Preserve the evidence. Record UTC time, HTTP status, request path, model ID, whether streaming was enabled, client version and any gateway request identifier. Do not record API keys or complete sensitive prompts.
- Identify the transport stage. Distinguish failure before connection, while waiting for the first response byte, after response headers, or after streaming deltas have arrived. An exception name is not enough evidence; use network logs or server-side tracing when available.
- Check the completion marker. For a stream, verify whether the protocol's completion event arrived. If you have only deltas and no completion event, treat the outcome as unknown; do not claim the task definitely failed or succeeded. 3
- Look up the request and bill. Use the gateway request ID, account usage record or provider support to check whether the call exists, what usage was recorded and whether a refund occurred. Give each retry its own correlation ID.
- Query before replaying. If the business offers a status or result-recovery endpoint, query the original request first. Do not resubmit a side-effecting operation while its state is uncertain.
- Check timeout layers. The client, reverse proxy, gateway and upstream API may each have a timeout. A shorter intermediate timeout can disconnect the client while upstream work is still in progress. Inspect configuration and logs layer by layer instead of simply increasing the client timeout.
- Limit automatic retries. Enable them only for errors known to be retryable and operations that are idempotent. Set a maximum count, backoff, jitter and total time limit, and monitor retry rates.
Useful settings for gateway users
- Set appropriate client and proxy timeouts for long generations, with consistent budgets across layers.
- Make the SSE client parse event boundaries and terminal events correctly; receiving a text chunk does not mean the call is complete.
- Generate a correlation ID for each business request so logs, billing records and support tickets can be reconciled.
- Use idempotency keys for tools that can create external side effects, and persist tool execution status separately.
- If upstream completion is unclear, ask the provider to check its records before clicking retry repeatedly.
Remember this
A 504 means the gateway did not receive an upstream response in time—not that the upstream definitely did nothing. Check request status and side effects before retrying.
1: RFC 9110, 15.6.5: 504 Gateway Timeout, IETF/RFC Editor. 2: 502 Bad Gateway - HTTP, MDN Web Docs. It describes 502 as a gateway receiving an invalid upstream response; failure to receive a timely upstream response is generally 504. 3: Streaming events, OpenAI Platform. It describes incremental SSE delivery and typed semantic events in the Responses API, including text deltas, completion and errors.
Sources & attribution
This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.
- RFC 9110: HTTP Semantics, 504 Gateway Timeout — RFC Editor / IETF · accessed 2026-11-29Note:RFC 9110 defines 504 as a gateway or proxy not receiving a timely response from an upstream server needed to complete the request.
- 504 Gateway Timeout - HTTP — MDN Web Docs · accessed 2026-11-29Note:MDN describes 504 as a proxy or gateway failing to receive an upstream response in time; the status alone does not establish whether upstream side effects completed.
- Streaming API responses — OpenAI Platform · accessed 2026-11-29Note:OpenAI's official streaming documentation describes incremental SSE delivery; the Responses API uses semantic events that distinguish text deltas, completion and errors.
One key for Claude, GPT and 50+ models
The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.