Skip to content
Ta strona nie jest jeszcze dostępna w Twoim języku, dlatego wyświetlamy ją po angielsku.

Grok Imagine 2.0 Ext Image Generation

Async text-to-image and reference-image generation; poll with task_id

Cała dokumentacja
POST/v1/images/generations
  • Text-to-image: 1–12 images; with references: 1 image per request
  • URL output only; streaming is not supported
  • Image URLs expire in 72 hours

Note

Text-to-image / reference-image generation · async jobs. Submit POST /v1/images/generations, then poll Get task status.

Model name is fixed grok-imagine-2.0-ext. Not supported: stream or response_format values other than url.

Note

For object layers or selected-region editing, see Layers and region editing.

Warning

Do not put API keys in browser bundles (VITE_* / NEXT_PUBLIC_*, LocalStorage, etc.). Prefer calling your own BFF from the browser; keep the APISea key on the server.

Przykłady żądań

curl --request POST \
  --url https://api.apisea.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --header 'Idempotency-Key: 8eacb46d-ef4e-4f4e-82de-830bd8bc67e2' \
  --header 'X-APISea-Response-Version: 2026-07-27' \
  --data '{
    "model": "grok-imagine-2.0-ext",
    "prompt": "A red apple on a white ceramic plate, clean studio product photo",
    "n": 1,
    "size": "1:1",
    "resolution": "quality",
    "response_format": "url"
  }'

Capabilities and limits

DimensionContract
ModelFixed grok-imagine-2.0-ext
CapabilityText-to-image and reference-image generation
ModeAsync task
Count nText-to-image: 1–12, default 1; with references: exactly 1 image
image_urlsUp to 5 public HTTP(S) image URLs in an array, in selection order
size7 aspect ratios + 5 pixel aliases (below)
Outputresponse_format=url only (also the default)
QualityText-to-image may use resolution: "quality"; omit resolution with references
Not supportedstream=true, public quality, style, b64_json / base64
Authorizationstringrequired

Bearer token. Get a key from the API Key page.

text
Authorization: Bearer YOUR_API_KEY
HeaderNotes
Content-Typeapplication/json (submit)
Acceptapplication/json
Idempotency-KeyStrongly recommended. New UUID per user-confirmed generation; network retries must reuse the same key and body
X-APISea-Response-VersionPrefer 2026-07-27 for a stable submit shape (data.id)

Request parameters

modelstringrequired

Fixed value: grok-imagine-2.0-ext

nsfw_checkbooleandefault: false

Whether to run content moderation before submitting the image task.

  • true: use omni-moderation-latest to review prompts and input images
  • false or omitted: do not send a moderation request, adding no moderation cost or latency (default)
promptstringrequired

Prompt. Must be non-empty after trim. Trim before submit.

image_urlsstring[]

Optional array of reference image URLs, up to 5 images. For local files, upload images first, then use the returned public HTTP(S) URLs.

  • Keep the URLs in the order selected by the user.
  • Pass an array even when there is only one reference image.
  • If no reference images are selected, omit image_urls entirely to submit a text-to-image request.
  • With references, each request generates 1 image: omit n or set it to 1, and omit resolution.
nintegerdefault: 1

For text-to-image, generate 1–12 images, default 1. Explicit 0 returns an error.

With reference images, each request generates exactly 1 image. Omit n or explicitly send n: 1.

sizestring

Aspect ratio. Prefer ratio strings (UI should only show ratios):

sizeOrientationTypical use
1:1SquareProduct, avatar
2:3PortraitPoster, full-body
3:2LandscapePhoto, wide scene
3:4PortraitE-commerce, people
4:3LandscapeDisplay art
9:16VerticalStory / short-video cover
16:9WideBanner, video cover

Pixel aliases: 1024x1024 (1:1), 1024x1792 (2:3), 1792x1024 (3:2), 720x1280 (9:16), 1280x720 (16:9).

Values outside the whitelist return 400 invalid_size (e.g. 1:2, 2:1, 4:5, auto).

Note

Actual pixels for a given ratio may differ from the alias table (e.g. 1:1 may return 1408×1408). Trust the returned image; do not rewrite size from measured pixels.

resolutionstring

The quality-mode settings below apply only to text-to-image. Omit resolution when sending reference images.

Quality-mode field. Verified value: quality.

  • Omit (model is quality-mode by default), or
  • Pass resolution: "quality" explicitly

Not a 1K / 2K / 4K pixel tier; framing is controlled by size.

Warning

Do not send a public quality field — you get 400 invalid_quality. Use resolution.

response_formatstringdefault: url

Only url is allowed. May be omitted. b64_json / base64 → 400 invalid_response_format.

webhookstring

Optional public HTTPS base URL. On terminal status the platform POSTs {webhook}/callback. Server-side only — see Webhook.

Unsupported parameters

ParameterBehavior
quality400 invalid_quality → Text-to-image may use resolution: "quality"; omit resolution with references
style400 invalid_style
image_with_roles400 invalid_image_input
stream: true400 invalid_stream
response_format: "b64_json" / "base64"400 invalid_response_format

Build requests with a whitelist; do not forward a generic image-form object from other models.

Request examples

Text-to-image (minimal)

json
{
  "model": "grok-imagine-2.0-ext",
  "prompt": "A red apple on a white ceramic plate, clean studio product photo"
}

Text-to-image (full parameters)

json
{
  "model": "grok-imagine-2.0-ext",
  "prompt": "A red apple on a white ceramic plate, clean studio product photo",
  "n": 1,
  "size": "1:1",
  "resolution": "quality",
  "response_format": "url"
}

Generation with one reference image

