# Chapter 29. Model Selection, Cost and Release Planning (/building-ai-workers/model-selection-and-cost/overview)

---
type: Document
title: Chapter 29. Model Selection, Cost and Release Planning
description: Price one week of Brightline's AP worker by step, and find what one invoice handled right costs. Lower that cost with a cache, a batch, effort or a smaller tier, check each change the way it can fail, and report it on its own line. Built on Claude first, then priced on OpenAI and an open model.
status: stable
order: 329
ksor:
  owner: team:panaversity
  audience:
    - public
  approval:
    by: process:panaversity
    at: 2026-11-30T10:58:07Z
chapter: '29'
part: III
expert_status: manager
objectives:
  - id: CCDV-F.D5.S1
    label: primary
  - id: CCDV-F.D5.S3
    label: primary
  - id: CCDV-F.D5.S4
    label: primary
  - id: CCAR-P.D2.T1
    label: primary
  - id: CCAR-P.D2.T5
    label: primary
  - id: CCAR-P.D4.T5
    label: primary
  - id: OAI.3.3
    label: primary
  - id: CCAR-P.D2.T4
    label: supporting
  - id: OAI.3.2
    label: supporting
word_budget: 4500
prerequisites:
  - '01'
  - '02'
  - '03'
  - '04'
  - '05'
  - '06'
  - '07'
  - 8
  - 9
  - '10'
  - '11'
  - '12'
  - '13'
  - '14'
  - '15'
  - '16'
  - '17'
  - '18'
  - '19'
  - '21'
  - '22'
  - '23'
  - '24'
  - '25'
  - '26'
  - '27'
  - '28'
build_step: One week of the AP worker priced by step against the 7:10 reports, then a cache, a batch and a smaller tier for the extraction, each checked the way it can fail and reported on its own line, a release plan for a new model id, and a port to OpenAI and an open model
artifact: brightline-ap with docs/cost-report.md and docs/release-plan.md, tag ch29
lab_data: https://github.com/panaversity/agentfactory-v2-resources/releases/latest/download/brightline-lab-ch29.zip
delta_entries:
  - D-031
concepts:
  - '29.1'
  - '29.2'
  - '29.3'
  - '29.4'
  - '29.5'
  - '29.6'
  - '29.7'
  - '29.8'
  - '29.9'
  - '29.10'
