ERROR CODES / ENGLISH

Relay 504 Gateway Timeout: long requests time out

How a 504 differs from a 502, why long answers trigger it, and what to change on the client and on the relay side.

Reviewed 2026-11-13 · ERROR CODES / 504 · Chinese detail: 完整中文页

What it means

A 504 means the gateway waited for the upstream until it timed out. Long answers are the most likely to trigger it.

504 Gateway Timeout

A 502 means the gateway could not reach a working upstream at all; a 504 means it reached the upstream but did not receive a response in time. Both errors come from the site's gateway, not from your client.

Common causes

ShareCause
55%The site's upstream timeout is set too short
25%The upstream responds slowly
20%The request itself is too long

How to confirm

Send a short request first. If short requests succeed and long ones fail, the timeout setting is the likely cause. If every request returns 504, the upstream is down. If switching sites fixes it, the original site's configuration is at fault.

Fix

On your side:

  1. Shorten the single request (split it into segments).
  2. Turn off streaming, or switch to non-streaming.
  3. Switch site.

On the service side:

  1. The site needs to raise its read timeout.

If it still fails

SymptomResponsible party
Short requests workTimeout setting
All requests return 504Upstream down
Switching site fixes itSite configuration

For long-form generation, prefer sites with generous timeout settings. A 504 tells you the gateway gave up, not that the model produced a bad answer.

General guidance, not a statement about any specific provider. For measured data, see the relay directory and method.