json
{
  "model": "grok-imagine-2.0-ext",
  "prompt": "Turn the subject in the reference image into an illustration, preserving its features",
  "image_urls": [
    "https://cdn.example.com/reference-1.jpg"
  ],
  "n": 1
}

Generation with multiple reference images

json
{
  "model": "grok-imagine-2.0-ext",
  "prompt": "Draw the subjects from the two reference images in the same illustration, in reference order",
  "image_urls": [
    "https://cdn.example.com/reference-1.jpg",
    "https://cdn.example.com/reference-2.jpg"
  ]
}

Both reference examples omit resolution. The single-reference example explicitly sets n: 1; the multiple-reference example omits n and also generates only 1 image.

Submit response

Prefer X-APISea-Response-Version: 2026-07-27. Success is HTTP 202; task id is data.id (do not rely on legacy data[0].task_id).

Persist:

  • data.id for polling
  • request_id for gateway debugging
  • the Idempotency-Key for safe retries when outcome is unknown
  • original request params for UI / support

Idempotency and safe retries

Image generation is billable — strongly recommend Idempotency-Key (1–191 printable ASCII chars; UUID is easiest; retained ~24 hours).

ScenarioBehaviorAction
Same key + same body already doneReplay; header Idempotency-Replayed: trueUse the same task id
Same key still in flight409 idempotency_in_progress + Retry-AfterWait, retry same key and body
Same key, different body409 idempotency_key_reusedNew logical job needs a new key
Outcome indeterminate409 idempotency_result_indeterminateDo not mint a new key; investigate with the old one

On POST network timeout when you cannot tell if the server accepted the job, do not immediately create a new key — retry with the same key / body / response version.

Poll tasks

http
GET /v1/tasks/{task_id}?language=en
Authorization: Bearer YOUR_API_KEY
Accept: application/json

Optional language: zh / en / ko / ja (failure message localization only). See Get task status.

Statuses

statusTerminalHandling
pending / processingNoKeep polling (result may be absent — not a failure)
completedYesParse result.images
failedYesShow error.message; cost is 0 (pre-charge refunded)
unknownNoShort retries; if it persists, contact support with the task id

Poll about every 2 seconds; cap near 10 minutes or 120 attempts. Honor Retry-After on 429. Tasks are kept ~3 days by default — keep the task id if the client times out.

Completed example

json
{
  "code": 200,
  "data": {
    "id": "task_01KZQE5CM0Y3KZ6M1N1BK619MX",
    "status": "completed",
    "progress": 100,
    "created": 1786419262,
    "completed": 1786419275,
    "actual_time": 13,
    "estimated_time": 100,
    "result": {
      "images": [
        {
          "expires_at": 1786505675,
          "url": [
            "https://example.com/image/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.jpg"
          ],
          "image_ids": [
            "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
          ]
        }
      ]
    }
  }
}

Parsing url and image_ids

text
result.images[]
  ├─ url[]          ← authoritative display/download field (array)
  ├─ image_ids[]    ← optional opaque IDs
  └─ expires_at     ← Unix seconds; multiply by 1000 for JS Date
  1. Use url[] for display; when n>1, walk all entries
  2. Pair by index only if image_ids.length === url.length
  3. Missing image_ids still allows display
  4. Links last 72 hours — download promptly; also trust expires_at

Webhook (optional)

json
{
  "webhook": "https://your-service.example.com/apisea"
}
  • Provide a base URL; the platform calls {base}/callback
  • Must be public and pass SSRF checks
  • If webhook_secret is set, signature is hex(HMAC-SHA256(secret, raw_body)) over raw bytes
  • Callback body matches task query data (no extra {code,data} wrapper)
  • Still keep low-frequency polling as a fallback

Common errors

HTTPerror.codeCauseAction
400invalid_requestEmpty prompt / bad JSONValidate input
400invalid_nn outside 1–12Text-to-image: 1–12, default 1; with references: exactly 1 image
400invalid_sizeSize not whitelistedFixed select options
400invalid_response_formatNot urlFix or omit
400invalid_qualityPublic quality sentText-to-image may use resolution: "quality"; omit resolution with references
400invalid_stylestyle sentRemove
400invalid_image_inputimage_with_rolesRemove image_with_roles; use image_urls
400invalid_streamstream=trueRemove
400invalid_idempotency_keyBad keyUse UUID
401Auth failureBad keyFix server credentials
402Payment requiredLow balanceTop up
409idempotency_*Idempotency conflictSee table above
429Rate limitToo fastHonor Retry-After
5xxServer error—Keep Idempotency-Key; do not blindly rotate

Prefer error.message for UI. Do not surface raw auth internals to end users.

Differences from 1.5 (summary)

ItemGrok Imagine 1.52.0 Ext
Modelgrok-imagine-1.5-apisea, etc.grok-imagine-2.0-ext
Image-to-imageSupported (see 1.5 docs)Up to 5 public HTTP(S) image URLs in an array, in selection order
CountSee 1.5 docsText-to-image: 1–12, default 1; with references: exactly 1 image
Quality fieldSee 1.5 docsText-to-image may use resolution: "quality"; omit resolution with references
OutputSee 1.5 docsURL only
URL TTLSee 1.5 docs (often 24h)72 hours

Odpowiedzi

{
  "code": 202,
  "request_id": "2026081111342261665927mpb4IPDb",
  "data": {
    "id": "task_01KZQE5CM0Y3KZ6M1N1BK619MX",
    "object": "generation.task",
    "type": "image",
    "status": "pending",
    "progress": 0,
    "poll_url": "/v1/tasks/task_01KZQE5CM0Y3KZ6M1N1BK619MX"
  }
}

Znalazłeś błąd w tej dokumentacji? Napisz na adres support@apisea.ai.