All insights

Model APIs

Grok Video API: Official xAI Endpoint, Python Example, and Pricing

xAI documents a direct video-generation API. See a Python submit-and-poll example, model options and listed prices, plus production checks.

Illustration for Grok video api

Is there an official Grok video API?

Yes. xAI documents video generation through its own API at https://api.x.ai/v1/videos/generations. Submit a prompt, receive a request_id, and poll that request for the result. This is xAI’s API—not a third-party provider’s separate endpoint or pricing. The generation endpoint can also accept an image, but the example below focuses on text-to-video.

Python: submit a video job and retrieve its result

Set your xAI API key in the XAI_API_KEY environment variable and install requests (pip install requests). This example follows xAI’s documented request and polling pattern. It makes up to 120 status checks, with five-second sleeps between checks; request time adds to the total elapsed time.

import os
import time
import requests

API_KEY = os.environ["XAI_API_KEY"]
BASE_URL = "https://api.x.ai/v1"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

# Submit a text-to-video job.
response = requests.post(
    f"{BASE_URL}/videos/generations",
    headers=HEADERS,
    json={
        "model": "grok-imagine-video-1.5",
        "prompt": "A quiet lake at sunrise, mist drifting over the water",
        "duration": 10,
        "aspect_ratio": "16:9",
        "resolution": "720p",
    },
    timeout=60,
)
response.raise_for_status()
request_id = response.json()["request_id"]

# Poll the same job up to 120 times, sleeping between checks.
for attempt in range(120):
    result = requests.get(
        f"{BASE_URL}/videos/{request_id}",
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=60,
    )
    result.raise_for_status()
    job = result.json()

    if job["status"] == "done":
        print("Video URL:", job["video"]["url"])
        break
    if job["status"] == "expired":
        raise RuntimeError("Video job expired")

    if attempt < 119:
        time.sleep(5)
else:
    raise TimeoutError("No documented terminal status within 120 polling attempts")

The documented flow returns the job’s request_id from the submission and uses it in GET /v1/videos/{request_id}. The generation guide shows done with the result at video.url, and also documents an expired outcome. raise_for_status() handles HTTP error responses in this Python client; it does not describe every possible API error body. The code does not assume a documented failed status.

Duration, resolution, and model choice

xAI’s video overview lists clip durations of 1–15 seconds. It lists output resolutions by model and describes different model capabilities: Video 1.5 includes reference, voice, and pinned-frame controls; Video 1.5 Lite is identified as a lower-priced text- and image-to-video option; and the base grok-imagine-video model is listed for video editing and extension. The overview lists resolutions, but the distinctions below do not make claims about whether a resolution is native or upscaled. Confirm model access and the exact supported inputs for your intended workflow.

Model Documented distinction Listed output resolutions
grok-imagine-video-1.5 Reference, voice, and pinned-frame controls 480p, 720p, 1080p
grok-imagine-video-1.5-lite Lower-priced text- and image-to-video option 480p, 720p, 1080p
grok-imagine-video Video editing and extension 480p, 720p

These are documented capabilities, not a guarantee that a particular feature is enabled for every account.

Official xAI API pricing

xAI lists video output pricing by resolution and generated second. The following rates are in USD per second; applicable input-media charges may also affect a request’s total.

Model 480p 720p 1080p
grok-imagine-video-1.5 $0.08/sec $0.14/sec $0.25/sec
grok-imagine-video-1.5-lite $0.02/sec $0.03/sec $0.14/sec
grok-imagine-video $0.05/sec $0.07/sec Not listed

Example estimate: a 10-second 720p generation costs 10 × $0.14 = $1.40 at the listed Video 1.5 output rate. At the listed Lite 720p rate, the same duration is 10 × $0.03 = $0.30. These are rate-based estimates, not guaranteed invoice totals; check current model pricing and applicable input charges before budgeting.

These are xAI API rates. A third-party service may have its own host, credentials, request format, terms, and billing; do not treat its code or prices as xAI’s API contract.

Production checks

Before shipping an integration:

  • Protect the API key. Keep it on your server rather than in browser code; authenticate requests with the documented Bearer token header.
  • Track jobs by their own request IDs. Persist each request_id, poll that job, and handle the documented completed and expired outcomes. Choose timeouts, retries, and logging for your client; do not present them as xAI guarantees.
  • Estimate cost against the selected model and resolution. Multiply the listed output rate by expected generated seconds, and account for any applicable input-media charges.
  • Confirm operational fit. The cited documentation does not establish a universal completion-time guarantee or production SLA for every model and account. Check current account limits and applicable terms before promising throughput.
  • Review the terms for your workload. Evaluate the applicable API terms, data-processing terms, and policies before sending personal or confidential material.

Bottom line

xAI documents a direct Grok video API with an asynchronous submit-and-poll flow: POST /v1/videos/generations, save the returned request_id, then poll GET /v1/videos/{request_id} for the result. Choose the model and resolution for your required capabilities and budget, and verify account access, current limits, and applicable terms before relying on the integration in production.

Sources

Videos: Inference API REST Reference

Video Generation: Grok API Capabilities

Video Overview: Grok Imagine Video API

Grok Imagine Video 1.5 Lite

Grok Imagine Video

Grok Imagine Video 1.5

Terms of Service — Enterprise

Data Processing Addendum

Contact us