Quick Answer
- Use POST /v1/images/generations with model=gpt-image-2.
- Supports prompt generation and reference_images URL inputs for guided generation.
- Reference images must be URLs, so local files must be uploaded first instead of passing base64 directly.
- The endpoint returns an async task id for later status polling.
Key Parameters
- model | string | required | gpt-image-2 | - | Use gpt-image-2 as the exact model id.
- prompt | string | required | - | - | Primary prompt for image generation or editing.
- size | string | optional | 1024x1024 | Use documented combinations with resolution | Output size constrained by documented resolution combinations.
- resolution | string | optional | 1024 | 1024 | 1536 | 2048 | Output resolution with documented size constraints.
- reference_images | string[] | optional | - | URL array | Reference image URL array. Local files must be uploaded first; no direct base64 references.
- image_urls | string[] | optional | - | URL array (compat field) | Compatibility field; prefer reference_images for new integrations.
- response_format | string | optional | url | url | b64_json | Response format; current Chinese docs recommend url.
Common Errors
- 400 invalid_request_error: trigger=Missing required fields or invalid size-resolution combinations.; fix=Validate model, prompt, size, resolution, and response_format against docs.; retry=Retry only after correcting the payload.
- 400 invalid_reference_images: trigger=Passing base64, local paths, or non-URL reference_images values.; fix=Upload the image first and pass the resulting URL in reference_images.; retry=Retry after fixing the reference image input.
- 401 authentication_error: trigger=Missing Authorization header or invalid API key.; fix=Verify bearer token format and key scope.; retry=Retry after fixing authentication.
- 429 rate_limit_exceeded: trigger=Request rate, concurrency, or current quota hits upstream rate limiting.; fix=Apply exponential backoff first, then review request rate, concurrency, and quota usage.; retry=Use 1s/2s/4s backoff with jitter; if it persists, reduce submission pressure.


