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, and404mean 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.429means 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 noRetry-Afterheader. See Limits and sizes.500and network timeouts are usually temporary. Retry with the same backoff. If the error stays, send theerror_idfrom the body to support.
Related
Limits and sizes
Rate limits, sizes, prompt length, and input limits.
Quickstart
Get a token and make a request that works.