API costs and limits
API prices are quoted per million tokens, differ by model and change several times a year, so read the price page itself rather than a number that will be wrong by spring: the per-token arithmetic, the rate limits and tiers that cap how fast you can spend, the two discounts that cut a large bill (cached prompts and batch jobs), and the budget alarm to set before any loop runs.
Where each vendor publishes prices and limits
Bookmark these instead of copying numbers. All four checked September 2026.
| Vendor | Prices | Rate limits and tiers | Prompt caching | Batch jobs |
|---|---|---|---|---|
| OpenAI | Pricing | Rate limits | Prompt caching | Batch |
| Google Gemini | Pricing | Rate limits | Context caching | Batch mode |
| xAI | Pricing | Rate limits | On the pricing page, as "cached input" | On the pricing page |
| Anthropic | Pricing | Rate limits | Prompt caching | Batch processing |
How to read a price page
Every page is a table with one row per model and at least two price columns. Read it in this order.
- Find the row for the exact model ID you use. Two models from one vendor can differ in price by ten times or more. A "latest" alias points at whatever is newest, so the price behind it can change without your code changing.
- Read input and output separately. Both are dollars per million tokens (MTok). Output is the dearer of the two on every price page checked, often several times dearer, so a job that writes long answers costs more than one that reads long documents.
- Look for a cached-input column. That is the price of input the vendor has already seen recently. It is a fraction of the normal input price.
- Check for a size break. Some models charge more per token once a single request passes a size threshold, stated in the row or a footnote.
- Read the footnotes for thinking. On a thinking model, the tokens it spends reasoning are billed as output, even though the reply does not show them. That is often the largest surprise on a first bill.
- Note the free tier's terms, if there is one. Google's free Gemini tier may use what you send to improve its products, and its paid tier does not (Gemini pricing). A free tier is for trying, not for work documents.
Then do the sum from the recipes page: tokens in divided by a million times the input price, plus tokens out divided by a million times the output price. A token is roughly three quarters of a word.
Rate limits and tiers
A rate limit caps how fast you can call, not how much you may spend in total. Vendors count some mix of requests per minute, input or total tokens per minute, and for some, requests per day. Whichever runs out first stops you, and the API answers 429 Too Many Requests until the window refills. The reply usually carries a retry-after header saying how many seconds to wait, and headers on every reply show how much of each limit remains.
Limits rise with tiers. A new account starts low; paying more over time moves it up, automatically on all four. Google counts limits per project, not per key, so two keys in one project share one allowance (Gemini rate limits). xAI states that a tier, once reached, is never taken away (xAI rate limits). The practical rules:
- A 429 is a speed limit, not a fault. Wait the
retry-aftertime, then slow the loop down. Retrying at once only earns more 429s. - Burst traffic trips limits sooner than steady traffic. Anthropic notes that a per-minute limit may be enforced per second (Claude rate limits); a short pause between calls fixes most first-run 429s.
- Some tiers also carry a monthly spend cap. When an account reaches it, calls fail until the month turns or the cap is raised; on the Claude API that also arrives as a 429, without a
retry-after, so waiting will not help.
Prompt caching, as a concept
Many jobs send the same long opening on every call: the same instructions, the same policy document, the same template, with only the last few lines changing. Prompt caching lets the vendor keep that repeated opening for a short time and charge the cached-input price the next time it arrives. The vendors differ in the details. OpenAI caches a long repeated opening automatically, Anthropic lets you mark where the reusable part ends, and Google offers both an automatic form and one you create explicitly.
What it means for you: put the part that never changes first and the part that changes last. Recipe 3 on the recipes page (the same template, a different row of facts each time) is the textbook case. The cache lasts minutes, not days, so it pays when calls come in quick succession.
Batch jobs, as a concept
If you do not need the answers for a few hours, most vendors will take a whole file of requests at once and return the results later at a discount. Each vendor states its discount and its turnaround on its batch page. Batch work also runs under separate, larger limits, so it sidesteps most 429s. Classification of a large spreadsheet, overnight summaries of a document set and any job you would otherwise run in a slow loop are good candidates. A job where a person is waiting for the answer is not.
Set the alarm before the loop
Set these once, before your first real run, in the vendor's console:
- A spend limit or budget below what you would be upset to lose. Anthropic's console has a spend limit you set under the tier's cap (Claude rate limits); OpenAI shows its usage limits and budgets on the same page as its tiers (OpenAI rate limits); Gemini billing runs through a Google Cloud billing account, where you set a budget and alert emails (Cloud Billing budgets); on xAI you add credits before you call (xAI quickstart), so keep the balance small while you learn.
- A separate project or workspace per job, with its own key and, where offered, its own limit. One runaway script then cannot spend the whole account's budget.
- Your own cap in code. The recipe helper keeps a running token count; have the script stop when the count passes your estimate by half. A vendor's alarm tells you after the money is spent; your own check stops the loop before.
What to do with this
Open the price page for the model you used on the recipes page, and redo your estimate with today's numbers. Set a spend limit in that vendor's console. Then carry on with retrieval, which is how you send the relevant pages of a large document set instead of the whole thing on every call.
Vendor facts checked ; re-verify before relying on them.