Skip to main content

Documentation Index

Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Grok Image is an xAI image model for text-to-image generation and single-reference image-to-image workflows. Use this page when you are ready to call the API after trying the model in the APIXO playground.
CapabilityValue
Model IDgrok-image
Modestext-to-image, image-to-image
Prompt length1-5000 characters
Reference images1 URL for image-to-image
Aspect ratios1:1, 3:2, 2:3 for text-to-image
OutputImage URL in resultJson.resultUrls

Endpoint and authentication

Base URL:
https://api.apixo.ai/api/v1
MethodEndpointPurpose
POST/generateTask/grok-imageSubmit a generation task
GET/statusTask/grok-image?taskId={taskId}Poll task status and retrieve results
All requests require your APIXO API key:
Authorization: Bearer YOUR_API_KEY
Submit requests also require:
Content-Type: application/json

Copy-paste async quickstart

This minimal request submits a text-to-image task and returns a taskId.
curl -X POST "https://api.apixo.ai/api/v1/generateTask/grok-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "a cozy cyberpunk cafe with neon lights",
      "aspect_ratio": "3:2"
    }
  }'
Successful response:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
Save the taskId; you need it to poll for the final result.

Poll for result

curl -X GET "https://api.apixo.ai/api/v1/statusTask/grok-image?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
Processing response:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
Success response:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965635929,
    "costTime": 25000
  }
}
Failed response:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "SensitiveContent",
    "failMsg": "Content violates provider policy, please adjust the prompt",
    "createTime": 1767965610929,
    "completeTime": 1767965620132,
    "costTime": 9039
  }
}
Parse resultJson after state becomes success:
const payload = JSON.parse(data.resultJson);
const imageUrls = payload.resultUrls;

Request body

Text-to-image

{
  "request_type": "async",
  "input": {
    "mode": "text-to-image",
    "prompt": "a serene mountain landscape at dawn",
    "aspect_ratio": "2:3"
  }
}

Image-to-image

{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "prompt": "turn this photo into a cinematic portrait",
    "image_urls": [
      "https://example.com/ref.png"
    ]
  }
}

Parameters

request_type
string
default:"async"
Result delivery mode. Omit this field or use async for polling with statusTask, or use callback for webhook delivery.
callback_url
string
Required when request_type is callback. Provide a public HTTPS URL that can receive the final task payload. See Webhooks.
input
object
required
Grok Image input parameters.

Response format

Submit task response

POST /generateTask/grok-image returns a task ID when the task is accepted:
code
integer
API status code. 200 means the task was accepted.
message
string
Human-readable status message.
data.taskId
string
Unique task identifier used with the status endpoint.

Status response fields

taskId
string
Unique task identifier.
state
string
Current task state: pending, processing, success, or failed.
resultJson
string
JSON string containing the generated image URLs. Present when state is success.
failCode
string
Machine-readable failure code. Present when state is failed.
failMsg
string
Human-readable failure message. Present when state is failed.
createTime
integer
Task creation timestamp in Unix milliseconds.
completeTime
integer
Task completion timestamp in Unix milliseconds. Present after completion.
costTime
integer
Processing duration in milliseconds. Present after completion.

Webhook callback mode

Use callback mode when your backend should receive the final result automatically instead of polling.
curl -X POST "https://api.apixo.ai/api/v1/generateTask/grok-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "text-to-image",
      "prompt": "a clean product photo of wireless earbuds on soft stone",
      "aspect_ratio": "1:1"
    }
  }'
Callback delivery uses the same final payload shape as the status response. See Webhooks for delivery requirements and retry behavior.

Billing

Grok Image is billed per generated image. Both supported modes use the same APIXO public price.
ModeAPIXO price
text-to-image$0.10 / image
image-to-image$0.10 / image
For current route and market comparison pricing, see Pricing.

Latency and polling

Actual latency may vary by prompt complexity, reference image access, provider queue load, and result storage time.
ModeTypical generation timeRecommended first pollPoll interval
text-to-imageAbout 25s on average15s after task creation3s
image-to-imageAbout 25s on average15s after task creation3s
For high-concurrency production workloads, use callback mode to avoid frequent polling.
Result URLs are valid for 15 days. Download and store important outputs promptly. Prompts can be written in English or Chinese. More specific scene, style, lighting, and composition details usually produce better results. Output is PNG by default; if you need transparency, describe that requirement in the prompt. Rate limits and concurrency can vary by account, API key, and route. If you receive 429, slow down requests and retry with backoff. For account-level details, see System APIs.

Errors and troubleshooting

HTTP errors

CodeMeaningWhat to do
400Invalid request body, missing mode, missing prompt, invalid aspect_ratio, malformed image_urls, or inaccessible image URLFix the request before retrying
401Missing or invalid API keyCheck the Authorization header
402Insufficient balance or quotaAdd balance or switch account/key
429Rate limit or concurrency limit reachedRetry with exponential backoff
500Internal error or unknown task failureRetry with backoff or contact support if it persists
502Upstream provider or network errorRetry with backoff

Validation notes

ParameterBackend behavior
input.modeRequired for routing. Must be text-to-image or image-to-image.
input.promptRequired string. Must not be empty and must not exceed 5000 characters.
input.aspect_ratioOptional for text-to-image. Must be 1:1, 3:2, or 2:3 if provided. Defaults to 1:1 for text-to-image.
input.image_urlsRequired and non-empty for image-to-image. Must be an array of strings and cannot contain more than 1 image.

Task failure codes

failCode is generated from APIXO’s mapped provider error. Common values include:
Fail codeMeaningWhat to do
PromptInvalidPrompt was invalid or rejected by the providerRewrite the prompt and retry
SensitiveContentPrompt or input/output content was rejected by safety checksChange the prompt or reference image
ImageFormatIncorrectReference image format could not be processedUse a public, direct image URL in a common image format
RateLimitedProvider rate limit was reachedRetry with exponential backoff
TimeoutProvider timeoutRetry later or use callback mode
Unknown errorProvider returned an unmapped failureRetry with backoff or contact support with the taskId
See Error Codes for the full error reference.