Tokens Are Money: Model, Effort, Limits and Caching
Why This Matters
Triage runs on every failed pipeline. A few cents per call adds up quickly, and saving money with a setting that misclassifies a product bug costs far more. You need to know where the cost comes from and which knobs change it.
What one request costs
Every response tells you what it cost. Here, one free-text triage: 257 tokens in, 1,074 out, about $0.02 and 11 seconds.
Multiply that by 40 failures a night, 250 nights a year, and a design choice becomes a budget line. Output tokens are usually priced higher than input tokens, so a short structured verdict (lesson 9) is cheaper than a long report.
Log the usage per run:
console.log(`${failure.id}: ${message.usage.input_tokens} in, ${message.usage.output_tokens} out`);
The knobs
Model, fallback model, thinking, speed and max tokens are all part of the request, and every one of them changes cost or speed.
| Knob | Effect | For TestPilot |
|---|---|---|
| Model | Larger models are better at hard cases and cost more | Try a smaller model on the golden set (module 3); keep it if quality holds |
| Effort / thinking | More reasoning before answering: better on hard cases, more tokens | Low for clear-cut failures, higher for “unknown” re-runs |
max_tokens | Hard limit on output length | Enough for a verdict, not for an essay |
| Speed tier | Faster responses at a different price | Rarely needed for a nightly job |
Check current model names and prices on Anthropic’s pricing page before you decide.
A cut-off answer
If stop_reason is max_tokens, the answer was cut off. For a structured verdict that means invalid JSON. With messages.parse(), you never get to check it: the SDK fails to parse the truncated JSON and throws first (“Failed to parse structured output”, the error lesson 18’s eval caught). So either catch that error, or call create() and check before you parse:
const message = await client.messages.create({ ...request });
if (message.stop_reason === "max_tokens") {
throw new Error(`Triage for ${result.id} was cut off; raise max_tokens or shorten the input`);
}
Prompt caching
TestPilot’s system prompt and category definitions are identical on every call. With prompt caching you mark that part of the request, and later requests that start with the same content read it from the cache at a fraction of the input price.
system: [
{ type: "text", text: SYSTEM_PROMPT, cache_control: { type: "ephemeral" } },
],
Caching works on the stable start of the request, so put unchanging content first and per-failure evidence last. Caches expire after a short time (five minutes by default), which suits a nightly run that sends 40 similar requests in a few minutes, with one catch: a cache entry only exists once the first response has started. Fire all 40 in parallel and they all write the cache instead of reading it. Send the first request alone, then the rest. Writing costs a little more than normal input (1.25×), reading far less (0.1×, or 0.05× on Opus 5.5 and Sonnet 5.5). Check the documentation for the minimum cacheable length and current cache lifetimes.
After a few runs, the usage page shows tokens in and out per model and per API key.
That page after one day of building this course: the triage runs, the eval with --repeat 3, and the triage team on both runtimes. Notice the ratio: far more tokens go in than come out. Evidence, prompts and tool definitions are sent on every call; a verdict is short. That is why caching the stable start of a request (below) pays off, and why trimming evidence matters more than shortening answers.
Once you add cache_control, caching analytics shows how much you are saving.
Exercise
- Log usage for a full
npm run triageand calculate the cost of one night. - Run the same fixture with a smaller model via
TESTPILOT_MODEL. Did any verdict change? - Add
cache_controlto the system prompt and checkcache_read_input_tokensin the usage of the second and later requests. - Write down a default model and setting for TestPilot, with one sentence on why.
Show suggested answers
- Cost of one night: add up
input_tokensandoutput_tokensfrom every response, multiply each by the price per million tokens on the current pricing page, and multiply by the number of failures in a typical night. Output tokens cost several times more than input tokens, so a short JSON verdict keeps the bill down. - Smaller model: the clear cases (
t-002,t-005) normally keep their verdict. The borderline ones (t-004,t-006) are where a smaller model differs. You cannot judge that from one run; that is what the golden set in module 3 is for. - Caching: you will probably see
cache_read_input_tokens: 0, even withcache_controlset. TestPilot’s system prompt is only a few hundred tokens, below the model’s minimum cacheable length (512 tokens on current models such as Sonnet 5.5, more on some older ones). Caching starts paying off once the stable part grows, for example with few-shot examples (lesson 20) or tool definitions (module 4). - A default: for example, “Sonnet at default settings: the verdicts on our golden set are as good as the largest model’s, at a fraction of the cost; escalate to a larger model only for failures that come back
unknown.”



