---
title: Cost, limits and choosing a model
summary: How to pick a model with your own tests, what drives cost and latency, and how to keep both under control in your app and in long agent sessions.
section: ai
phase: plan
order: 8
last_reviewed: 2026-11-20
---

# Cost, limits and choosing a model

Model lineups, prices and limits change every few months, so this page has no tables of them. It teaches the part that doesn't expire: how to choose by measuring, what actually drives the bill and the wait, and which habits keep both down.

## You'll be able to

- Choose a model for a feature using your own test cases instead of reputation
- Explain what you are billed for and where the tokens go
- Reduce latency and cost without quietly lowering quality
- Spot the habits that make long agent sessions expensive

## The mental model

Choosing a model is a three-way trade between **quality**, **speed** and **cost**, and the right balance is different for every task. Using the biggest model for everything is like hiring a specialist to sort the mail. Using the smallest for everything works until the first hard case. The way out of guessing is the same as everywhere else in this section: **measure on your own data.**

Cost has a simple shape too. You pay for tokens going in and tokens coming out, plus a few modifiers. Anything that sends fewer tokens, or fewer requests, costs less and runs faster.

> **Note:** Vendors change model names, prices, limits and features often. Everything here is a principle to check against current docs and your own measurements. Last checked 2026-11-20.

## Key concepts

- **Quality, speed, cost, effort:** Anthropic's guide lists capabilities, response speed, cost and effort as the factors. "Effort" (OpenAI calls it reasoning effort) is a setting on some models that trades depth of thinking for speed and cost, and Anthropic says tuning it is often a better lever than switching models.
- **Two starting strategies:** *Efficiency-first* starts with a faster, cheaper model and upgrades only where a specific capability gap shows up. It suits prototypes, tight latency, cost sensitivity and high-volume simple tasks. *Capability-first* starts with the strongest model, tunes the prompt, then lowers effort or tries smaller models over time. It suits complex reasoning and highly autonomous agent work.
- **Benchmark on your own task:** Anthropic calls building tests for your use case the most important step: run real prompts and data, compare accuracy, response quality and edge-case handling, then weigh the result against cost. OpenAI's guide agrees: compare models on the same inputs and keep the lightest setting that meets your quality bar.
- **Time to a usable result:** OpenAI suggests measuring this, including your review time, not just model speed. A cheap model that needs three rounds of fixing isn't cheap.
- **Combining models:** A cheaper model can do most of the work while a stronger one handles the hard decisions or coordinates the rest, so most tokens are billed at the lower rate.
- **What you're billed for:** Input tokens and output tokens, with cached prefixes priced differently for writing and reading, and a discount for batch (asynchronous) jobs. Tool definitions, tool calls and tool results count as input tokens. Some server-side tools add their own per-use charges. Reasoning ("thinking") tokens are billed as output.
- **Token counts differ by model:** Newer tokenizers can produce more tokens for the same text, so compare cost using each model's own usage numbers, not word counts.
- **Latency levers:** Both vendors point the same way: use a faster model or lower effort when quality allows, generate fewer tokens (ask for only the detail needed, request specific fields, set an output cap), send fewer input tokens, make fewer sequential requests, run independent calls in parallel, and stream so users see progress. OpenAI adds: don't default to a model when plain code or a template already knows the answer.
- **Measure before tuning:** Track time to first token and end-to-end latency, and look at p50 and p95 on representative traffic, not a single request. Anthropic also advises getting the prompt working well first, because optimizing early can hide your best result.
- **Agent sessions are different:** In a long coding-agent session, the whole conversation is sent again on every request, and each tool call triggers another one. Cost grows with how long the session runs and how much context it carries.

## Decisions you make (not the agent)

| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| Starting point | Capability-first for complex or high-stakes tasks; efficiency-first for simple, high-volume ones | You have no tests yet: write them first |
| How to decide | Run your eval set on the candidates, compare quality, latency and cost | Never decide from a handful of examples or a leaderboard |
| Effort or reasoning level | Lowest setting that passes your evals | Hard cases that fail at low effort |
| One model or several | One model per feature | A cheap model for easy cases and a stronger one for hard ones (route on a measurable signal) |
| Output length | Ask for only what you need, with a hard cap | Long-form generation; remember the cap truncates mid-sentence |
| Caching | Stable instructions first, measure hit rates | Prompts that are different every time |
| Real-time or batch | Batch or background jobs for work no one is waiting on | Interactive features |
| Spend controls | A monthly limit and usage alerts from day one | Never run unlimited |
| Agent model for coding | A mid-range default for most work; the largest only for hard design or reasoning | A task that keeps failing at the default |
| Revisit | Re-run your evals when a new model ships or prices change | Never lock in forever |

