Grok Imagine 2.0 Ext
Grok Imagine 2.0 Ext Image Generation
- Async text-to-image; poll with task_id
- 1–12 images per request; billed per successfully delivered image ($0.08 each)
- URL output only; no image-to-image / streaming
- Image URLs expire in 72 hours
POST
Text-to-image · async jobs. Submit
Model name is fixed
POST /v1/images/generations, then poll Get task status.Model name is fixed
grok-imagine-2.0-ext. Not supported: reference images, stream, or response_format values other than url.Capabilities and limits
Auth and recommended headers
string
required
Bearer token. Get a key from the API Key page.
Request parameters
string
required
Fixed value:
grok-imagine-2.0-extstring
required
Prompt. Must be non-empty after trim. Trim before submit.
integer
default:"1"
Image count:
1–12. Explicit 0 errors. Omit for 1.string
Aspect ratio. Prefer ratio strings (UI should only show ratios):
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).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.string
Quality-mode field. Verified value:
quality.- Omit (model is quality-mode by default), or
- Pass
resolution: "quality"explicitly
1K / 2K / 4K pixel tier; framing is controlled by size.string
default:"url"
Only
url is allowed. May be omitted. b64_json / base64 → 400 invalid_response_format.string
Optional public HTTPS base URL. On terminal status the platform POSTs
{webhook}/callback. Server-side only — see Webhook.Unsupported parameters
Build requests with a whitelist; do not forward a generic image-form object from other models.
Request examples
Minimal
Recommended
Submit response
PreferX-APIMart-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.idfor pollingrequest_idfor gateway debugging- the
Idempotency-Keyfor safe retries when outcome is unknown - original request params for UI / support
Idempotency and safe retries
Image generation is billable — strongly recommendIdempotency-Key (1–191 printable ASCII chars; UUID is easiest; retained ~24 hours).
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
language: zh / en / ko / ja (failure message localization only). See Get task status.
Statuses
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
Parsing url and image_ids
- Use
url[]for display; whenn>1, walk all entries - Pair by index only if
image_ids.length === url.length - Missing
image_idsstill allows display - Links last 72 hours — download promptly; also trust
expires_at
Billing
Base price $0.08 per image (successful deliveries):- Pre-submit UI should say “estimate”; final USD is
data.cost data.credits_costis the credits view (currently ~ USD × 10)- Pre-charge by requested count; settle on successful count (partial refunds if partial failure)
- Full failure:
cost=0, pre-charge refunded - Do not build price keys from
resolution; this model is flat per image
Webhook (optional)
- Provide a base URL; the platform calls
{base}/callback - Must be public and pass SSRF checks
- If
webhook_secretis set, signature ishex(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
Prefer
error.message for UI. Do not surface raw auth internals to end users.