Errors, rate limits and costs | Master AI Automation in 4 hours Master AI Automation in 4 hours Course About Ayush Modules Sample chapter Toolbox The Microcap Minute Classroom / Module 04: APIs: How Software Talks / Chapter 7 Errors, rate limits and costs Watch first, then read. Same lesson, your pace. What you will learn – The four error codes that explain most failures – Rate limits: what they are and the polite way through them – Token costs: estimating before running The four codes that matter APIs answer failure with numbers. Memorise these four and you can diagnose nearly everything: Code Name Meaning Fix 401 Unauthorised Key missing/invalid Check .env , check header spelling 404 Not found Wrong URL/model name Re-read docs; copy model ID exactly 429 Too many requests You hit the speed/quota limit Wait + retry (below), go off-peak 500 Server error Their fault Wait a minute; it’s not your bug The debugging protocol from Module 3 Chapter 7 applies perfectly: full error → AI → fix. Never paraphrase a 401 into “it doesn’t work”. 429: the polite queue Rate limits are guard rails: “N requests per minute”, “M tokens per day”, every provider protects its kitchen from floods. Free tiers have smaller rails. When you meet 429: Wait and retry , many libraries do this automatically (“exponential backoff”: retry after 2s, then 4s, then 8s…) Batch slower , add time.sleep(1) between calls in loops Rotate free models , Chapter 6’s trick: three free models = triple the rails Go off-peak , midnight IST queues are empty Costs without surprises Paid tokens are billed per million; rough current scale: small fast models ≈ tens of paise per million input tokens, flagship models ≈ ₹150-400. Before any bulk run, estimate: 10,000 summaries × ~800 tokens ≈ 8M tokens On a :free model → ₹0 On a cheap paid model → a few rupees On a flagship → hundreds of rupees Same output, wildly different bill, so route bulk work to free/small models and save flagships for hard thinking. OpenRouter’s dashboard shows live spend per model; check it after your first loops. Try it yourself Manufacture each error once, safely: call with a garbage key (hello 401), a made-up model name (404), then fire 30 rapid requests in a loop at one free model until 429 arrives. Read each error, predict the code before revealing it. Then add a retry with backoff to your loop and watch it politely survive. Log the experience in learn/error-diary.md . Key takeaways – 401 = your key, 404 = your URL, 429 = your speed, 500 = their server. – Survive 429s with backoff, slower batching, model rotation, off-peak timing. – Estimate tokens × price before bulk runs; route bulk to free models. – Dashboards make spend visible, glance after every new script. Download the exercise sheet (PDF) Module workbook (PDF) ← Prev: Free models forever Module 04 index → Classroom / Module 04: APIs: How Software Talks / Chapter 7 Errors, rate limits and costs What you will learn – The four error codes that explain most failures – Rate limits: what they are and the polite way through them – Token costs: estimating before running The four codes that matter APIs answer failure with numbers. Memorise these four and you can diagnose nearly everything: Code Name Meaning Fix 401 Unauthorised Key missing/invalid Check .env , check header spelling 404 Not found Wrong URL/model name Re-read docs; copy model ID exactly 429 Too many requests You hit the speed/quota limit Wait + retry (below), go off-peak 500 Server error Their fault Wait a minute; it’s not your bug The debugging protocol from Module 3 Chapter 7 applies perfectly: full error → AI → fix. Never paraphrase a 401 into “it doesn’t work”. 429: the polite queue Rate limits are guard rails: “N requests per minute”, “M tokens per day”, every provider protects its kitchen from floods. Free tiers have smaller rails. When you meet 429: Wait and retry , many libraries do this automatically (“exponential backoff”: retry after 2s, then 4s, then 8s…) Batch slower , add time.s
Errors, rate limits and costs
Written by
in