Grok Imagine 2.0 Ext Image Generation
Async text-to-image and reference-image generation; poll with task_id
Toda la documentación/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:streamorresponse_formatvalues other thanurl.
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.
Ejemplos de solicitudes
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
| Dimension | Contract |
|---|---|
| Model | Fixed grok-imagine-2.0-ext |
| Capability | Text-to-image and reference-image generation |
| Mode | Async task |
Count n | Text-to-image: 1–12, default 1; with references: exactly 1 image |
image_urls | Up to 5 public HTTP(S) image URLs in an array, in selection order |
size | 7 aspect ratios + 5 pixel aliases (below) |
| Output | response_format=url only (also the default) |
| Quality | Text-to-image may use resolution: "quality"; omit resolution with references |
| Not supported | stream=true, public quality, style, b64_json / base64 |
Auth and recommended headers
AuthorizationstringrequiredBearer token. Get a key from the API Key page.
Authorization: Bearer YOUR_API_KEY| Header | Notes |
|---|---|
Content-Type | application/json (submit) |
Accept | application/json |
Idempotency-Key | Strongly recommended. New UUID per user-confirmed generation; network retries must reuse the same key and body |
X-APISea-Response-Version | Prefer 2026-07-27 for a stable submit shape (data.id) |
Request parameters
modelstringrequiredFixed value: grok-imagine-2.0-ext
nsfw_checkbooleandefault: falseWhether to run content moderation before submitting the image task.
true: useomni-moderation-latestto review prompts and input imagesfalseor omitted: do not send a moderation request, adding no moderation cost or latency (default)
promptstringrequiredPrompt. 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_urlsentirely to submit a text-to-image request. - With references, each request generates 1 image: omit
nor set it to1, and omitresolution.
nintegerdefault: 1For 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.
sizestringAspect ratio. Prefer ratio strings (UI should only show ratios):
size | Orientation | Typical use |
|---|---|---|
1:1 | Square | Product, avatar |
2:3 | Portrait | Poster, full-body |
3:2 | Landscape | Photo, wide scene |
3:4 | Portrait | E-commerce, people |
4:3 | Landscape | Display art |
9:16 | Vertical | Story / short-video cover |
16:9 | Wide | Banner, 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:1may return 1408×1408). Trust the returned image; do not rewritesizefrom measured pixels.
resolutionstringThe 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
qualityfield — you get400 invalid_quality. Useresolution.
response_formatstringdefault: urlOnly url is allowed. May be omitted. b64_json / base64 → 400 invalid_response_format.
webhookstringOptional public HTTPS base URL. On terminal status the platform POSTs {webhook}/callback. Server-side only — see Webhook.
Unsupported parameters
| Parameter | Behavior |
|---|---|
quality | 400 invalid_quality → Text-to-image may use resolution: "quality"; omit resolution with references |
style | 400 invalid_style |
image_with_roles | 400 invalid_image_input |
stream: true | 400 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)
{
"model": "grok-imagine-2.0-ext",
"prompt": "A red apple on a white ceramic plate, clean studio product photo"
}Text-to-image (full parameters)
{
"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
{
"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
{
"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.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 recommend Idempotency-Key (1–191 printable ASCII chars; UUID is easiest; retained ~24 hours).
| Scenario | Behavior | Action |
|---|---|---|
| Same key + same body already done | Replay; header Idempotency-Replayed: true | Use the same task id |
| Same key still in flight | 409 idempotency_in_progress + Retry-After | Wait, retry same key and body |
| Same key, different body | 409 idempotency_key_reused | New logical job needs a new key |
| Outcome indeterminate | 409 idempotency_result_indeterminate | Do 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
GET /v1/tasks/{task_id}?language=en
Authorization: Bearer YOUR_API_KEY
Accept: application/jsonOptional language: zh / en / ko / ja (failure message localization only). See Get task status.
Statuses
status | Terminal | Handling |
|---|---|---|
pending / processing | No | Keep polling (result may be absent — not a failure) |
completed | Yes | Parse result.images |
failed | Yes | Show error.message; cost is 0 (pre-charge refunded) |
unknown | No | Short 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
{
"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
result.images[]
├─ url[] ← authoritative display/download field (array)
├─ image_ids[] ← optional opaque IDs
└─ expires_at ← Unix seconds; multiply by 1000 for JS Date- 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
Webhook (optional)
{
"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_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
| HTTP | error.code | Cause | Action |
|---|---|---|---|
| 400 | invalid_request | Empty prompt / bad JSON | Validate input |
| 400 | invalid_n | n outside 1–12 | Text-to-image: 1–12, default 1; with references: exactly 1 image |
| 400 | invalid_size | Size not whitelisted | Fixed select options |
| 400 | invalid_response_format | Not url | Fix or omit |
| 400 | invalid_quality | Public quality sent | Text-to-image may use resolution: "quality"; omit resolution with references |
| 400 | invalid_style | style sent | Remove |
| 400 | invalid_image_input | image_with_roles | Remove image_with_roles; use image_urls |
| 400 | invalid_stream | stream=true | Remove |
| 400 | invalid_idempotency_key | Bad key | Use UUID |
| 401 | Auth failure | Bad key | Fix server credentials |
| 402 | Payment required | Low balance | Top up |
| 409 | idempotency_* | Idempotency conflict | See table above |
| 429 | Rate limit | Too fast | Honor Retry-After |
| 5xx | Server 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)
| Item | Grok Imagine 1.5 | 2.0 Ext |
|---|---|---|
| Model | grok-imagine-1.5-apisea, etc. | grok-imagine-2.0-ext |
| Image-to-image | Supported (see 1.5 docs) | Up to 5 public HTTP(S) image URLs in an array, in selection order |
| Count | See 1.5 docs | Text-to-image: 1–12, default 1; with references: exactly 1 image |
| Quality field | See 1.5 docs | Text-to-image may use resolution: "quality"; omit resolution with references |
| Output | See 1.5 docs | URL only |
| URL TTL | See 1.5 docs (often 24h) | 72 hours |
Respuestas
{
"code": 202,
"request_id": "2026081111342261665927mpb4IPDb",
"data": {
"id": "task_01KZQE5CM0Y3KZ6M1N1BK619MX",
"object": "generation.task",
"type": "image",
"status": "pending",
"progress": 0,
"poll_url": "/v1/tasks/task_01KZQE5CM0Y3KZ6M1N1BK619MX"
}
}Modelos que usan este endpoint
¿Has encontrado un problema en esta documentación? Escribe a support@apisea.ai.