502 upstream_error: when to try again and when to choose another model

Coding with AIChoosing a Tool & Fixing Errors·· 9 views· 3 min read

502 with the code upstream_error means the AI service behind our API did not respond as expected. It usually has nothing to do with your setup: with a wrong key or model, the answer would be 401 or 404, not 502.

First, try again

502 is one of the errors worth repeating after a pause, like 429, 500 and 503. The tools usually do it on their own: Claude Code retries failed requests up to 10 times by default (CLAUDE_CODE_MAX_RETRIES). Codex retries up to 4 times (request_max_retries) and up to 5 when a streaming answer is cut off (stream_max_retries). If the error still shows, wait a few minutes and send the message again.

When to choose another model

If the 502 keeps coming with the same model while the others answer, change the model and keep working:

Tool How to change the model
Claude Code /model zai-org/glm-5.2
Codex CLI codex -m zai-org/glm-5.2, for that session only
OpenCode /models, with the model already written in the file
Cursor The model picker, with the model already added in Add Custom Model
Cline The Model ID field

Choose among the recommended coding models. With the Coding Plan, all six spend plan points. If you move from a model of about a million tokens to moonshotai/kimi-k2.7-code, which reads 262,144, lower the context you set in the tool as well.

500, 502 and 503: the difference

Answer What it is What to do
500 internal_error A failure on our side. Try again later and give the correlation_id to support.
502 upstream_error The AI service behind the API did not respond as expected. Try again or choose another model.
503 disabled The API is switched off at the moment. Try again later.

When to ask for help

In Claude Code the error arrives as api_error; in Codex, with the code upstream_error. If the 502 shows with several models for a long time, open a support ticket with the correlation_id (in Claude Code, the request_id), the time, the tool and the model.

Never send the key in a support ticket, by chat or by email. Support does not need it.

Want to code with All in One AI models? Visit the Coding with AI page.

See Coding with AI

SEE ALSO

The recommended coding models

Errors when setting up a tool

429 rate_limited in a coding tool

Using Claude Code with All in One AI

Coding with AI in All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 396,00 MT/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.