APIMODELSAPIMODELS
Documentação da API

apimodels.app

Docs/GPT Image 2 API

GPT Image 2 API reference

OpenAI gpt-image-2. A single endpoint handles text-to-image and multi-image editing (up to 16 reference images, 30MB each); output composition is driven by aspect_ratio. Native 1K / 2K / 4K ($0.025 / $0.03 / $0.05). Async: POST creates the task, then poll with GET ?task_id= or supply a callback_url.

Model page: GPT Image 2 API — pricing, specs and the playground

Autenticação

Authorization: Bearer YOUR_API_KEY

Model & pricing

ModelmodelPriceNotas
GPT Image 2gpt-image-2$0.025 / $0.03 / $0.05Async · 1K / 2K / 4K tiers

Endpoints

POST/api/v1/images/generationscreate task
GET/api/v1/images/generations?task_id=...poll status

Code examples

# ─── 1. Text-to-image ──────────────────────────────────────
# resolution: "1K" | "2K" | "4K" (optional, default 1K). aspect_ratio: 1:1, 3:2, 2:3, 4:3, 3:4, 16:9, 9:16.
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A minimalist product shot of a white sneaker on a pastel gradient backdrop, soft studio lighting",
    "aspect_ratio": "1:1",
    "resolution": "2K"
  }'

# Response:
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx...", "state": "pending" } }


# ─── 2. Image editing with a reference URL ─────────────────
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Place this product on a marble kitchen counter with soft morning light",
    "image_url": "https://example.com/product.jpg",
    "aspect_ratio": "3:2"
  }'


# ─── 3. Multi-image fusion (up to 10 reference images) ─────
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Use the model from image 1 wearing the outfit from image 2, studio lighting",
    "image_urls": [
      "https://example.com/model.jpg",
      "https://example.com/outfit.jpg"
    ],
    "aspect_ratio": "2:3"
  }'


# ─── 4. Image editing via base64 ───────────────────────────
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Add a geometric fox logo in the center of the mug",
    "image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
    "image_mime_type": "image/png",
    "aspect_ratio": "1:1"
  }'


# ─── 5. Poll task status ───────────────────────────────────
curl "https://api.apimodels.app/v1/images/generations?task_id=TASK_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Success response:
# {
#   "code": 200,
#   "msg": "success",
#   "data": {
#     "taskId": "clxxx...",
#     "state": "completed",
#     "resultUrls": ["https://r2.apimodels.app/images/xxx.png"],
#     "images": [{"url": "https://r2.apimodels.app/images/xxx.png", "width": 2048, "height": 2048}],
#     "costTime": 14320,
#     "completeTime": 1705123465000
#   }
# }


# ─── 6. Webhook callback (optional) ────────────────────────
# Add "callback_url" to the create request and your endpoint
# will receive a POST with the same payload when the task
# completes — useful for production to avoid polling.
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Studio photo of a ceramic mug",
    "aspect_ratio": "1:1",
    "callback_url": "https://your-domain.com/webhook/image"
  }'

Parâmetros da requisição

FieldRequiredTypeDescription
modelYesstringDeve ser "gpt-image-2"
promptYesstringPrompt ou instruções de edição. Ao editar várias imagens, referencie-as como "image 1", "image 2". Comprimento de 1–20000 caracteres.
aspect_ratioNostringOutput aspect ratio. Enum: 1:1 / 2:3 / 3:2 / 4:5 / 5:4 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9. Omit or pass "auto" — see the note below. Note: 5:4 and 4:5 are supported at 1K only — not at 2K/4K (use 1K, or switch to 3:4 / 4:3). Note on auto: when editing, it follows the reference image; for text-to-image there is nothing to follow, so it falls back to a 1:1 square rather than letting the model choose. Pick an enum value when you need a shape. Two things measured on 2026-08-13: asking for a ratio in the prompt does nothing (prompt-only "5:2" with no size still returned 1024x1024), and an exact size outside the enum is snapped to the nearest grid step (1600x640 for 5:2 and 1552x656 for 21:9 both came back 1456x624). The widest shape currently reachable is 21:9 (2.33).
resolutionNostring"1K" (default) / "2K" / "4K". Tiered pricing: 1K $0.025, 2K $0.03, 4K $0.05.
image_urlNostringURL de uma única imagem de referência (acessível publicamente). Fornecê-la roteia para imagem para imagem. ≤ 10MB.
image_urlsNostring[]Multiple reference image URLs (up to 16, ≤ 10MB each) for multi-image fusion. Beyond 16, only the first 16 are used.
image_base64NostringImagem de referência codificada em Base64 ou data-URI (para arquivos locais). Mutuamente exclusiva com image_url.
image_mime_typeNostringTipo MIME de image_base64. Valor padrão image/jpeg. Suporta image/png, image/jpeg, image/webp.
output_formatNostringDelivery format: "png" / "jpeg" / "webp". Default when omitted: opaque images are delivered as JPEG q95, images with an alpha channel stay PNG. Pass "png" for the lossless original (no re-encode at all — the upstream PNG is delivered byte-for-byte), at roughly 6x the JPEG size: a 1760x2352 render measures 6.6MB as PNG versus 1.0MB as JPEG. "webp" is JPEG-sized and is the only option that both compresses and keeps an alpha channel. Use png when your pipeline requires lossless; otherwise leave it unset.
callback_urlNostringURL do webhook chamada quando a tarefa é concluída. O servidor fará um POST para essa URL com o mesmo JSON da resposta de polling.

