TTodAPI

Errors

429 rate limit

The request was valid, the key is valid, and the balance is fine — but a limit was hit. 429 is the one error where retrying is the correct answer, provided you back off.

What causes it

How to fix it

import random, time
from openai import OpenAI, RateLimitError

client = OpenAI(api_key="sk-...", base_url="https://todapi.work/v1")

def call(**kwargs):
    delay = 0.5
    for attempt in range(6):
        try:
            return client.chat.completions.create(**kwargs)
        except RateLimitError:
            if attempt == 5:
                raise
            time.sleep(delay + random.uniform(0, delay / 2))
            delay = min(delay * 2, 8)
  1. Back off exponentially with jitter — synchronised retries recreate the burst.
  2. Cap concurrency in your worker pool; do not let the SDK open unlimited streams.
  3. If one key is the bottleneck, split work across keys instead of raising the retry count.

What not to do

Retrying immediately in a tight loop turns a short limit into a longer one, and every retry still costs you the round trip. Retries should be bounded — three to five attempts, then surface the error.

Should you retry?

Yes, with backoff. If it happens every day at the same hour, the fix is architectural, not a longer timeout.

FAQ

How long does a 429 last?

Usually milliseconds to a few seconds, because the limit is a window rather than a lock. A Retry-After header, when present, is the precise answer.

Is 429 the same as 402?

No. 402 means the prepaid balance is empty and retrying cannot help.

402 balance

The other error people confuse with a rate limit.

Pricing

What a retry actually costs.

OpenAI alternative

Same SDK, different base URL.