
Midjourney imagine generation with native --ar and --stylize parameters
Midjourney
أخرىصورة
تاريخ الإصدارأغسطس 2026
xAI
PublishedImageUse model grok-imagine with a single create call, then poll the result endpoint. All requests use the same API key and USD balance.
Runs end-to-end: submit a task, then poll until it completes.
#!/usr/bin/env bash
set -euo pipefail
I2V_API_KEY="${I2V_API_KEY:?Set your API key: export I2V_API_KEY=...}"
# 1. Submit task
RESPONSE=$(curl -s -X POST "https://i2v.ai/api/v1/jobs/createTask" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $I2V_API_KEY" \
-d '{
"model": "grok-imagine",
"inputs": {
"prompt": "A calm lake at sunrise",
"aspectRatio": "1:1"
}
}')
TASK_ID=$(echo "$RESPONSE" | grep -o '"taskId":"[^"]*"' | cut -d'"' -f4)
echo "Task created: $TASK_ID"
# 2. Poll until complete
while true; do
RESULT=$(curl -s "https://i2v.ai/api/v1/jobs/recordInfo?taskId=...?taskId=$TASK_ID" \
-H "Authorization: Bearer $I2V_API_KEY")
STATUS=$(echo "$RESULT" | grep -o '"status":"[^"]*"' | head -1 | cut -d'"' -f4)
case "$STATUS" in
success) echo "$RESULT"; break ;;
fail) echo "Failed: $RESULT"; exit 1 ;;
*) echo "Status: $STATUS — waiting..."; sleep 2 ;;
esac
donegrok-imagineGrok Imagine is xAI's image model for photorealistic stills. It renders square, portrait and landscape frames from text and can rework a single reference image, with a strong bias toward natural light and camera-like realism.
/api/v1/jobs/createTaskCreate a generation task and return its task ID.
/api/v1/jobs/recordInfo?taskId=...Read one task by taskId; poll it until the status is success or fail.
/api/v1/accountReturn the current USD balance of the API key owner.
4 fields
| Parameter | Required | Type | Allowed | Default | Description |
|---|---|---|---|---|---|
| prompt | Yes | string | ≤ 5000 chars | Not recorded | The scene or edit instruction. Describe subject, location, light and lens. |
| uploadedUrls | No | string[] | ≤ 1 | Not recorded | One reference image; extra entries are discarded. |
| imageUrls | No | string[] | ≤ 1 | Not recorded | One reference image; extra entries are discarded. |
| aspectRatio | No | enum | 1:1, 2:3, 3:2, 16:9, 9:16 | 1:1 | One of 1:1, 2:3, 3:2, 16:9 or 9:16. Ignored in image-to-image mode. |
{
"taskId": "..."
}{
"taskId": "...",
"model": "grok-imagine",
"status": "success",
"creditsUsed": 100,
"output": [
{
"url": "...",
"width": 1280,
"height": 720
}
],
"error": null,
"createTime": 1760000000000,
"completeTime": 1760000060000
}{
"code": "invalid_params",
"message": "Invalid request parameters"
}| Status values | Description |
|---|---|
| waiting | Task queued |
| generating | Processing in progress |
| success | Output ready |
| fail | Generation failed |
| Code | HTTP | Description |
|---|---|---|
| invalid_params | 400 | Request body, inputs or model ID is invalid. |
| unauthorized | 401 | API key is missing, invalid or expired. |
| insufficient_credits | 402 | Available USD balance is below the quoted amount. The response may include required and available. |
| access_denied | 403 | The task belongs to another account, or the account or entitlement is unavailable. |
| not_found | 404 | Task not found. |
| conflict | 409 | expectedRevision does not match, or the idempotency key was reused with a different payload. |
| concurrency_limit | 429 | The account reached its concurrent task limit. |
| rate_limit | 429 | The account reached its per-minute submission limit. |
| internal_error | 500 | Unexpected server error. |
| service_unavailable | 503 | Authentication or an upstream dependency is temporarily unavailable. |
Send your API key as a Bearer token in the Authorization header. Create and revoke keys in Settings → API keys.
Send Authorization: Bearer API_KEY and Content-Type: application/json. Reuse one Idempotency-Key for the same logical create; the same key with a different payload is rejected.
Authorization: Bearer $I2V_API_KEYContent-Type: application/jsonIdempotency-Key: <uuid>