Tamanhos de saída: 2K e 4K

As faixas 2K e 4K seguem os rótulos de tamanho que a própria OpenAI usa para o gpt-image-2. Estes são os tamanhos 2K e 4K listados no guia de geração de imagens dela:

NívelTamanhoRótulo da OpenAI
2K2048x20482K square
2K2048x11522K landscape
4K3840x21604K landscape
4K2160x38404K portrait
  • Os tamanhos 2K da OpenAI têm lado maior de 2048 pixels. Um pedido 16:9 pode voltar em 2048x1152, que é o 2K paisagem da OpenAI, ou em 2736x1536, maior e na mesma proporção; 9:16 também volta em 1152x2048 ou 1536x2736. Os dois são renderizações 2K, cobradas pelo preço 2K de $0.03.
  • O mesmo guia diz que resoluções acima de 2560x1440 são experimentais, então um tamanho maior como 2736x1536 não é garantido em todo pedido.
  • O 4K é limitado pelo teto da OpenAI de 8.294.400 pixels no total (3840x2160). 16:9 e 9:16 chegam a 3840 no lado maior; as outras proporções têm o lado maior mais curto, por exemplo 2880x2880 em 1:1.
  • Regras completas da OpenAI para o tamanho no gpt-image-2: os dois lados múltiplos de 16, lado maior ≤ 3840, razão entre lado maior e menor ≤ 3:1 e entre 655.360 e 8.294.400 pixels no total.
  • Toda tarefa concluída devolve a largura e a altura reais em data.images, então você pode conferir o tamanho no código.

Fonte: Guia de geração de imagens da OpenAI · GPT Image 2 settings

Campos da resposta

FieldRequiredTypeDescription
code—integer200 em caso de sucesso; caso contrário, consulte a tabela de códigos de erro.
msg—string"success" ou uma mensagem de erro.
data.taskId—stringID da tarefa usado para consultas de status.
data.state—stringpending / processing / completed / failed.
data.resultUrls—string[]Presente apenas quando state=completed; URLs de imagens hospedadas no R2. Excluídas automaticamente após 30 dias — baixe ou re-hospede no seu próprio armazenamento o quanto antes.
data.images—object[]Só vem quando state=completed (tarefas a partir de 2026-10-25): o tamanho real em pixels de cada imagem, na mesma ordem de resultUrls — [{ url, width, height }]. Se uma imagem não pôde ser medida, o item traz apenas url.
data.failMsg—stringPresente apenas quando state=failed; motivo da falha do provedor upstream.
data.costTime—integerDuração da tarefa em milissegundos.
data.completeTime—integerTimestamp de conclusão em ms.

Notas

  • Fluxo assíncrono: POST retorna taskId imediatamente com state=pending; faça polling com GET ?task_id= até state=completed. Latência típica de 10–30s, limitada a ~3min.
  • O endpoint roteia automaticamente: apenas prompt → texto para imagem; com image_url / image_urls / image_base64 → imagem para imagem.
  • Image inputs can be public URLs, data:<mime>;base64,... URIs, or bare base64 strings (auto-wrapped). Up to 16 per request, 10MB each; beyond 16, only the first 16 are used.
  • callback_url é a opção preferida em produção — o backend faz um POST do mesmo payload de data para o seu endpoint quando a tarefa termina, evitando o seu próprio loop de polling.
  • resultUrls são links do R2 excluídos automaticamente após 30 dias — baixe ou re-hospede no seu próprio armazenamento dentro desse prazo.
  • Tarefas com falha são gratuitas: requisições com state=failed não são cobradas, tentar novamente é seguro.
  • Tiered pricing by resolution: 1K $0.025, 2K $0.03, 4K $0.05 — independent of aspect ratio or prompt length. 5:4 / 4:5 are 1K-only (unsupported at 2K/4K).

Related: for the OpenAI-SDK-compatible sync channel see GPT Image 2 All; try it in the Playground

Perguntas frequentes

How much does the GPT Image 2 API cost?

Tiered by resolution: 1K $0.025, 2K $0.03, 4K $0.05 per image — independent of aspect ratio or prompt length. Charged only on success.

How do I edit an image with GPT Image 2?

POST /api/v1/images/generations with model gpt-image-2, a prompt, and image_url (single) or image_urls[] (up to 16). Poll GET ?task_id= until completed, or pass callback_url.

What is the difference between gpt-image-2, gpt-image-2-all and gpt-image-2-lite?

gpt-image-2 is the async task channel (1K/2K/4K tiers). gpt-image-2-all is the OpenAI-SDK-compatible sync channel with the full quality matrix and multi-image editing. gpt-image-2-lite is the most affordable channel: a flat $0.01 per image, single tier (~1.5MP at your aspect ratio), sync.