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

xAI API error

xAI API gRPC RESOURCE_EXHAUSTED: what it means and how to fix it

Error message
gRPC RESOURCE_EXHAUSTED

Retry? YesLast verified 2 documented fixes2 sources

What it means

gRPC status raised by the xAI Python SDK when a resource quota has been exceeded, meaning the user has exceeded their API usage quota or rate limits. Sync clients raise grpc.RpcError and async clients raise grpc.aio.AioRpcError.

Causes

  • The user has exceeded their API usage quota or rate limits for requests

How to fix it

  1. Fix 1.

    Retry with exponential backoff on RESOURCE_EXHAUSTED (official xAI SDK example).

    Snippet
    def request_with_backoff(prompt, max_retries=5):
        chat = client.chat.create(model="grok-4.7")
        chat.append(user(prompt))
        for attempt in range(max_retries):
            try:
                return chat.sample()
            except grpc.RpcError as e:
                if e.code() != grpc.StatusCode.RESOURCE_EXHAUSTED:
                    raise
                wait = 2 ** attempt
                time.sleep(wait)
        raise RuntimeError("Max retries exceeded")
  2. Fix 2.

    The SDK does not retry this code by default; add it to a custom gRPC retry policy via the grpc.service_config channel option.

    JSON
    "retryableStatusCodes": ["UNAVAILABLE", "RESOURCE_EXHAUSTED"] # Additional status code for retry

More xAI API errors

All 18 xAI API errors

FAQ

What does the xAI API error "gRPC RESOURCE_EXHAUSTED" mean?

gRPC status raised by the xAI Python SDK when a resource quota has been exceeded, meaning the user has exceeded their API usage quota or rate limits. Sync clients raise grpc.RpcError and async clients raise grpc.aio.AioRpcError.

How do I fix xAI API "gRPC RESOURCE_EXHAUSTED"?

There are 2 documented fixes. Start with the first: Retry with exponential backoff on RESOURCE_EXHAUSTED (official xAI SDK example).

Should I retry xAI API "gRPC RESOURCE_EXHAUSTED"?

Yes. The official docs treat this error as retryable.

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.