API / handle-grok-api-rate-limits

API

Handle Grok API rate limits

Handle Grok API rate limits

Every xAI API team has per-model caps on requests per second (RPS) and tokens per minute (TPM). RPS is derived from RPM/60, so you cannot dump a full minute of requests into one second. Exceed either cap and the API returns HTTP 429. View your tier and per-model numbers on the Rate Limits page in the xAI Console.

Tiers by cumulative spend

Tiers unlock from cumulative API spend since January 1, 2026. Once you qualify, you stay there — tiers never downgrade. Text and embedding models use this table. Voice and Imagine increases go through sales@x.ai.

Tier Spend threshold
Tier 0 $0 (default)
Tier 1 $50
Tier 2 $250
Tier 3 $1,000
Tier 4 $5,000
Enterprise On request

Qualification counts prepaid credit purchases and successfully fulfilled invoices.

grok-4.6 RPS / TPM by tier

Tier RPS TPM
T0 150 50M
T1 172 53M
T2 208 60M
T3 312 74M
T4 500 100M

Imagine image models (grok-imagine-image, grok-imagine-image-quality, grok-imagine-image-2.0) have RPS only — no TPM column. Other models (including grok-4.3, grok-build-0.1, and video Imagine) have their own rows on the Rate Limits docs page.

What counts toward TPM

All of these count against the model's TPM budget:

  • Prompt tokens (text, image, audio)
  • Completion tokens
  • Reasoning tokens on reasoning models
  • Cached prompt tokens (still count toward TPM; they bill at the reduced cached rate)

See Maximize Grok API prompt cache hits and Read API request cost in USD ticks for cache and cost meters.

Back off on 429

import os
import time
from openai import OpenAI, RateLimitError

client = OpenAI(base_url="https://api.x.ai/v1", api_key=os.getenv("XAI_API_KEY"))

def request_with_backoff(messages, max_retries=5):
    for attempt in range(max_retries):
        try:
            return client.chat.completions.create(
                model="grok-4.6",
                messages=messages,
            )
        except RateLimitError:
            wait = 2 ** attempt
            time.sleep(wait)
    raise RateLimitError("Max retries exceeded")

xAI SDK uses the same pattern with from xai_sdk.exceptions import RateLimitError.

Raise limits

  • Spend more — tiers upgrade automatically.
  • Request an increase in the xAI Console when you need higher caps without more spend, or beyond Tier 4.
  • Email sales@x.ai for enterprise capacity or Voice/Imagine bumps.

Pitfalls

  • Treating cached prompt tokens as free of TPM — they still burn the minute budget.
  • Bursting a full RPM into one second — RPS is RPM/60.
  • Assuming Imagine image models share TPM with text models — image Imagine is RPS-only on this page.