Skip to content
Learn · AI Lessons · Free lesson

API Rate Limits and Cost Optimisation

You have built something that works. Users are happy, the model responses are good, and then the invoice arrives. Or worse: your application grinds to a halt at 9 in the morning on a Monday with a wall of HTTP 429 errors and no obvious explanation. Both problems have the same root cause: most developers learn enough about large language model APIs to get a prototype running, and then discover the billing and throttling mechanics only when something breaks in production. This lesson untangles those mechanics. Rate limits and spend quotas are different things, controlled by different levers, and they are routinely confused at considerable cost. Token pricing has a structure that rewards deliberate prompt design, and a toolkit of techniques (caching, batching, and model routing) can meaningfully reduce what you pay without degrading what your users experience. By the end you will be able to read a provider's pricing page with confidence, diagnose throttling errors correctly, and make informed decisions about when to call a frontier model and when a smaller one will do.

Start this lesson freeFree forever. No card required.
Intermediate 15 minutes AI for Practitioners Certificate upon completion

Create your free account

Unlock the full lesson, the quiz, and your verifiable completion.

Continue with Google
or
Continue with email

By continuing you agree to the Institute of AI terms of use and privacy policy.

Learners across the UK study with the Institute of AI
Open to everyone From the UK's professional body for AI 100% free, no card required
What you'll learn

By the end of this lesson, you will be able to:

  • Tell a throughput rate limit apart from a spend quota, even when both arrive as an HTTP 429.
  • Explain how token pricing works, and why output tokens carry a higher price than input tokens.
  • Cut spend with prompt caching, semantic caching, and routing easy tasks to a smaller model.
  • Smooth traffic with exponential backoff and jitter, async queues, and batching for latency-tolerant work.

Recommended before you start

None of these are hard requirements. The lesson is easier if they are already familiar, but everything it uses is explained along the way, so you can start without them.

  • Comfort calling a REST API and reading HTTP status codes.
Join Others Learning AI

Free to start. Free to finish. Free to prove.

Start this lesson free
Inside this lesson

3 sections, about 15 minutes.

Section one is open to everyone. Create a free account to work through the rest and take the quiz.

01

Rate Limits vs Quotas: Two Different Problems

Free preview

Developers frequently conflate two distinct constraints, and treating them as the same thing leads to debugging in the wrong place. Rate limits are throughput constraints: they govern how fast you can consume an API, typically expressed as tokens per minute, requests per minute, or tokens per day. When you exceed a rate limit, the API responds with an HTTP 429 status code, defined as too many requests; the server is not saying your account is out of funds, it is saying you are sending traffic faster than your tier permits. Spend quotas are volume or budget caps, which may appear as a monthly token ceiling or a hard spend limit in your billing console. Exhausting a quota surfaces differently per provider: some return a distinct account-level error, while others reuse HTTP 429 with a specific error code such as insufficient_quota, so read the error body rather than the status code alone; either way, it is not resolved by slowing your request rate. You can hit a rate limit with budget to spare, and you can exhaust a quota while sending requests well within your per-minute limit, so diagnosing which problem you have is the first step to fixing it. Why do rate limits exist? The short answer is fairness. LLM inference is GPU-bound, and a single large, sustained workload can starve other users sharing the same infrastructure, so rate limits ensure fair allocation across thousands of concurrent tenants and protect overall system stability. Higher-tier plans carry higher limits because the provider has planned for that capacity; the limit is a ceiling on how fast you may send, not a guaranteed level of throughput. Think of it like motorway smart lanes, where variable speed limits keep finite road capacity flowing for everyone. The standard way to handle 429 errors is exponential backoff with jitter. When a 429 is received, wait before retrying, and increase the wait time with each successive failure. Adding randomness, the jitter, to the delay prevents a thundering herd: if every client retries at the same interval, they all hit the API simultaneously and trigger another 429. Most provider SDKs include built-in retry logic, so verify it is enabled before writing your own.

02

How Token Pricing Actually Works

Unlock free
03

Practical Techniques for Cost and Traffic Optimisation

Unlock free
How it works

Walk away with proof, not just knowledge.

Step 1

Study the lesson

Work through every section at your own pace, from start to finish.

Step 2

Pass the quiz

A short set of questions on what you have just covered.

Step 3

Get your certification

Every completion has a certificate that you can share publicly for anyone to verify.

Your record of completion

Finish the lesson. Keep the proof.

The Institute of AI
Record of completion
API Rate Limits and Cost Optimisation
Completed by
Your name
Quiz score
90%
theinstituteofai.co.uk/verify/lesson/…

Pass the quiz and the Institute of AI issues you a record of completion with your score. Every completion has its own public verification page, so the link you put on your CV or LinkedIn profile can be checked by anyone, at any time.

  • Verifiable by anyone, with no account needed
  • One link for your CV, email signature, or LinkedIn profile
  • Issued by the UK's professional body for AI
— Common questions —

Frequently asked questions.

Is this lesson really free?+
Yes. Every AI lesson from the Institute of AI is free to take and free to complete, including the quiz and your record of completion. There is no trial, no card, and no catch.
Do I need a technical background?+
This lesson is pitched at intermediate level, so it helps to be comfortable with what is recommended above, though none of it is a hard requirement. Everything is explained in plain English, and if a term matters, the lesson covers it before using it.
How long does this lesson take?+
Around 15 minutes to work through, plus the quiz at the end. You can leave and come back at any point.
What do I get when I finish?+
A record of completion with your score, held on your profile. Each completion has a public verification page, so you can share a link on your CV or LinkedIn profile that anyone can check.
What is the Institute of AI?+
The Institute of AI is the UK’s professional body for artificial intelligence. It sets the standard of AI practice, works to that standard itself, and puts it within reach of everyone else. Its work runs across four areas: Accreditation, Practice, Platforms, and AI for All.

Join learners across the UK and start "API Rate Limits and Cost Optimisation" today.

Free lessons, a quiz to test what you have learned, and a completion you can verify publicly. All from the UK's professional body for artificial intelligence.

The Institute of AI

Free to learn.
Yours to prove.

Every AI lesson is free to start, free to finish, and ends in a completion you can verify publicly.