APIKO
Image Series

GPT Image 2 API

  • gpt-image-2 generates images with POST /v1/images/generations and edits reference images with POST /v1/images/edits.
  • Send "async": true to get a task id right away, then poll GET /v1/tasks/{id}. Asynchronous calls are recommended.
  • Result links are APIKO-signed and kept for 24 hours; download anything you need to keep.
  • Billed by the tokens each result uses, so quality and size change the price. See Billing below.
POST
/
v1
/
images
/
generations
TASK_ID=$(curl https://api.apiko.app/v1/images/generations \
  -H "Authorization: Bearer $APIKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "A cinematic product photo on a marble table",
  "async": true
}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')

while :; do
  TASK=$(curl -s https://api.apiko.app/v1/tasks/$TASK_ID \
    -H "Authorization: Bearer $APIKO_API_KEY")
  printf '%s\n' "$TASK"
  printf '%s' "$TASK" | grep -qE '"status": *"(completed|failed)"|"error": *\{' && break
  sleep 5
done
{
  "id": "task_abc123",
  "object": "image.task",
  "status": "queued",
  "created": 1790000000
}

Authorizations

Authorization
stringrequired
All requests use Bearer authentication: Authorization: Bearer <API_KEY>.
Create a key in Console → API Keys.
Routes
string
  • POST /v1/images/generations — text to image
  • POST /v1/images/edits — edit or combine reference images (JSON body with images)
  • GET /v1/tasks/{id} — query an asynchronous task

Body

application/json
model
stringdefault:gpt-image-2required
Use this exact public model id.
Available options: gpt-image-2
Example:"gpt-image-2"
prompt
stringrequired
Image description or edit instruction, at most 32,000 characters (a 32,000-character prompt is about 7,100 text input tokens).
A prompt over 32,000 characters is rejected with HTTP 400 before any charge (prompt is too long: at most 32000 characters).
Minimum length: 1
Maximum length: 32000
Example:"A cinematic product photo on a marble table"
size
stringdefault:1:1
Aspect ratio, rendered at the resolution tier; exact WIDTHxHEIGHT (multiples of 16, each edge at most 3840, long edge at most 3x the short, 655,360 to 8,294,400 pixels; resolution is then ignored); or auto. Omitted on /v1/images/generations = 1:1; omitted on /v1/images/edits = the first image's aspect ratio. Sizes outside these bounds are refused before billing.
Send a ratio from the list (sized by resolution), auto, or an exact WIDTHxHEIGHT within the bounds above. Anything else is rejected before any charge.
Available options: 1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 2:1, 1:2, 21:9, 9:21, 3:1, 1:3, auto
Example:"1:1"
resolution
enum<string>default:1k
Output tier for aspect-ratio sizes; omitted = 1k.
Values are lowercase. Omit the field for the default tier. The tier sets the output size, and with it the number of output tokens billed; see the model page for estimates.
Available options: 1k, 2k, 4k
Example:"1k"
quality
enum<string>default:medium
Rendering quality, billed by output tokens: a 1024x1024 image uses 196 at low, 1,756 at medium and 7,024 at high (1024x1536 high 5,488, 3840x2160 low 371); omitted = medium; auto lets the model choose and bills the level it used; no xhigh or max.
Higher levels use more output tokens and cost more; auto lets the model choose and is billed by the tokens it uses. See Billing below.
Available options: low, medium, high, auto
Example:"medium"
output_format
enum<string>default:png
Png, jpeg or webp; no transparent background (gpt-image-2 does not support it, also when the prompt asks for one) and no gif.
Available options: png, jpeg, webp
Example:"png"
output_compression
integer
0-100, only for jpeg or webp.
Range: 0 ≤ x ≤ 100
Example:0
moderation
enum<string>default:auto
Auto (default) or low.
Available options: auto, low
Example:"auto"
user
string
A stable ID for your end user (hash it); accepted and not forwarded upstream.
Maximum length: 256
images
string<uri>[]
Reference image HTTPS URLs, 1 to 16; each 1024x1024 reference is about 1,024 image input tokens; data URLs and plain HTTP are not accepted (upload a local file with POST /v1/uploads/images first); required for /v1/images/edits.
  • Accepted only by POST /v1/images/edits, where at least one image is required. Send the edits request as JSON, not multipart form data.
  • Every entry must be a publicly reachable HTTPS URL; file uploads, base64 and data URLs are rejected. For a local image, upload it to POST /v1/uploads/images first (multipart field file) and pass the returned url; uploads are kept 72 hours.
  • Each 1024×1024 reference adds about 1,024 image-input tokens to the charge (measured); larger references add more.
