xAI: Grok Imagine Image 2.0 (Text to Image) API Reference

About

Generate images from text using xAi's Grok Imagine 2.0 model.

1. Calling the API

Setup your API Key

To begin using Infron, you first need to create an account and generate your API Key.

Once you have your API key, set it as an environment variable in your runtime environment. This allows your applications to securely access Infron’s API.

export INFRON_KEY="YOUR_API_KEY"

Submit a request

For long-running requests, you can poll for results.

curl https://media.onerouter.pro/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<'EOF'
{
  "model": "x-ai/grok-imagine-image-2.0/text-to-image",
  "prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific.",
  "n": 1,
  "aspect_ratio": "16:9",
  "resolution": "1k",
  "quality": "medium"
}
EOF

Response with queue task id

The response will look like this:

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "20260818081956572207570FA7ck3JB",
    "object": "image",
    "model": "x-ai/grok-imagine-image-2.0/text-to-image",
    "status": "created",
    "urls": {
      "query": "https://media.onerouter.pro/v1/images/tasks/20260818081956572207570FA7ck3JB"
    },
    "created_at": "2026-08-18 08:19:56.62"
  }
}

Fetch request status

You can fetch the status of a request to check if it is completed or still in progress.

curl https://media.onerouter.pro/v1/images/tasks/{task_id} \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" 

# For example
curl https://media.onerouter.pro/v1/images/tasks/20260818081956572207570FA7ck3JB \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Response with queue task status query

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "20260818081956572207570FA7ck3JB",
    "object": "image",
    "model": "x-ai/grok-imagine-image-2.0/text-to-image",
    "status": "in_progress",
    "fail_reason": "",
    "submit_time": 1787041197,
    "start_time": 1787041196,
    "finish_time": 0,
    "outputs": [],
    "created_at": "2026-08-18 08:19:57"
  }
}

Possible statuses:

  • created
  • in_progress
  • processing
  • completed
  • failed

created -> in_progress → processing → completed | failed

Poll every 1-2 seconds until status is "completed" or "failed"

Get the result (when status is "completed")

Once the request is completed, you can fetch the result. See the Output Schema for the expected result format.

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "20260818081956572207570FA7ck3JB",
    "object": "image",
    "model": "x-ai/grok-imagine-image-2.0/text-to-image",
    "status": "completed",
    "fail_reason": "",
    "submit_time": 1787041197,
    "start_time": 1787041196,
    "finish_time": 1787041265,
    "outputs": [
      "https://infron.ai/cdn/media/image/generated/official_xai_image_8f73b96242b3499b9a689d14de97caf0.png"
    ],
    "usage": {
      "completion_tokens": 0,
      "image_count": 1,
      "image_quality": "medium",
      "prompt_tokens": 1,
      "quality": "medium",
      "resolution": "1k",
      "total_tokens": 1,
      "web_search": false
    },
    "cost": {
      "total_cost": 0.06,
      "cost_details": {
        "prompt_cost": 0,
        "completion_cost": 0,
        "image_cost": 0.06,
        "video_cost": 0,
        "audio_cost": 0,
        "native_web_search_cost": 0,
        "plugin_web_search_cost": 0,
        "tools_cost": 0,
        "prompt_cache_read_cost": 0,
        "prompt_cache_write_cost": 0,
        "prompt_cache_write_5_min": 0,
        "prompt_cache_write_1_h": 0,
        "reasoning_cost": 0,
        "discount_rate": 1,
        "is_byok": false,
        "byok_cost": 0
      }
    },
    "created_at": "2026-08-18 08:19:57"
  }
}

2. Schema

Input

ParameterTypeRequiredDefaultRangeDescription
modelstringYes--Explore all modelsModel name.
promptstringYes----Text prompt for generation; Positive text prompt.
nintegerNo1[1,10]Number of images to generate.
aspect_ratiostringNoautoauto, 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20Aspect ratio of the generated image.
resolutionstringNo1k1k, 2kResolution of the generated image.
qualitystringNomediumlow, mediumQuality of the generated image.

Example request

curl https://media.onerouter.pro/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<'EOF'
{
  "model": "x-ai/grok-imagine-image-2.0/text-to-image",
  "prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific.",
  "n": 1,
  "aspect_ratio": "16:9",
  "resolution": "1k",
  "quality": "medium"
}
EOF

Output

ParameterTypeRangeDescription
codeinteger--Status code of the request.
messagestring--Status message of the request.
dataobject--Data of the task.
data.task_idstring--ID of the task.
data.objectstring--Object type of the task.
data.modelstring--Model name of the task.
data.statusstringcreated, in_progress, processing, completed, failedStatus of the task.
data.fail_reasonstring--Fail reason of the task.
data.submit_timeinteger--Timestamp of the task submission.
data.start_timeinteger--Timestamp of the task start.
data.finish_timeinteger--Timestamp of the task finish.
data.outputsarray--Outputs of the task.
data.created_atstring--Timestamp of the task creation.

Example output

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "20260818081956572207570FA7ck3JB",
    "object": "image",
    "model": "x-ai/grok-imagine-image-2.0/text-to-image",
    "status": "completed",
    "fail_reason": "",
    "submit_time": 1787041197,
    "start_time": 1787041196,
    "finish_time": 1787041265,
    "outputs": [
      "https://infron.ai/cdn/media/image/generated/official_xai_image_8f73b96242b3499b9a689d14de97caf0.png"
    ],
    "usage": {
      "completion_tokens": 0,
      "image_count": 1,
      "image_quality": "medium",
      "prompt_tokens": 1,
      "quality": "medium",
      "resolution": "1k",
      "total_tokens": 1,
      "web_search": false
    },
    "cost": {
      "total_cost": 0.06,
      "cost_details": {
        "prompt_cost": 0,
        "completion_cost": 0,
        "image_cost": 0.06,
        "video_cost": 0,
        "audio_cost": 0,
        "native_web_search_cost": 0,
        "plugin_web_search_cost": 0,
        "tools_cost": 0,
        "prompt_cache_read_cost": 0,
        "prompt_cache_write_cost": 0,
        "prompt_cache_write_5_min": 0,
        "prompt_cache_write_1_h": 0,
        "reasoning_cost": 0,
        "discount_rate": 1,
        "is_byok": false,
        "byok_cost": 0
      }
    },
    "created_at": "2026-08-18 08:19:57"
  }
}

3. Detailed Pricing

QualityResolutionNo Reference Image1 Reference Image2 Reference Images3 Reference Images
low1K$0.04$0.05$0.06$0.07
low2K$0.06$0.07$0.08$0.09
medium1K$0.06$0.07$0.08$0.09
medium2K$0.08$0.09$0.10$0.11