Developer Resources

Grok 5 Imagine API Documentation

Integrate xAI's Grok 5 Imagine model into your applications. Support for text-to-image, text-to-video, and image-to-video generation with simple REST API.

1

Authentication

The Grok 5 Imagine API uses Bearer Token authentication. Pass your API Key in the request header.

Authentication
Authorization: Bearer sk-your-api-key-here

Keep your API key secure. Do not share it in client-side code.

Pricing

TypeCostDescription
Text to Image (text2img)5 CreditsGenerate images from text prompts using Grok 5 AI.
Text to Video (text2video)24 CreditsGenerate videos from text prompts using Grok 5 AI.
Image to Video (img2video)24 CreditsGenerate videos from images using Grok 5 AI.
2

Create Task

POSThttps://grok5ai.com/api/generate
Async Generation

Pricing

Credits vary by model: text2img costs 5 credits, text2video and img2video cost 24 credits each.

Initiate a generation task. The API returns a task_id immediately, which you use to poll for results.

Body Parameters

ParameterTypeRequiredDescription
modelstringRequiredModel to use: text2img, text2video, or img2video.
promptstringConditionalThe text description for generation. Max 5000 characters. Required for text2img and text2video.
image_urlsarrayConditionalArray of image URLs for img2video mode. Required if task_id is not provided.
task_idstringConditionalTask ID from a previous generation to use as input image. Required if image_urls is not provided.
callback_urlstringOptionalWebhook URL for task completion notification.

Request Examples

Text to Image Example (cURL)
curl -X POST https://grok5ai.com/api/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text2img",
    "prompt": "A serene mountain landscape at sunset"
  }'
Text to Video Example (cURL)
curl -X POST https://grok5ai.com/api/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text2video",
    "prompt": "A timelapse of clouds moving over mountains"
  }'
Image to Video Example (cURL)
curl -X POST https://grok5ai.com/api/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "img2video",
    "image_urls": ["https://example.com/image.jpg"]
  }'
Success Response
{
  "code": 200,
  "data": {
    "task_id": "grok5abc123def456img",
    "status": "IN_PROGRESS"
  }
}
Error Response
{
  "code": 400,
  "message": "Bad Request: 'prompt' is required.",
  "data": null
}
3

Check Status

GEThttps://grok5ai.com/api/status

Poll this endpoint to check the progress of your task. We recommend polling every 5-10 seconds.

Query Parameters

ParameterTypeDescription
task_idstringThe task ID received from the generate endpoint. Required

Status Values

PENDINGTask is queued
IN_PROGRESSProcessing
SUCCESSCompleted
FAILEDError occurred
cURL
curl -X GET "https://grok5ai.com/api/status?task_id=grok5abc123def456img" \
  -H "Authorization: Bearer YOUR_API_KEY"
Response (In Progress)
{
  "code": 200,
  "data": {
    "task_id": "grok5abc123def456img",
    "status": "IN_PROGRESS",
    "consumed_credits": 10,
    "created_at": "2024-12-19T10:00:00Z"
  }
}
Response (Completed)
{
  "code": 200,
  "data": {
    "task_id": "grok5abc123def456img",
    "status": "SUCCESS",
    "response": [
      "https://cdn.example.com/image.png"
    ]
  }
}
Response (Failed)
{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "grok5abc123def456img",
    "status": "FAILED",
    "consumed_credits": 0,
    "error_message": "Content policy violation detected",
    "created_at": "2024-12-19T10:00:00Z",
    "request": { ... },
    "response": null
  }
}

Error Codes

CodeDescription
200Success
400Bad Request - Invalid parameters (missing prompt, invalid model, etc.)
401Unauthorized - Missing or invalid API key
404Not Found - Task ID does not exist
500Internal Server Error - Please retry or contact support

Need Help?

Check out our support channel or email us.

Contact Support