## What good output looks like

- A short decision record: criteria, the eval results for each candidate, the choice, and when to revisit
- Usage logged per request: input, cached and output tokens, latency, and the model used
- Cost per unit of work (per ticket, per document) calculated from real usage and prices kept in config, not hard-coded in your head
- Prompts that ask for only what is needed and put stable content first
- Spend and rate limits set, with alerts

## Red flags

- **The biggest model for everything** → measure; many tasks pass on a cheaper setting.
- **Switching models because of one bad answer** → add that case to your evals, then compare properly.
- **No baseline** → without evals you can't tell whether a cheaper model is good enough.
- **Averages only** → watch p95, because users feel the slow tail.
- **An output cap that cuts answers off** → mid-sentence truncation breaks parsing, and on reasoning models the cap can also count the thinking tokens.
- **Huge tool and instruction lists in every request** → they are input tokens each time. Send only what the task needs.
- **A long agent session that is never cleared** → the full history rides along on every request. Start fresh between unrelated tasks.
- **No spend limit** → a loop or a spike becomes a surprise bill.
- **Reaching for an LLM where code would do** → formatting, lookups and arithmetic are cheaper and exact as code.

## Worked example

**Task:** The ticket summarizer from [Building with LLM APIs](/docs/ai-agents/building-with-llm-apis.md) is live. It runs on the most capable model available, and both the bill and the response time are higher than you'd like.

Someone suggests switching to the smallest model. You try it on three tickets and it looks fine, so it ships.

**What a good result contains:** the eval set from before, run against two or three candidates and settings; a table of pass rate per criterion, p50 and p95 latency, tokens per request and cost per 1,000 tickets (computed from usage logs and prices in a config file); a recommendation; and a plan for what happens on the cases the cheap setting gets wrong.

**The wrong turn:** three easy tickets proved nothing. On long, ambiguous or non-English tickets the small model misses priorities, and nobody notices until customers complain. Meanwhile the real savings were elsewhere: the prompt repeated a long preamble that could be cached, and a nightly backfill ran synchronously when it could have been a batch job.

**How review catches it:** run the whole eval set before and after, and compare every criterion, not just the average. Then pick the lightest setting that passes, and consider routing: use the cheaper setting by default and the stronger one for tickets flagged as long or ambiguous, with eval cases at the boundary. Apply the free wins (stable prompt prefix first, shorter outputs, batch for the backfill) and re-measure.

## Sample prompts

### Weak vs strong
```compare
## Weak
Make our AI feature cheaper and faster.
## Why it fails
No target, no baseline and no way to know whether quality dropped. The agent will pick a smaller model and call it done.
## Strong
Goal: reduce cost and latency of the ticket summarizer without lowering quality.
Step 1, measure: add logging per request of model, input tokens, cached input tokens, output tokens and latency. Do not log ticket text.
Step 2, compare: write a script that runs the eval set in evals/tickets.json against <candidate A> and <candidate B>, each at <low> and <medium> effort. For each combination report pass rate per criterion, p50 and p95 latency, average tokens, and estimated cost per 1,000 tickets using prices from prices.config.json (leave placeholders; I will fill them in).
Step 3, recommend: the lightest combination that meets these thresholds: <pass rate thresholds>. List the cases it fails.
Constraints: don't change the prompt in this pass. Non-goals: no UI changes.
Verify: show the script output and the table.
## Why it works
Measure first, compare on your own tests, and keep prices in config so the page isn't tied to numbers that go stale.
## What changed
- **Measure first**: tokens, cached tokens and latency are logged
- **Candidates and settings** are compared on your own eval set
- **Prices live in config**, not in the prompt or the head
- **A threshold** defines 'good enough'
- **Failing cases are listed**
```

