Skip to main content
Watch: I Built an AI App Without Leaving Databricks

xAI API error

xAI API 429 Too Many Requests: what it means and how to fix it

Error message
429 Too Many Requests

Retry? YesLast verified 3 documented fixes2 sources

What it means

Returned on inference endpoints when you send requests too frequently and reach your rate limit. Each team has per-model limits on requests per second (RPS) and tokens per minute (TPM), set by a spend-based tier, and exceeding any limit returns 429.

Causes

  • Sending requests too frequently and reaching the rate limit
  • Exceeding the per-model RPS or TPM cap for your team's tier
  • All tokens count toward TPM, including prompt, completion, reasoning and cached prompt tokens

How to fix it

  1. Fix 1.

    Implement exponential backoff to handle 429 gracefully (official OpenAI SDK example).

    Snippet
    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.7",
                    messages=messages,
                )
            except RateLimitError:
                if attempt == max_retries - 1:
                    raise
                wait = 2 ** attempt
                time.sleep(wait)
  2. Fix 2.

    Reduce your request rate or increase your rate limit on xAI Console.

  3. Fix 3.

    Tiers upgrade automatically based on cumulative spend; you can also submit a limit increase request through the xAI Console, or email sales@x.ai for enterprise capacity.

More xAI API errors

All 18 xAI API errors

HTTP 429 at other providers

Compare 429 across providers

FAQ

What does the xAI API error "429 Too Many Requests" mean?

Returned on inference endpoints when you send requests too frequently and reach your rate limit. Each team has per-model limits on requests per second (RPS) and tokens per minute (TPM), set by a spend-based tier, and exceeding any limit returns 429.

How do I fix xAI API "429 Too Many Requests"?

There are 3 documented fixes. Start with the first: Implement exponential backoff to handle 429 gracefully (official OpenAI SDK example).

Should I retry xAI API "429 Too Many Requests"?

Yes. The official docs treat this error as retryable.

Which other AI APIs return HTTP 429?

Per their official error docs: Amazon Bedrock (429 ThrottlingException; 429 ModelNotReadyException), Anthropic API (429 rate_limit_error; 429 rate_limit_error (enforced_spend_limit_reached)), Azure OpenAI (429 Too Many Requests (Rate limit is exceeded); 429 Too Many Requests (System is experiencing high demand); 429 Too Many Requests (temporary rate limit adjustment); 429 Too Many Requests (token budget exceeded by request parameters)), Cohere API (429 Too Many Requests), DeepSeek API (429 - Rate Limit Reached), Gemini API (429 rate_limit_exceeded; 429 quota_exceeded; 429 too_many_requests; 429 RESOURCE_EXHAUSTED), Groq API (429 Too Many Requests), Mistral API (429 Too many requests), OpenAI API (429 credit_balance_exhausted; 429 Rate limit reached for requests; 429 rate_limit_error slow_down; 429 organization_spend_limit_exceeded; 429 project_spend_limit_exceeded; 429 organization_usage_limit_exceeded), OpenRouter (429 rate_limit_exceeded), Vertex AI (429 RESOURCE_EXHAUSTED; 429 Resource exhausted, please try again later; 429 Too many requests. Exceeded the Provisioned Throughput).

Sources

Last verified against 2 sources: xAI API's official docs and official SDK repositories.

Newsletter

Know when the APIs change

One email per week. New model releases, API changes, what broke, and how developers are working around it.