gpt-image-2

by OpenAI

openai/gpt-image-2

Generate an image from a written description.

Billed per
token
Price
Text input / 1M tokensPrice: $5.00Text output / 1M tokensPrice: $0Image output / 1M tokensPrice: $30.00
Provider
OpenAI
Timeout
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.

FieldTypeRequiredDescription
promptstringYesWhat to draw, in plain language.
Maximum: 1000
aspect_ratiostringNoShape of the image: 1:1; medium also accepts 3:2 or 2:3. Square when omitted.
resolutionstringNoSize class of the image: 1K. 1K when omitted.
qualitystringNoImage quality. A quality must be available in pricing_tiers before it can run.
Allowed: low, medium, high
Default: "medium"

Requests up to 1 MB, prompt up to 1,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

Prices 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.

QualityAvailabilityText inputText outputImage output
lowAvailablePrice: $5.00Price: $0Price: $30.00
medium (default)AvailablePrice: $5.00Price: $0Price: $30.00
highAvailablePrice: $5.00Price: $0Price: $30.00

Questions