last_verified: '2026-11-30'
sources:
  - id: anthropic-cost-and-intelligence
    title: Optimizing for cost and intelligence, Anthropic (verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/about-claude/models/optimizing-for-cost-and-intelligence
  - id: anthropic-pricing
    title: Pricing, Anthropic (verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/about-claude/pricing
generated:
  at: 2026-11-30T10:58:07Z
  by: esl-rewrite/1.2.0+ksor.1
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

<!-- EDITOR: two source ids are not in the drafting brief's shared list: anthropic-glossary (the Glossary page, for "Even with temperature set to 0, the results will not be fully deterministic") and anthropic-thinking-steering (the "Steering thinking and cost" page, one id for the whole chapter since review round 1, for max_tokens as the hard cap and the two remedies). The facts file reads both. The other option: cite the same facts from anthropic-migration-guide and anthropic-effort only, which do not carry the two remedies word for word. -->

<!-- EDITOR: objective ids in the front matter (spec, appendix point 8). The front matter carries the ids that specs/v2plan/data/chapters.yaml lists for Chapter 29: CCDV-F.D5.S1, D5.S3 and D5.S4 primary, with the CCAR-P and OAI ids, and CCAR-P.D2.T4 and OAI.3.2 supporting, as Chapter 27 did. The CCDV-F guide, version 1.1, calls the objectives 5.1, 5.2 and 5.3, and the spec adds 2.1 as supporting, which has no id in chapters.yaml. The ids switch when the plan's item G1 changes the objective map. The other option: write the guide 1.1 ids now and add 2.1 as supporting, in the same pull request as chapters.yaml. -->

## Start here if you skipped Chapter 28

*If you read Chapter 28, skip this. These are the words from the chapters before it that this chapter builds on.*

<!-- OPEN: Chapter 28 is being written at the same time as this chapter, so this table names nothing from it and links no page of it. Once it is published, link "Chapter 28" above, and add any word from it that this chapter uses. -->

| Word | What it means | Where this chapter uses it |
| --- | --- | --- |
| **Token**, **usage** | A token is a small piece of text that a model reads or writes. Prices are per million tokens, with one price for input and another for output. Every response reports its **usage**: how many tokens it read and wrote ([21.12](../agent-loop-by-hand/tokens-caching-and-what-a-call-costs.md)) | Everywhere |
| **Caching** | Keeping the start of a request on the provider's side, so the next request that starts the same way reads it at a fraction of the price (21.12). The usage shows tokens written to the cache and tokens read from it as their own counts | The point, 29.2, 29.6, 29.7 |
| **Model pinning** | Naming the exact model id in one place, such as `src/loop/config.json`, so the model changes only when you choose ([21.13](../agent-loop-by-hand/versions-models-and-keys.md)). The extraction's pin is `claude-sonnet-5-5` | 29.3, 29.5 |
| **Budget** | A hard cap, in dollars, on what one hosted session may spend. When a company pays you a fixed monthly fee, every run is your cost, not theirs ([23.5](../hosted-agents/a-budget-on-every-run.md)). Cedar Ridge Supply pays Brightline such a fee | Why it matters, 29.9 |
| **The morning triage** | The worker's scheduled run at 7:10 on each weekday. It is a hosted session with a budget of $0.50, and a check by code tests what it returns ([23.16](../hosted-agents/loops-check-feedback-and-stop.md)) | The point, 29.4, 29.6, 29.8 |
| **The month-end review** | Dave's review of the open invoices, on a budget of $1.00, tested by Lab 26's check by code ([Chapter 26](../context-engineering/overview.md)) | 29.4, 29.6 |
| **The extraction step** | For each new invoice, before 7:10, the portal's code makes two requests to the Messages API. The first asks for the invoice with the `get_invoice` tool. The second answers after the tool result ([Chapter 25](../prompts-and-structured-output/overview.md)) | Everywhere |
| **The three gates** | The extraction's checks by code, in order: the **stop reason** (why the model stopped writing), the **schema** (the shape of the answer) and the **values** (each one against the record). An answer that fails a gate is not used ([25.10](../prompts-and-structured-output/defensive-parsing.md)) | Everywhere |
| **The 7:10 report** | The morning list of every answer the code would not accept, each with its gate and its reason, and a count by gate (25.10) | The point, 29.1, 29.6 |
| **`needs_review`** | The status of a result that code would not accept. It waits for a person, and is never posted as done ([Lab 24](../evaluating-ai-workers/lab.md)) | Everywhere |
| **Golden set, suite** | The golden set is cases with known answers, labeled by Ana ([24.2](../evaluating-ai-workers/golden-sets.md)). The suite runs them. It has 42 cases: 26 questions and 16 extractions | Everywhere |
| **Trial, pass^k** | A trial is one run of one case. pass^k is the chance that all k trials of a case are right. Before a release, each case runs three trials ([24.6](../evaluating-ai-workers/metrics-you-can-defend.md)) | 29.1, 29.3, 29.5 |
| **Chapter 27's table of steps** | `docs/architecture.md`, with one row for each step of a job and who decides it ([27.1](../agent-architecture/workflow-or-agent.md)) | 29.6 |

## The point

**Tuesday, May 11, 2027, 9:00 in the morning.** You are the builder. Dave Kowalski, Brightline's controller, forwards the Console's cost for the week of Monday, May 3 to Sunday, May 9. The Console is the vendor's web page for your account and its bill. Dave adds one question: "What does one invoice cost us, and can it cost less without Ana seeing worse answers?"

<!-- EDITOR: the day, Tuesday, May 11, 2027, and the week read, May 3 to 9, are proposed in the spec (appendix point 3a) and agreed with the threads writing Chapters 28 and 30. They are not yet in specs/labs/part-2-facts.md. If Chapter 28's day moves, this day moves after it (appendix point 14). -->

<!-- OPEN: recorded run. Every blank in "The point" ($[total], $[b], [n], [a], $[b ÷ a], the largest step and each cache share) waits for the recorded week (spec, "The worked run"). -->

The bill cannot answer him. It lists calls and tokens by model. The 7:10 reports list invoices, by gate. Nothing joins the two.

So you join them. Each model call in the week wrote one line to the portal's **usage log**, `usage/week.jsonl`, with its step, its company, its model and its usage. You check that the log's total matches the Console's. You set Cedar Ridge's lines apart, because Dave asked about Brightline. Then you divide. What Brightline's new invoices cost goes on top. The invoices that passed every gate and appeared in a posted 7:10 report go below. The result is the cost of each invoice handled right.

By step, the extraction is the largest line. It runs twice for every new invoice. Next you look at how much of its input was read from the cache. That part is its **cache share**. Anthropic reports that agent loops read a median 84% of their input from the cache, and says: "Below about 80%, look for something breaking the cache."[^anthropic-cost-and-intelligence]

**10:15.** You add two cache breakpoints. A **cache breakpoint** is a marker that tells the API where to save the start of a request ([29.7](caching-by-how-often-content-changes.md)). One goes after the tools and the rules. One goes at the end of each invoice's first request, so the second request reads it. A rerun of Monday, May 3's invoices raises the cache share. A cache changes the price, not the answer, so you do not run the suite.

**10:45.** First you try a lower effort on the model you have, because effort changes less than a model does ([29.3](tiers.md)). You run the 16 extraction cases on Sonnet 5.5 at medium effort, three trials each. You keep the lowest effort whose lowest trial matches high's. A smaller model is tried only when lowering effort stops saving.

**11:00.** You send the 16 extraction cases as one **batch**, which means many requests sent together and answered later, at half the price ([24.6](../evaluating-ai-workers/metrics-you-can-defend.md)). Each case runs three times on Sonnet 5.5 and three times on Haiku 5.5, a smaller and cheaper model. Both models use the same output limit and the same **effort**, which means how hard the model works ([29.2](thinking-and-effort.md)). Each request has its own id, such as `INV-8340-haiku-t2`. An extraction is two requests, so the batch goes in two rounds. When round 1 ends, round 2 goes. Until a round has ended, the result waits.

**2:30 p.m.** The batch is back, and the keep rule decides whether the smaller model stays. Whatever it decides, it is kept only for now. Next week's gate counts confirm it. You send Dave the headline and two lines, one for the cache and one for the model. A third line, for moving the extraction to an overnight batch, follows on Wednesday. It comes after the batch's first run at 1:00 a.m., with its measured delay.

**You have met every piece of this before.** In [12.5](../agentic-coding/context-sessions-effort.md) you chose a model and an effort for your coding agent. You also read that Chapter 29 shows how to measure what each choice costs. The new thing is the unit. The bill counts calls. Brightline is paid for results.

So before you change anything, answer one question. **Last week's bill says what each call cost. What did one invoice handled right cost Brightline, and which change lowers that without lowering what Ana's suite measures?** Start with what a call is made of: tokens ([29.1](tokens-and-why-output-varies.md)).

<!-- EDITOR: the chapter's question, printed in bold above, is the agent's recommendation of 30 November 2026 and is not yet confirmed by the editor (spec, raised point 1). The other four candidates are in .work/chapter-spec/model-selection-and-cost/questions.md. If he chooses another, each section's job changes with it. -->

## For managers

An AI Worker's bill counts tokens, the small pieces of text a model reads and writes. Your company is not paid for tokens. It is paid for work done right. This chapter shows a builder how to price that work, and how to lower the price without lowering the quality.

The unit is one **accepted result**: a piece of work that passed every check that code makes on it. What a step spends, divided by its accepted results, is its **cost per accepted result**. For Brightline, the invented company in this book, that is one invoice the worker read correctly. Dave Kowalski, its controller, gets one headline each week. It is the week's spend on Brightline's own invoices, divided by the new invoices that passed every check and appeared in the morning report. A cheaper call that sends one more invoice to a person is not a saving. It moves the work to Ana Morales, the accounts payable (AP) analyst who reads the morning report.

The builder works in four steps:

1. **Group the week by step.** Each part of the worker that calls a model is a step: reading invoices, the morning triage, the month-end review. The bill groups cost by model. The builder groups it by step, and finds the step that costs most.
2. **Match each cost to its lever.** A lever is a change that can lower one kind of cost. Repeated text points to caching. Work nobody waits for points to a batch, which costs half as much and answers later. Long answers point to less effort, or a smaller model. Then name the **binding constraint**, which is the one requirement a cheaper choice must still meet. For reading invoices it is quality. For a batch it is the 7:10 deadline.
3. **Change one thing, and check it the way it can fail.** A change to the price or the timing cannot change the answers. So it is checked by what it can break: the cache, or the deadline. A change to the answers, such as a smaller model, runs the worker's test cases three times, on the old and the new model together.
4. **Report each change against the same baseline.** Each change gets one line, with its saving in dollars a week. Savings are never added up, because two changes together are measured as a run of their own.

Ask your builder five questions:

- What did one accepted result cost last week, and in which step?
- What is the one requirement the cheaper choice must still meet?
- How was the change checked: by the test cases, by the cache, or by the deadline?
- What is the saving in dollars a week, and was it measured alone?
- Which model is pinned, and how do we go back to the old one?

The price of this method is test runs. A change to the answers costs a run of the test cases before anyone knows whether it is a saving. And one part of the worker, Ana's questions in the portal, has no check by code while it runs. It is judged on its test cases alone, and the chapter says so.

## Why it matters

Brightline runs its own invoices and Cedar Ridge's for a fixed monthly fee, so every run is Brightline's cost, not Cedar Ridge's (23.5). That includes every run that failed and every run that ran twice. A call can get cheaper while the work gets more expensive. A cheaper call that sends more invoices to `needs_review` moves the work to Ana's morning. A smaller model that does worse on Chapter 24's suite is no saving that Brightline can use. A batch that finishes after 7:10 misses the morning triage.

Anthropic's own advice for comparing models has the same shape: "Compare on cost per solved task, not per token."[^anthropic-cost-and-intelligence]

The chapter never puts a price on Ana's time, because no source gives one. It counts the results stopped at a gate instead, in every report, beside the dollars.

Figure 29.1 shows the week Dave asked about, by step.

<!-- FIGURE 29.1: "Last week, by step." A bar chart, one bar per model step of Brightline's AP worker for the week of May 3 to 9, 2027: the extraction, the morning triage, the month-end review, Ana's portal questions, and the suite runs. Each bar's height is the step's spend for the week in dollars. Under each bar, two figures: its accepted results (for the extraction, invoices that passed the three gates and appeared in a posted 7:10 report; for the triage, runs that passed 23.16's check by code; for the month-end review, the run that passed Lab 26's check) and its cost per accepted result. The portal-questions bar and the suite bar show "n/a" for accepted results and for cost per accepted result. Above the bars, the headline: "Brightline's own invoices: $[b] ÷ [a] accepted = $[b ÷ a] for each invoice handled right." Cedar Ridge's spend is a separate, lighter segment in each bar, labeled "Cedar Ridge, set apart". A note in the corner: "The bill shows calls. Dave asked about invoices." Which bar is tallest, and every number, come from the recorded week (OPEN: recorded run). Bars use one color and a pattern for Cedar Ridge's segment, so the figure reads without color. The alt text must give every step's spend, accepted results and cost per accepted result, say which steps show "n/a", give the headline and the note. -->

*Figure 29.1. Last week, by step. Each step has its own spend, its own accepted results and its own cost per accepted result. The suite and the portal questions have no accepted count.*

## How this chapter works

The chapter has ten concepts and one lab. Read the concepts in order.

Every price on a page is dated 30 November 2026 in its footnote. Prices change, so the book checks them each month, and the lab copies them on the day you run it ([F5](../agent-loop-by-hand/field-guide-agent-loop-by-hand.md#f5-prices-usage-and-caching)).[^anthropic-pricing] Where a concept uses a feature in beta, a test stage that can still change, it says so.

Two words are kept narrow. "Accepted" always means passed the step's own checks by code. "Saving" always means a lower cost per accepted result, measured, with the check it passed.

Five subjects belong to other chapters. Caching's basics are 21.12's, and 29.7 adds only where the breakpoints go. Errors by class, and falling back to another model, are 30.4's. Carrying a model change through three environments is 30.6's. Files and images are 30.3's. The cost of serving many companies is Chapter 43's.

<!-- EDITOR: Chapters 30 and 43 are not written yet. The pointers follow the spec's Boundaries. The other option: name only the subjects, without chapter numbers, until those chapters exist. -->

After this chapter you can:

- **Explain why the same request can pass one run and fail the next,** and why the same text counts as more tokens on another model.
- **Set effort and the output limit on purpose,** and check a change to either on the suite.
- **Choose a model for each step** by its cost per accepted result, and write down the constraint that decided it.
- **Plan a release** for a new model: pin it, test it, switch one step at a time, and keep a way back.
- **Read a week of usage by step,** find the **dominant cost**, which is the step that spent the most, and match it to its lever.
- **Place cache breakpoints** by how often each part of a request changes.
- **Move work to a batch** only where it still meets its deadline.
- **Write each saving** in dollars a week, with the check it passed.

## What you will build

**Who's who.** You are the builder. Dave Kowalski is Brightline's controller. He owns AP policy and reads the bill. Ana Morales is Brightline's AP analyst. She reads the 7:10 report each morning and labeled the golden set. Brightline Wholesale Supply is the invented wholesale distributor whose AP worker you have built since Chapter 16. Cedar Ridge Supply pays Brightline a fixed monthly fee to run its invoices too.

**Where you are.** You start from the AP worker at the end of Lab 28, at tag `ch28`. This chapter uses four of its model steps, all built before Chapter 28. The extraction reads each new invoice in two requests, before 7:10, behind three gates, on `claude-sonnet-5-5`. The morning triage runs at 7:10 as a hosted session, with a budget of $0.50. The month-end review runs on a budget of $1.00. Ana asks the worker questions in the portal. The suite holds 42 cases, and runs on each pull request. Nothing in the worker yet says what any of this costs for each invoice.

**What you build,** in Lab 29, from tag `ch28` to tag `ch29`:

1. **Price the week.** Tag each call with its step, and price the usage log at today's prices. Count the accepted results from the five 7:10 reports, and check the total against the Console's. Then find the dominant cost.
2. **The cache.** Place breakpoints on the extraction's requests, rerun one day, and measure the cache share and the saving.
3. **The batch.** Run 20 extractions in realtime and as two batch rounds, and match the results. Send an errored request to `needs_review`, and write the rule that runs at 6:45.
4. **A smaller tier.** Run the 16 extraction cases on Sonnet 5.5 and Haiku 5.5, three trials each, in one batch, and apply the keep rule.
5. **The release plan.** Write `docs/release-plan.md` for a new model id.

The lab's page is published once its runs are recorded.
6. **The port,** for practice. Price the same week on OpenAI and on an open model.

Every task runs from recorded files, so you need no API key. The report you send Dave is `docs/cost-report.md`. As in Chapters 17 to 27, coding agents write every file and run every command. You specify, check and approve.

<!-- EDITOR: Task 4 tests a smaller tier on the extraction, not on the triage. The plan's Lab 29 says "route triage to a smaller tier proved on the Chapter 24 suite", but at tag ch28 the suite has no triage cases, and the triage's model sits in its hosted agent definition (spec, raised point 2). The other option: Ana labels triage cases for the golden set (24.2), and the triage's tier is judged on them. -->

<!-- EDITOR: new story facts, proposed in the spec (appendix point 3) and not yet in specs/labs/part-2-facts.md: the usage log usage/week.jsonl with one line per model call, the week's model steps and how often each ran, the 1:00 a.m. batch and the 6:45 a.m. rule. The coordinator owns that file. -->

<!-- OPEN: how many sittings Lab 29 takes, and the lab page's anchor. "Lab 29" carries no link in this part until the lab is built. The task numbers named in 29.1 and 29.2 follow the spec's lab plan. Recording the lab's files is still to do: no Claude API key exists yet (spec, "The lab's tasks in full"). -->

## In this chapter

| Section | The question it answers |
| --- | --- |
| [29.1](tokens-and-why-output-varies.md) Tokens, context windows and why output varies | Why can the same request pass the gates one run and fail the next, and why does the same text count differently on another model? |
| [29.2](thinking-and-effort.md) Thinking and effort | When does more thinking pay, and how do you know? |
| [29.3](tiers.md) Tiers: quality, latency and cost | Which model gives one step the lowest cost per accepted result, without losing a case? |
| [29.4](the-binding-constraint.md) The binding constraint, and writing the justification | What one requirement decides each step's choice, and how do you write it down? |
| [29.5](release-planning.md) Release planning | When a new model comes out, how do you switch without a surprise, and go back if you must? |
| [29.6](reading-a-usage-report.md) Reading a usage report | Where did last week's money go, step by step? |
| [29.7](caching-by-how-often-content-changes.md) Caching by how often content changes | Where do the breakpoints go, by how often each part of a request changes? |
| [29.8](realtime-or-batch.md) Realtime or batch | Which work can wait for a batch and still be ready at 7:10? |
| [29.9](token-budgets-and-a-saving.md) Token budgets, and quantifying a saving | Which limit stops what, and how do you write a saving in dollars a week? |
| [29.10](how-todays-tools-realize-it.md) How today's tools realize it | How do Claude, OpenAI and an open model price the same week, and what do you measure the same way on each? |
| Lab 29 | Five tasks and a port, from tag `ch28` to tag `ch29`, each change checked the way it can fail |
| Check yourself | One open question for each concept, with an outline of its answer |

[^anthropic-cost-and-intelligence]: Optimizing for cost and intelligence, Anthropic, read November 30, 2026.
[^anthropic-pricing]: Pricing, Anthropic, read November 30, 2026.
