APIMODELSAPIMODELS
Documentación de la 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

Autenticación

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 de la solicitud

FieldRequiredTypeDescription
modelYesstringDebe ser "gpt-image-2"
promptYesstringPrompt o instrucciones de edición. Al editar varias imágenes, refiérete a ellas como "image 1", "image 2". Longitud 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 una sola imagen de referencia (accesible públicamente). Si la proporcionas, se enruta a imagen a imagen. ≤ 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_base64NostringImagen de referencia codificada en Base64 o data-URI (para archivos locales). Mutuamente excluyente con image_url.
image_mime_typeNostringTipo MIME de image_base64. Valor predeterminado image/jpeg. Admite 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 del webhook que se invoca cuando la tarea finaliza. El servidor enviará por POST a esta URL el mismo JSON que la respuesta del sondeo.

Tamaños de salida: 2K y 4K

Los niveles 2K y 4K siguen las etiquetas de tamaño que OpenAI usa para gpt-image-2. Estos son los tamaños 2K y 4K que aparecen en su guía de generación de imágenes:

NivelTamañoEtiqueta de OpenAI
2K2048x20482K square
2K2048x11522K landscape
4K3840x21604K landscape
4K2160x38404K portrait
  • Los tamaños 2K de OpenAI tienen un lado largo de 2048 píxeles. Una petición 16:9 puede devolver 2048x1152, que es el 2K horizontal de OpenAI, o un 2736x1536 más grande con la misma proporción; 9:16 devuelve igualmente 1152x2048 o 1536x2736. Ambos son renders 2K y se cobran al precio 2K de $0.03.
  • La misma guía indica que las resoluciones por encima de 2560x1440 son experimentales, así que un tamaño mayor como 2736x1536 no está garantizado en cada petición.
  • El 4K está limitado por el máximo de OpenAI de 8.294.400 píxeles en total (3840x2160). 16:9 y 9:16 llegan a 3840 en el lado largo; las demás proporciones tienen el lado largo más corto, por ejemplo 2880x2880 en 1:1.
  • Reglas completas de OpenAI para el tamaño en gpt-image-2: ambos lados múltiplos de 16, lado largo ≤ 3840, relación entre lado largo y corto ≤ 3:1 y entre 655.360 y 8.294.400 píxeles en total.
  • Cada tarea completada devuelve el ancho y el alto reales en data.images, así que puedes comprobar el tamaño en tu código.

Fuente: Guía de generación de imágenes de OpenAI · GPT Image 2 settings

Campos de la respuesta

FieldRequiredTypeDescription
code—integer200 si tiene éxito; de lo contrario, consulta la tabla de códigos de error.
msg—string"success" o un mensaje de error.
data.taskId—stringID de la tarea usado para las consultas de estado.
data.state—stringpending / processing / completed / failed.
data.resultUrls—string[]Presente solo cuando state=completed; URLs de imágenes alojadas en R2. Se eliminan automáticamente tras 30 días: descárgalas o realójalas en tu propio almacenamiento cuanto antes.
data.images—object[]Solo aparece con state=completed (tareas desde el 2026-10-25): el tamaño real en píxeles de cada imagen, en el mismo orden que resultUrls — [{ url, width, height }]. Si una imagen no se pudo medir, su entrada lleva solo url.
data.failMsg—stringPresente solo cuando state=failed; motivo del fallo del proveedor upstream.
data.costTime—integerDuración de la tarea en milisegundos.
data.completeTime—integerMarca de tiempo de finalización en ms.

Notas

  • Flujo asíncrono: POST devuelve taskId de inmediato con state=pending; sondea con GET ?task_id= hasta que state=completed. Latencia típica de 10–30s, con un máximo de ~3min.
  • El endpoint se enruta automáticamente: solo prompt → texto a imagen; con image_url / image_urls / image_base64 → imagen a imagen.
  • 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 es la opción preferida en producción: el backend envía por POST el mismo payload de data a tu endpoint cuando la tarea finaliza, evitando tu propio bucle de sondeo.
  • resultUrls son enlaces de R2 que se eliminan automáticamente tras 30 días: descárgalos o realójalos en tu propio almacenamiento dentro de ese plazo.
  • Las tareas fallidas son gratuitas: las solicitudes con state=failed no se facturan, reintentar es 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

Preguntas frecuentes

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.