Pegue sua chave de API

da OpenAI

Texto legível na imagem e edições precisas com máscara

openai/gpt-image-2/text-to-imageA partir de 1 créditopor imagem · US$ 0,01
  • Até 4K
  • Até 10 imagens de referência
  • 15 proporções
  • Até 10 por geração
  • Criar imagem
  • Editar imagem
3 2 1 PopVer exemplos

Chame com o nome de modelo openai/gpt-image-2/text-to-image em POST /jobs/createTask, a partir de 1 crédito por imagem (US$ 0,01). Contas novas ganham 30 créditos grátis para você testar primeiro no Playground.

Nome do modeloopenai/gpt-image-2/text-to-image
EndpointPOST https://api.popnow.ai/api/v1/jobs/createTask
# 1. Create the task. Keep the Idempotency-Key if you retry after a network error.
export IDEMPOTENCY_KEY="$(uuidgen)"
curl -X POST https://api.popnow.ai/api/v1/jobs/createTask \
  -H "Authorization: Bearer $POPNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $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",
    "aspect_ratio": "1:1",
    "resolution": "1k",
    "quality": "medium",
    "num_outputs": 1,
    "output_format": "png"
  }
}'

# 2. Copy data.taskId from the response, then poll until state is succeeded, failed, canceled or expired.
TASK_ID="TASK_ID_FROM_RESPONSE"
curl "https://api.popnow.ai/api/v1/jobs/recordInfo?taskId=$TASK_ID" \
  -H "Authorization: Bearer $POPNOW_API_KEY"

O input é montado a partir do schema abaixo, então passa na validação como está. Troque o prompt e os links pelos seus.

Preço

OpçãoCréditos por imagem≈ USD
aspect_ratio 1:3quality lowresolution 1K0,27US$ 0,0027
aspect_ratio 3:1quality lowresolution 1K0,27US$ 0,0027
aspect_ratio 21:9quality lowresolution 1K0,37US$ 0,0037
aspect_ratio 9:21quality lowresolution 1K0,37US$ 0,0037
aspect_ratio 1:2quality lowresolution 1K0,41US$ 0,0041
aspect_ratio 2:1quality lowresolution 1K0,41US$ 0,0041
aspect_ratio 1:3quality lowresolution 2K0,43US$ 0,0043
aspect_ratio 3:1quality lowresolution 2K0,43US$ 0,0043
aspect_ratio 16:9quality lowresolution 1K0,46US$ 0,0046
aspect_ratio 9:16quality lowresolution 1K0,46US$ 0,0046
aspect_ratio 2:3quality lowresolution 1K0,54US$ 0,0054
aspect_ratio 3:2quality lowresolution 1K0,54US$ 0,0054

1 crédito = US$ 0,01 · Todas as opções e preços: GET /models/openai/gpt-image-2/text-to-image

Cada tarefa é arredondada para cima em créditos inteiros, então uma execução no nível mais baixo custa 1 crédito por imagem (US$ 0,01).

Limites

Resoluções
1K · 2K · 4K
Proporções
1:1 · 1:2 · 1:3 · 2:1 · 2:3 · 3:1 +9
Resultados por chamada
1–10
Tamanho do prompt (caracteres)
5,000

Parâmetros

Estes campos vêm do mesmo schema que usamos para validar cada requisição. Campos que não estão na lista são rejeitados.

  • promptstringObrigatório

    Describe the image you want.

    Faixa
    1 – 5000 chars
  • aspect_ratiostringOpcionalMuda o preço

    O formato do quadro: horizontal, quadrado ou vertical.

    Padrão
    "1:1"
    Valores aceitos
    "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"
  • resolutionstringOpcionalMuda o preço

    Tamanho de saída. Maior fica mais nítido e custa mais.

    Padrão
    "1k"
    Valores aceitos
    "1k""2k""4k"
  • qualitystringOpcionalMuda o preço

    Mais tempo e preço em troca de detalhes mais finos.

    Padrão
    "medium"
    Valores aceitos
    "low""medium""high"
  • num_outputsintegerOpcionalMuda o preço

    Quantos resultados gerar de uma vez.

    Padrão
    1
    Faixa
    1 – 10
  • output_formatstringOpcional

    Tipo de arquivo do resultado.

    Padrão
    "png"
    Valores aceitos
    "png""jpeg""webp"
  • output_qualityintegerOpcional

    Compression quality for JPEG and WebP, from 0 to 100.

    Faixa
    0 – 100
JSON Schema bruto
{
  "type": "object",
  "required": [
    "prompt"
  ],
  "properties": {
    "prompt": {
      "type": "string",
      "maxLength": 5000,
      "minLength": 1,
      "description": "Describe the image you want."
    },
    "quality": {
      "enum": [
        "low",
        "medium",
        "high"
      ],
      "type": "string",
      "default": "medium",
      "description": "Rendering quality. Higher tiers add detail, time and cost."
    },
    "resolution": {
      "enum": [
        "1k",
        "2k",
        "4k"
      ],
      "type": "string",
      "default": "1k",
      "description": "Output size tier."
    },
    "num_outputs": {
      "type": "integer",
      "default": 1,
      "maximum": 10,
      "minimum": 1,
      "description": "How many images to return, each billed separately."
    },
    "aspect_ratio": {
      "enum": [
        "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"
      ],
      "type": "string",
      "default": "1:1",
      "description": "Output aspect ratio."
    },
    "output_format": {
      "enum": [
        "png",
        "jpeg",
        "webp"
      ],
      "type": "string",
      "default": "png",
      "description": "File format of the returned images."
    },
    "output_quality": {
      "type": "integer",
      "maximum": 100,
      "minimum": 0,
      "description": "Compression quality for JPEG and WebP, from 0 to 100."
    }
  },
  "additionalProperties": false
}

