gpt-image-2
openai/gpt-image-2Generate an image from a written description.
- token
Official price: $5.00Sale price: $3.575Price: $0Official price: $30.00Sale price: $21.4528.5% off- OpenAI
- 5 min
Overview
Generate an image from a text prompt. The request may return RUNNING before the image is ready; poll GET /v1/runs/{runId} until COMPLETED. Returns one image. Low and high quality require 1:1 at 1024 × 1024. Medium is the default and retains 1:1, 3:2 and 2:3 framing.
After COMPLETED, decode run.output.data[0].b64_json from base64 to save the image.
Input
These go in the input object of the run request.
| Field | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | What to draw, in plain language. Maximum: 32000 |
| aspect_ratio | string | No | Shape of the image: 1:1; medium also accepts 3:2 or 2:3. Square when omitted. |
| resolution | string | No | Size class of the image: 1K. 1K when omitted. |
| quality | string | No | Image quality. All qualities use the canonical GPT Image 2 billing route. Allowed: low, medium, high Default: "medium" |
Requests up to 1 MB, prompt up to 32,000 characters.
Example
Use your own API key and a saved idempotency key for each new job. Replace image or media placeholders with your own publicly reachable HTTPS URLs. Keep the same key and request body when recovering a timeout.
# Set once per job; reuse this key and the identical body after a timeout.
: "${AGENTSKY_IDEMPOTENCY_KEY:?Set a unique, saved key for this job}"
curl --fail-with-body https://gateway.agentsky.dev/v1/run \
-H "authorization: Bearer $AGENTSKY_API_KEY" \
-H "content-type: application/json" \
-H "Idempotency-Key: $AGENTSKY_IDEMPOTENCY_KEY" \
-d '{"provider":"openai","endpoint":"gpt-image-2","input":{"prompt":"A paper airplane over a city at dusk, flat illustration"}}'
# If status is READY/RUNNING, poll GET /v1/runs/{runId} with the same API key.Pricing
28.5% offPrices per million tokens, using your plan when signed in. Read the final customer charge from price.amount.value after the run finishes. A RUNNING response is not the final bill.
| Meter | USD per million tokens |
|---|---|
| Text input | |
| Text output | Price: $0 |
| Image output |
