Content-Type is application/json.
Known errors
Requests the API can’t process, for example a size outside the supported sizes, fail with an error status too. Print the status and the body to see why.
Handle errors
Retries
- Most 4xx errors mean the request needs a change: a token, a parameter, or a size. Fix it before sending again; retrying the same request gives the same result. The exception is going over the rate limits, below.
- 5xx errors and network timeouts are usually temporary. Retry with exponential backoff, for example after 1, 2, and 4 seconds.
- Rate limits are 100 images per minute and 5 requests per second per user. Space out your requests to stay under them, and back off when requests start failing. See Limits and sizes.
Related
Limits and sizes
Rate limits, sizes, prompt length, and input limits.
Quickstart
Get a token and make a request that works.