Core concepts

Rate limits

Per-key request limits and how to handle 429s.

Rate limits are applied per API key on a sliding one-minute window. Each endpoint family has its own bucket:

EndpointLimit (per minute)
/v1/messages60
/v1/messages/count_tokens120
/v1/images/*30

When you exceed a limit the API returns 429 rate_limited with a retry-after header telling you how many seconds to wait.

Handling 429s

Back off and retry after the retry-after interval. A simple exponential backoff with jitter works well for bursts:

import time, random

def with_retry(call, tries=5):
  for i in range(tries):
      resp = call()
      if resp.status_code != 429:
          return resp
      wait = float(resp.headers.get("retry-after", 2 ** i))
      time.sleep(wait + random.random())
  return resp
python · 10 lines

The official SDKs already retry 429 responses for you, honoring retry-after.

Rate limits | Spoof