Um resultado real do GPT Image 2

3 2 1 Pop
PromptSwiss-style typographic poster: enormous bold numerals "3 2 1" stacked in cobalt, tangerine and lilac, with the word "POP!" bursting out of a glossy pink bubblegum bubble at the bottom; small clean grotesk text "A FESTIVAL OF SMALL EXPLOSIONS" and "FRI 21:00"; cream paper background, subtle paper texture, perfect grid, crisp legible text, no logos.
A mesma requisição pela API
{
  "model": "openai/gpt-image-2/text-to-image",
  "input": {
    "prompt": "Swiss-style typographic poster: enormous bold numerals \"3 2 1\" stacked in cobalt, tangerine and lilac, with the word \"POP!\" bursting out of a glossy pink bubblegum bubble at the bottom; small clean grotesk text \"A FESTIVAL OF SMALL EXPLOSIONS\" and \"FRI 21:00\"; cream paper background, subtle paper texture, perfect grid, crisp legible text, no logos.",
    "aspect_ratio": "1:1",
    "resolution": "1k",
    "quality": "medium",
    "num_outputs": 1,
    "output_format": "png"
  }
}

Respostas, consultas e callbacks

Todos os modelos funcionam do mesmo jeito: crie uma tarefa e depois consulte ou espere o callback.

Veja o preço antes

cURL
curl -X POST https://api.popnow.ai/api/v1/jobs/quote \
  -H "Authorization: Bearer $POPNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-image-2/text-to-image",
  "input": {
    "prompt": "A ceramic teapot on a linen cloth, soft window light, muted palette",
    "aspect_ratio": "1:1",
    "resolution": "1k",
    "quality": "medium",
    "num_outputs": 1,
    "output_format": "png"
  }
}'

Mesmo corpo do createTask. Retorna a cobrança esperada e a máxima possível, sem rodar nada.

Aceita

HTTP
HTTP/1.1 202 Accepted

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_01k3m8x9q2z4v7n5p6r8s0t1w3",
    "state": "queued"
  },
  "request_id": "req_example_create"
}

HTTP 202 quer dizer que a tarefa foi aceita e os créditos estão reservados, ainda não cobrados. A cobrança final nunca passa da reserva.

Consultar status

cURL
curl "https://api.popnow.ai/api/v1/jobs/recordInfo?taskId=$TASK_ID" \
  -H "Authorization: Bearer $POPNOW_API_KEY"

Consulte a cada poucos segundos, espaçando cada vez mais, e pare quando state for succeeded, failed, canceled ou expired.

Tarefa pronta

JSON
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_01k3m8x9q2z4v7n5p6r8s0t1w3",
    "model": "openai/gpt-image-2/text-to-image",
    "state": "succeeded",
    "output": {
      "assets": [
        {
          "url": "https://cdn.popnow.ai/tasks/task_01k3m8x9q2z4v7n5p6r8s0t1w3/output.png?signature=FROM_RESPONSE",
          "expiresAt": "2026-10-17T12:20:00Z",
          "mime": "image/png",
          "width": 1024,
          "height": 1024
        }
      ]
    },
    "settled": true
  },
  "request_id": "req_example_record"
}

Baixe pela url antes de expiresAt. Precisa de um link novo depois? Peça com POST /common/download-url.

Verificar um callback

Node.js
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
import express from "express";

const app = express();
// express.raw keeps the exact bytes that were signed; express.json would not match.
app.post("/hooks/popnow", express.raw({ type: "application/json" }), (req, res) => {
  const timestamp = req.header("X-Webhook-Timestamp");
  const signature = req.header("X-Webhook-Signature") ?? "";
  const body = JSON.parse(req.body.toString("utf8"));
  const taskId = body.data?.taskId ?? body.task_id;
  const digest = createHash("sha256").update(req.body).digest("hex");
  const expected = createHmac("sha256", process.env.POPNOW_WEBHOOK_SECRET)
    .update(`${taskId}.${timestamp}.${digest}`)
    .digest("base64");
  const ok = expected.length === signature.length && timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
  // Check the signature first, then reject anything older than five minutes.
  if (!ok || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return res.status(401).end();
  res.status(200).end(); // answer fast, then fetch the task and store its files
});

Com callBackUrl definida, enviamos a tarefa pronta para você. Confira a assinatura no corpo bruto antes de confiar nela.

Enviar um arquivo local

cURL
curl -X POST https://api.popnow.ai/api/v1/common/upload-url \
  -H "Authorization: Bearer $POPNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contentType": "image/png", "bytes": 482113}'

# PUT the file bytes to data.uploadUrl with every header in data.headers, then commit it:
curl -X POST https://api.popnow.ai/api/v1/files/$FILE_ID/commit \
  -H "Authorization: Bearer $POPNOW_API_KEY"
# The commit returns a popnow://f/... reference. Put it in any image, video or
# audio field of the task input instead of a public https URL.

Links https públicos funcionam como estão. Arquivos locais passam antes por upload-url e commit.