Skip to main content
A failed request returns a non-2xx HTTP status. The body explains the error, but its format varies: some errors return plain text, others JSON. Read the body as text first, and parse it as JSON only when Content-Type is application/json.

Known errors

JSON errors always have a code and a message. Use code to tell errors apart: two different errors can share the 400 status, and message can be empty. Other 400 codes exist, for example prompt_is_improper when the content filter blocks a prompt.

Handle errors

Retries

  • 400, 401, and 404 mean the request needs a change: a token, a parameter, a size, or more API units. Fix it before sending again; retrying the same request gives the same result.
  • 429 means you went over a rate limit: 100 images per minute or 5 requests per second per user. Wait and retry with exponential backoff, for example after 1, 2, and 4 seconds. The response has no Retry-After header. See Limits and sizes.
  • 500 and network timeouts are usually temporary. Retry with the same backoff. If the error stays, send the error_id from the body to support.

Limits and sizes

Rate limits, sizes, prompt length, and input limits.

Quickstart

Get a token and make a request that works.