Skip to content
IT Vizag
← Async & Performance

▶ Sign up free for the video, slides & prompts

The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.

Checking…

AI angle: AI pipelines at scale

Lesson 9 of 10 · 3 min read

Rate limits, batching and backoff when calling models in bulk.

🎬 Video version coming soon — read it now

Running an AI task on 10 items is easy. Running it reliably on 50,000 support tickets or product descriptions needs planning: rate limits, batching, retries, cost and resumability.

Rate limits

Providers limit requests per minute and tokens per minute, depending on your account tier. Exceed them and you get HTTP 429 Too Many Requests. Check your limits in the provider's console before planning a big job.

Retries with backoff

The official SDKs automatically retry 429s, server errors and connection problems with exponential backoff: wait 1s, then 2s, then 4s, plus a little randomness so all your tasks don't retry at the same instant. You can raise the retry count:

🔒 Code example: sign up free (above) to unlock it.

If you call a plain HTTP API without an SDK, write the same idea yourself:

🔒 Code example: sign up free (above) to unlock it.

Control concurrency

Use a semaphore sized to your limits. A simple starting point: begin at 5 concurrent requests, watch for 429s, then increase gradually.

Batching

Two kinds of batching help:

  • Several small items per request: classify 20 short reviews in one call with structured output returning a list, instead of 20 calls. Fewer requests, and shared instructions are sent once.
  • Provider batch APIs: submit thousands of requests as one job and collect results later, often within hours, usually at a significant discount. Ideal when nobody is waiting for the answer.

Make it resumable

A 3-hour job will be interrupted eventually: laptop sleep, network loss, a bug at item 30,000.

🔒 Code example: sign up free (above) to unlock it.

Write each result as it completes (JSON Lines: one JSON object per line). On restart, skip what's finished.

Estimate cost before you start

  1. Run 20 representative items.
  2. Average response.usage.input_tokens and output_tokens.
  3. Multiply by the item count and the provider's price per million tokens.
  4. Decide if it's worth it, or shorten the prompt or choose a smaller model after testing quality.

Monitor as it runs

Print progress every 100 items: count done, errors, average seconds per item and tokens used. A job that's silent for an hour is a job you can't trust.

Tip: Keep a small "golden set" of items with known correct answers, and run it before every big job. If the prompt or model changed and quality dropped, you'll know before spending money on 50,000 items.

In one line

At scale, respect rate limits with bounded concurrency and backoff, batch where you can, write results as you go so you can resume, and estimate cost first.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend