Skip to main content

OpenAI's GPT Image 2 text-to-image, which can write legible text into the picture. GPT Image 2 has low, medium and high quality, with medium selected initially; output-token costs rise roughly four to ninefold per step at a fixed size.

From $0.0018/image20% below the publisher's list price

Workbench

Send a request

Quickstart

Examples use the selected endpoint’s public parameter definitions. Replace the API key and example media, then send the request from your server.

SDKs & integrations
POSThttps://api.spicyapi.ai/api/v1/jobs/createTask

API authentication

Keep the API key in the server environment variable SPICY_API_KEY. Use Bearer authentication and Content-Type: application/json for JSON requests.

Authorization: Bearer $SPICY_API_KEY
GPT Image 2 · Text to Image · Sample output
Sample outputUse this example
# Generate the idempotency key once; reuse it when retrying after a lost response.
export SPICY_IDEMPOTENCY_KEY="${SPICY_IDEMPOTENCY_KEY:-$(uuidgen)}"
curl -X POST https://api.spicyapi.ai/api/v1/jobs/createTask \
  -H "Authorization: Bearer $SPICY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $SPICY_IDEMPOTENCY_KEY" \
  -d '{
  "model": "openai/gpt-image-2/text-to-image",
  "input": {
    "prompt": "A ceramic teapot on a linen cloth, soft window light, muted palette",
    "quality": "medium",
    "resolution": "1k",
    "num_outputs": 1,
    "aspect_ratio": "1:1",
    "output_format": "png"
  }
}'

# Copy data.taskId from the response into TASK_ID, then poll the status.
TASK_ID="TASK_ID_FROM_RESPONSE"
curl "https://api.spicyapi.ai/api/v1/jobs/recordInfo?taskId=$TASK_ID" \
  -H "Authorization: Bearer $SPICY_API_KEY"

Generated from this model’s input schema — the same one the API validates every request against.

Input parameters

Place these fields inside the request body’s input object. Names and types match the API. Do not assume a default when none is specified.

promptstringRequired

Up to 5,000 characters. Put every word that must appear in the image in double quotes and say where it goes; the rest is read as description. The first 100 input tokens of the prompt are included in the image price; longer prompts add a small charge per extra token, shown in the quote. Chinese, Japanese and Korean text counts about one token per character, other text about one token per four characters.

Default
Not specified
Constraints
minLength:1
maxLength:5000
official_fallbackbooleanOptional

GPT Image 2 is billed per output by quality, resolution and shape; standard-priced edits add a fixed source-image charge to each output, and wide or tall shapes cost less than squares at the same tier. The lower-priced GPT Image 2 offer covers one medium 1k PNG, in any ratio except 21:9, 9:21, 3:1 and 1:3. With Official fallback enabled by default, a lower-priced request that is refused or cannot finish is retried at the standard price; the GPT Image 2 quote shows the starting amount and maximum, other settings use standard pricing immediately, and disabling fallback rejects settings outside the offer without guaranteeing success for eligible ones. A refused GPT Image 2 request is not charged; under standard pricing only, prompt tokens after the first 100 add a fee once per request, estimated at one token per Chinese, Japanese or Korean character and about one per four other characters.

Default
true
output_qualityintegerOptional

Set JPEG/WebP compression quality between 0 and 100 for GPT Image 2 exports; higher values keep more detail in larger files, while PNG and the image price are unaffected.

Default
Not specified
Constraints
minimum:0
maximum:100
output_formatstringOptional

GPT Image 2 can deliver png, jpeg or webp at the same rendering price, with png selected initially.

Default
"png"
Allowed values
"png""jpeg""webp"
num_outputsintegerOptionalAffects price

Set the GPT Image 2 batch size to 1–10, initially 1; each poster or cover returned counts as a billable image.

Default
1
Constraints
minimum:1
maximum:10
qualitystringOptionalAffects price

GPT Image 2 has low, medium and high quality, with medium selected initially; output-token costs rise roughly four to ninefold per step at a fixed size.

Default
"medium"
Allowed values
"low""medium""high"
resolutionstringOptionalAffects price

GPT Image 2 defaults to 1k and also offers 2k or 4k; squares are 1024, 2048 or 2880 pixels wide, with higher tiers priced higher and some lower-priced 1k results slightly larger.

Default
"1k"
Allowed values
"1k""2k""4k"
aspect_ratiostringOptionalAffects price