Items: 1–16
Example:["https://example.com/reference.png"]
mask
string<uri>
Inpainting mask HTTPS URL: a PNG with an alpha channel, the same size as the first image; the transparent area is what gets repainted; only for /v1/images/edits; it guides the edit, so pixels outside it may still change slightly.
  • Public HTTPS URL. Use it with images on POST /v1/images/edits.
  • Use a PNG with an alpha channel, the same size as the first image in images; transparent pixels mark the area to redraw.
  • Replace the example mask URL with your own: a mask that cannot be downloaded makes the task fail (refunded).
Example:"https://example.com/mask.png"
n
enum<integer>default:1
Only 1; send one request per image.
Only 1 is accepted. Send separate requests for more images.
Available options: 1
Example:1
response_format
enum<string>default:url
Results are always returned as APIKO-signed URLs.
Available options: url, b64_json
Example:"url"
async
booleandefault:false
True returns a task id; poll GET /v1/tasks/{id}.
  • Recommended. With true the response is a task object right away; poll GET /v1/tasks/{id} until it completes.
  • With false the request stays open until the image is ready. A request with no response after 100 seconds is closed with HTTP 524 but is still charged, and no task id comes back to fetch the image.
Example:false
callback_url
string<uri>
Optional public HTTPS URL notified when the task finishes.
  • When the task ends in completed or failed, APIKO POSTs the same JSON as GET /v1/tasks/{id} with header X-Apiko-Task-Id.
  • Each delivery waits up to 10 seconds; any 2xx response counts as delivered. A failed delivery is retried 3 times, after 2, 10 and 30 seconds.
  • Redirects are not followed: a 3xx response counts as a failed delivery. A callback_url that is not a public HTTPS URL is rejected when you submit (invalid_callback_url).
  • Callbacks are not signed: re-fetch the task to confirm the result.
Example:"https://your-domain.com/webhooks/apiko-task"

Response

200 - application/json

A slightly higher amount is reserved when the request is accepted and settled by the tokens used when the task completes; a task that ends in failed is refunded in full.

id
string
Task id returned by an async request. Use it with GET /v1/tasks/{id}.
Example:"task_abc123"
status
enum<string>
Task status. Poll every 5–10 seconds until it is completed or failed.
Available options: queued, in_progress, completed, failed
progress
string
Progress reported by the task, e.g. "100%".
data
object[]
Present when the task is completed. Each data[].url is an APIKO-signed image link kept for 24 hours; download anything you need to keep.
A synchronous request (async omitted or false) returns { "created": …, "data": [{ "url": … }] } directly.
usage
object
Present when the task is completed: input_tokens, input_tokens_details (text_tokens, image_tokens) and output_tokens. The charge is computed from these counts; see Billing.
fail_reason
string
Why the task failed. Failed tasks are refunded in full.
Image models answer one of: the prompt or a reference image was rejected by the content safety review; change them and try again (retrying the same input fails the same way), the image service is busy or temporarily unavailable; please retry later, the request or a reference image was not accepted; check the parameters and reference images, a reference image could not be downloaded; use a public https:// image URL or upload the image, or image generation failed.
GET /v1/tasks/{id}
object
The 200 response example is what submitting returns. Polling returns the task in this shape (a callback POSTs the same JSON):
Example:
{
  "id": "task_abc123",
  "task_id": "task_abc123",
  "status": "completed",
  "progress": "100%",
  "created_at": 1790000000,
  "finished_at": 1790000060,
  "fail_reason": "",
  "data": [
    {
      "url": "https://api.apiko.app/v1/tasks/task_abc123/artifacts/image-0/content?access=…"
    }
  ],
  "usage": {
    "input_tokens": 1148,
    "input_tokens_details": {
      "text_tokens": 48,
      "image_tokens": 1100
    },
    "output_tokens": 439
  }
}

Billing

GPT Image 2 is billed by the tokens each result uses, not per image. For per-image billing, use gpt-image-2-upscale.

Token prices
per 1M tokens
  • Text input: $4.00 (official $5.00)
  • Image input, which covers reference images: $6.40 (official $8.00)
  • Image output: $24.00 (official $30.00)
