Skip to main content

Introduction to XAI (Grok)

Welcome to the XAI service documentation! This service integrates xAI’s Grok models for AI-powered image and video generation. Using grok-imagine-image and grok-imagine-video, you can create stunning visual content from text prompts, or use reference images to guide generation.

Features

XAI Grok offers the following generation capabilities:
  • Text-to-Image: Generate high-quality images from text prompts using the grok-imagine-image model, with customizable aspect ratios.
  • Image-to-Image: Provide a reference image along with a prompt to edit or transform images — output dimensions follow the reference image.
  • Text-to-Video: Generate videos from text prompts using the grok-imagine-video model, with control over duration (6s / 10s / 15s), aspect ratio, and resolution.
  • Image-to-Video: Use a reference image to guide video generation — when provided, aspect ratio and resolution follow the reference image automatically.
  • Async Task System: All generation requests return a taskId. Poll the task endpoint to get status and results.

How to Use XAI

  1. Create a Generation Task: Call the image or video generation endpoint with your prompt and parameters.
  2. Get Task ID: The response returns a taskId for tracking.
  3. Poll Task Status: Use the task result endpoint (GET /xai/tasks) to check progress.
  4. Download Results: Once the task status is completed, the result contains your generated content.

Available Endpoints

Image Generation

EndpointMethodDescription
/xai/imagesPOSTGenerate images from text prompts or reference images

Video Generation

EndpointMethodDescription
/xai/videosPOSTGenerate videos from text prompts or reference images

Task Management

EndpointMethodDescription
/xai/tasksGETQuery task status and results by taskId

Explore the API Documentation

Image: Video: Task:

Key Parameters

Image Generation

ParameterRequiredDescription
promptYesImage description (max 1000 characters)
modelYesgrok-imagine-image
aspectRatioNo1:1, 2:3, 3:2, 9:16, 16:9
imagesNoReference image URL (max 1); when provided, output size follows the reference

Video Generation

ParameterRequiredDescription
promptYesVideo description (max 1000 characters)
modelYesgrok-imagine-video
durationNo6 (default), 10, or 15 seconds
aspectRatioNo1:1, 2:3, 3:2, 9:16, 16:9
resolutionNo480P, 720P (default)
imagesNoReference image URL (max 1); when provided, aspectRatio and resolution are ignored

Task Status Values

StatusDescription
pendingTask is queued
readyTask is ready to be processed
assignedTask has been assigned to a worker
processingTask is currently being processed
completedTask finished successfully
failedTask encountered an error
cancelledTask was cancelled
timeoutTask timed out

Best Practices

  1. Write Clear Prompts: Be specific and descriptive to get more accurate results.
  2. Use Reference Images: When available, provide a reference image for more precise control over style and composition.
  3. Choose Appropriate Settings: Select the right aspect ratio, duration, and resolution for your use case.
  4. Implement Polling: Use exponential backoff when polling task status to avoid rate limiting.
  5. Handle Errors Gracefully: Check for failed and timeout statuses, and use errorMessage / errorCode for diagnostics.