GPT Image 2 generation has 15 ratios from 1:3 to 3:1, initially 1:1; edits also offer auto, which follows the first image at about 1.5 megapixels and ignores resolution, while fixed shapes have their own prices.

Default
"1:1"
Allowed values
"1:1""1:2""1:3""2:1""2:3""3:1""3:2""3:4""4:3""4:5""5:4""9:16""9:21""16:9""21:9"

Track the task

HTTP 202 means the task was accepted, not completed. Save the returned taskId and query that task. Do not create another task while waiting for its result.

Accepted response
HTTP/1.1 202 Accepted
Location: /api/v1/jobs/recordInfo?taskId=job_01k3m8x9q2z4v7n5p6r8s0t1w3

{
  "code": 200,
  "msg": "success",
  "request_id": "req_example_create",
  "data": {
    "taskId": "job_01k3m8x9q2z4v7n5p6r8s0t1w3",
    "state": "queued",
    "estimatedCost": "0.750000"
  }
}

The accepted response includes the estimate so your app can show the same amount in task history and billing.

Read the job
curl --get "https://api.spicyapi.ai/api/v1/jobs/recordInfo" \
  --data-urlencode "taskId=$TASK_ID" \
  -H "Authorization: Bearer $SPICY_API_KEY"

Start polling at about 2 seconds and gradually increase the interval. Stop at a terminal state. After a connection failure, query the original taskId. Retry creation only with the original idempotency key and body.

Or let the callback find you
import { verifyWebhook } from "@spicyapi/sdk";

// express.raw keeps the bytes we signed; express.json never matches.
app.post("/hooks/spicy", express.raw({ type: "application/json" }), (req, res) => {
  const { payload } = verifyWebhook({
    rawBody: req.body,
    timestamp: req.header("X-Webhook-Timestamp"),
    signature: req.header("X-Webhook-Signature"),
    payloadVersion: Number(req.header("X-Webhook-Payload-Version")),
    secret: process.env.SPICY_WEBHOOK_SECRET,
  });
  res.status(200).end();
  void handleFinishedTask(payload);
});

Pass callBackUrl when you create the task and the finished record is POSTed to you — no polling loop at all. Every delivery carries X-Webhook-Timestamp, X-Webhook-Signature and X-Webhook-Payload-Version. The signature is a base64 HMAC-SHA256 over taskId.timestamp.sha256(body), so it must be checked against the raw bytes: parsing the JSON and re-serialising it changes them and the check will fail. Failed deliveries are retried, so the same taskId can arrive twice — make the handler idempotent. Answer 2xx first and do the work afterwards; a slow handler is treated as a failed delivery.

Read the result

Consume output only when state is succeeded. On failure, use errorCode, errorMessage and request_id to investigate. Example costs and states do not represent an actual bill.

Completed response example
{
  "code": 200,
  "msg": "success",
  "request_id": "req_example_record",
  "data": {
    "taskId": "job_01k3m8x9q2z4v7n5p6r8s0t1w3",
    "model": "openai/gpt-image-2/text-to-image",
    "state": "succeeded",
    "output": {
      "assets": [
        {
          "key": "tasks/2026/08/28/job_01k3m8x9q2z4v7n5p6r8s0t1w3/3f7a1c9e5b2d48f0a6c1e3d5b7f9a1c3.png",
          "mime": "image/png",
          "url": "https://example.r2.cloudflarestorage.com/results/job_01k3m8x9q2z4v7n5p6r8s0t1w3/result.png?X-Amz-Signature=SIGNATURE_FROM_RESPONSE",
          "expiresAt": "2026-08-28T12:20:08.000Z"
        }
      ]
    },
    "cost": "0.750000",
    "settled": true,
    "createdAt": "2026-08-28T12:00:00Z",
    "completedAt": "2026-08-28T12:00:30Z"
  }
}

For each available asset, open or download assets[].url directly without an API Authorization header. The signed URL expires at expiresAt; poll the task again to refresh it while the asset remains within its retention period. A pending or unavailable asset has no URL. Treat signed URLs as private.

SDKs & integrations

Use SpicyAPI in your app, terminal, AI assistant or visual workflow. Choose a setup guide below.

Use it in ComfyUI

Install the SpicyAPI nodes from ComfyUI Manager or with the command below, then search for GPT Image 2 · Text to Image on the canvas. The node has the same options as this page and shows its price before it runs.

cd ComfyUI/custom_nodes
git clone https://github.com/spicyapi-ai/comfyui-spicyapi