About 20% below OpenAI's list prices. These are the rates at the time of writing; the model page always shows the current ones.
Pre-charge and settlement
async
Submitting a request reserves a slightly higher amount from your balance. When the task completes, the charge for the tokens actually used replaces it and the difference is refunded automatically. A task that ends in failed is refunded in full.
usage
object
A completed result carries the tokens it was charged for, in the OpenAI shape. input_tokens_details.image_tokens counts the reference images of an edit.
Example:
{
  "usage": {
    "input_tokens": 48,
    "input_tokens_details": {
      "text_tokens": 48,
      "image_tokens": 0
    },
    "output_tokens": 1756
  }
}
quality
low | medium | high | auto
Quality changes the price: higher levels use more output tokens. Supported values are low, medium, high and auto. When quality is omitted the image is made at medium; with auto the model picks the level, and the submit-time reservation assumes medium.
Measured output tokens: 196 (low), 1,756 (medium) and 7,024 (high) at 1024×1024; 5,488 at 1024×1536 high; 1,372 at 1536×1024 medium; 371 at 3840×2160 low. Medium is 3,568 at 2048×2048 and about 5,932 at 2880×2880. The model page lists every quality and size.
Input: a 32,000-character prompt is about 7,100 text tokens; each 1024×1024 reference is about 1,024 image tokens.
Limits
checked before any charge
  • size in pixels: width and height multiples of 16, each edge at most 3840, the long edge at most 3× the short one, 655,360 to 8,294,400 pixels in total.
  • quality: low, medium, high or auto (no xhigh or max); omitted = medium.
  • output_format: png, jpeg or webp; output_compression 0–100 with jpeg or webp only. moderation: auto or low.
  • prompt: at most 32,000 characters. images: 1 to 16 HTTPS URLs on edits; mask: a PNG with alpha, the same size as the first image.
  • A request outside these limits is answered with HTTP 400 and is not charged.
Generation time
20–120 s
Usually 20 to 120 seconds; high quality and edits take longest. Send "async": true and poll GET /v1/tasks/{id} rather than holding the request open.
Not supported
background, gif, n > 1
Transparent backgrounds are not supported: there is no background field, and asking for one in the prompt gives an opaque image. Use GPT Image 2.5 Flare or Sunburst for transparency. output_format gif, n above 1 and input_fidelity are rejected before any charge. mask is supported on /v1/images/edits and is not billed as extra input.

Errors

application/json

Errors use the shape { "error": { "message", "type", "param", "code" } }; most messages end with a request id to quote when you contact support.

400
error
Invalid request. Fix the request instead of retrying it; it is not charged.
  • A field this page does not list, e.g. seed is not supported.
  • A value outside the listed options or range, e.g. size must be one of the documented ratios or table WxH pixels.
  • A missing or empty prompt (prompt is required).
  • A prompt over 32,000 characters (prompt is too long: at most 32000 characters).
  • n other than 1 (n must be 1).
  • A user longer than 256 characters (user must be a string of at most 256 characters).
  • images sent to /v1/images/generations (images requires the edits endpoint), or an image URL that is not HTTPS (images must contain HTTPS URLs).
  • More than 16 images (images must contain 1 to 16 HTTPS URLs).
  • mask sent to /v1/images/generations (mask requires the edits endpoint), or a mask that is not HTTPS (mask must be an HTTPS URL).
  • An edit without images (images is required for edits), or an edit sent as multipart form data (JSON body required).
  • A callback_url that is not a public HTTPS URL: code: "invalid_callback_url", callback_url must be an HTTPS public URL (no request id).
401
error
Missing or invalid API key (Invalid token).
403
error
Insufficient balance (code: "insufficient_user_quota"). Add credit in Console → Billing.
404
error
GET /v1/tasks/{id} for a task that does not exist or belongs to another account (Task not found).
503
error
The model exists but none of its routes can take the request right now: No available channel for model … (code: "model_not_found"). Retry later with backoff, or pick another model. A missing or misspelled model returns 404 with the same message; check the id instead of retrying.
524
error
A synchronous request (async omitted or false) got no response within 100 seconds and the edge closed it. The request was still accepted and charged, but no task id was returned, so the image cannot be retrieved. Use "async": true for anything that may take over a minute.