OpenAI logo

gpt-image-2

by OpenAI
openai/gpt-image-2

gpt-image-2 is a image model from OpenAI, callable through the AgentSky API as openai/gpt-image-2 and billed per token (Single image generation (example): 1K (default): $0.0247 · 2K: $0.0297 · 4K: $0.033 · Other requests: Text input: $3.575 / 1M tokens · Text output: $0 / 1M tokens · Image output: $21.45 / 1M tokens).

Generate an image from a written description.

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. Configured flat-price generation supports square, landscape and portrait: 1K is 1024×1024, 1360×768 or 768×1360; 2K is 2048×2048, 2736×1536 or 1536×2736; 4K is 2880×2880, 3840×2160 or 2160×3840. Landscape and portrait use 16:9 and 9:16. Other routes support 1K only: low/high square and medium square, 3:2 or 2:3. Medium is the default.

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: 32000
aspect_ratiostringNoShape of the image: 1:1; flat-price routes also accept 16:9 or 9:16; native medium also accepts 3:2 or 2:3. Square when omitted.
resolutionstringNoSize class of the image: 1K; flat-price routes also accept 2K or 4K. 1K when omitted.
qualitystringNoImage quality. Consult pricing_routes for any configured flat-price generation; other requests use native token billing.
Allowed: auto, 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

Prices by supplier route and resolution, 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.

Single image generation — used by the example

Flat price for prompt, quality auto, low, medium or high (medium when omitted), aspect_ratio 1:1, 16:9 or 9:16 (square when omitted), and resolution 1K, 2K or 4K (1K when omitted); no additional fields. 4K square is 2880x2880.

Input conditionsAvailabilityUSD per image
1K (default)AvailableOfficial price: $0.0346Sale price: $0.0247
2KAvailableOfficial price: $0.0415Sale price: $0.0297
4KAvailableOfficial price: $0.0461Sale price: $0.033

Other requests

All other supported requests use native token pricing, including editing and streaming.

Input conditionsAvailabilityUSD per million tokens
otherAvailableText input / 1M tokensOfficial price: $5.00Sale price: $3.575Text output / 1M tokensPrice: $0Image output / 1M tokensOfficial price: $30.00Sale price: $21.45

Questions