GPT-Image-2 API

2026-04 image gen

POST /v1/images/generations

gpt-image-2: Image generation, required fields, nested response schema and a fictional example.

Basic request

Required parameters: model, prompt

Available parameters: model, prompt, n, size, quality, output_format, background

Request parameters

ParameterTypeRequiredDescription
modelstringYesExact model identifier shown on this page. Options: gpt-image-2
promptstringYesImage prompt, or the requested change in editing workflows.
nintegerNoRequested image count; the example uses one.
sizestringNoImage size supported by this model.
qualitystringNoOutput quality supported by the model.
output_formatstringNoImage encoding. Options: png / jpeg / webp
backgroundstringNoBackground mode. Options: auto / opaque / transparent
## Usage and response conventions - Follow required fields and the nested schema. Optional settings without a documented numeric default use the current model default. - Context, output budgets and media constraints differ by model. Unverified limits are not universal guarantees. - An absent value differs from a reported zero. Read status, content and usage as actually returned. - Replace example.invalid addresses with readable media you are authorized to use. - Save generated files promptly; result links need not remain available indefinitely. ## Reference Terminology: [OpenAI Images](https://developers.openai.com/api/reference/resources/images/methods/generate). Use this page's platform base URL and exact model identifier for requests. Reviewed: 2026-11-07. ## Complete nested field reference Array elements use []. Required flags apply only when the enclosing object or content-block variant is used. Response fields can be absent or null as described; false does not imply a fabricated zero. ### Request headers | Field path | Type | Required in its object | Meaning | |---|---|---|---| | `Content-Type` | string | Yes | JSON request-body content type. | ### Request body | Field path | Type | Required in its object | Meaning | |---|---|---|---| | `model` | string | Yes | Exact model identifier shown on this page. Values: gpt-image-2 | | `prompt` | string | Yes | Image prompt, or the requested change in editing workflows. | | `n` | integer | No | Requested image count; the example uses one. Minimum: 1 | | `size` | string | No | Image size supported by this model. | | `quality` | string | No | Output quality supported by the model. | | `output_format` | string | No | Image encoding. Values: png, jpeg, webp | | `background` | string | No | Background mode. Values: auto, opaque, transparent | ### Response 200 | Field path | Type | Required in its object | Meaning | |---|---|---|---| | `created` | integer | No | Creation time in Unix seconds. | | `data` | array[object] | No | Image results; read url or b64_json as returned. | | `data[].url` | string | No | Image URL when URL output is used. | | `data[].b64_json` | string | No | Base64 image data when inline output is used. | | `data[].revised_prompt` | string | No | Revised prompt, when returned. | | `usage` | object | No | Optional reported usage. | | `usage.input_tokens` | integer | No | Input tokens. | | `usage.output_tokens` | integer | No | Output tokens. | | `usage.total_tokens` | integer | No | Total tokens. | ### Error response structure | Field path | Type | Required in its object | Meaning | |---|---|---|---| | `error` | object | No | Error details for this request. | | `error.message` | string | No | Message content or a readable error explanation, according to its enclosing object. | | `error.type` | string | No | Type discriminator; use the values documented for the enclosing object. | | `error.code` | string | No | Error code; it may be empty. |

Request example

curl --request POST https://api.router.ai/v1/images/generations \
  --header "Authorization: Bearer $API_KEY" \
  --header "Content-Type: application/json" \
  --data-raw '{
  "model": "gpt-image-2",
  "prompt": "A fictional blue paper boat on a plain white background."
}'

Endpoint reference: Aliyun Qwen-Image text-to-image