### Design a routing rule
```text
Propose a routing rule: the cheaper model handles most tickets, and the stronger one handles the rest. Suggest 2-3 measurable signals for escalating (for example length, a low-confidence flag, or language), and for each, estimate the share of tickets it would escalate from our logs. Then add eval cases that sit right on the boundary and show the pass rate with and without routing.
```
*Why it works:* A routing rule is only safe if you test the boundary cases.

### Put the prompt on a token diet
```text
Audit the prompt and request for this feature for wasted tokens. List: (1) instructions or examples that never change, which should go first so they can be cached, (2) content we send that the task doesn't need, (3) outputs we request that we don't use, (4) places an output cap or more specific format request would shorten answers. Rewrite the prompt builder with these changes and show before and after token counts on 5 real inputs.
```
*Why it works:* Fewer tokens in and out helps both cost and latency, and the before/after counts prove it.

### Find batch candidates
```text
List every place our code calls the model. For each, say whether a user is waiting on the result. Mark the ones that don't need an immediate response as candidates for batch or background processing, and say what would change in the code. Don't change anything yet.
```
*Why it works:* Work nobody is waiting on can usually be scheduled more cheaply.

### Audit what an agent session carries
```text
List everything that is loaded into your context on every turn of this session: instruction files, tool and MCP server definitions, and any other standing instructions. For each, estimate how large it is, whether this task needs it, and what we could remove, move into on-demand material, or disable.
```
*Why it works:* In agent sessions the standing context is paid for again on every request, so trimming it compounds.

### Write the decision record
```text
Write a one-page model decision record for <feature>: the criteria that matter, the candidates we tested, a table of the eval results (quality per criterion, p50 and p95 latency, cost per unit), the choice and why, known weaknesses, and when to re-run the evals. Use only the numbers from <results file>; mark anything missing as "not measured".
```
*Why it works:* A short record keeps the decision honest and tells future you when to revisit it.

## Check your understanding

```quiz
Q: How should you decide which model to use for a feature?
- [ ] Pick the one with the best reputation
- [x] Run your own eval set against the candidates and compare quality, speed and cost
- [ ] Use whatever the agent suggests
> Why: Both vendors' guidance is to benchmark on your own task and keep the lightest setting that meets your quality bar.

---

Q: Which of these is typically billed as output?
- [ ] Your system prompt
- [x] Reasoning ("thinking") tokens, along with the text the model writes
- [ ] Nothing, thinking is free
> Why: Thinking tokens bill as output, which is one reason reasoning effort is a cost lever.

---

Q: Why do long agent sessions get expensive?
- [ ] The model slows down
- [x] The whole conversation is sent again on every request, and each tool call adds another request
- [ ] Longer sessions use a bigger model
> Why: Cost grows with how long the session runs and how much context it carries, so clear it between unrelated tasks.
```

## Checklist

- [ ] An eval set exists, and the decision came from running it
- [ ] Per-request logging covers model, tokens, cached tokens and latency
- [ ] The lightest setting that passes quality is the one in use
- [ ] Stable prompt content comes first, and outputs are as short as the task allows
- [ ] Work nobody is waiting on runs in batch or the background
- [ ] Spend limits and alerts are set
- [ ] Long agent sessions are cleared between unrelated tasks
- [ ] The decision has a date and a reason to revisit

## Go deeper

- [Choosing the right model (Claude docs)](https://platform.claude.com/docs/en/about-claude/models/choosing-a-model): efficiency-first and capability-first strategies, benchmarking and combining models
- [Reducing latency (Claude docs)](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/reduce-latency): model choice, shorter outputs and streaming
- [Pricing (Claude docs)](https://platform.claude.com/docs/en/about-claude/pricing): which things are billed, including caching, batch and tool use; check it for current numbers
- [Model selection (OpenAI docs)](https://developers.openai.com/api/docs/guides/model-selection): matching model and reasoning effort to the task, and measuring time to a usable result
- [Latency optimization (OpenAI docs)](https://developers.openai.com/api/docs/guides/latency-optimization): measuring p50 and p95, fewer tokens, fewer requests and parallelism
- [Manage costs effectively (Claude Code docs)](https://code.claude.com/docs/en/costs): why long agent sessions get expensive and how to control it
- [Building with LLM APIs](/docs/ai-agents/building-with-llm-apis.md): the wrapper, caching and the eval set this page relies on
- [Context engineering](/docs/ai-agents/context-engineering.md): keeping standing context small
