Why a list price per million tokens is not a unit price
A model-switch forecast usually looks like this: take last month's input and output token totals, multiply by the new model's rates per million tokens, compare to the current bill. The arithmetic is fine. The inputs are not, because last month's totals were produced by the current model's tokenizer, and the new model will cut the same text into a different number of tokens.
A token is a unit of a specific tokenizer. INFRO's earlier analysis of billing units cites Anthropic's pricing page for the statement that Claude 4.7 and later models use a newer tokenizer that produces approximately 30% more tokens for the same text, with the exact increase depending on content and workload shape.1 Two models with identical published input rates are therefore not the same price per unit of your text if one of them cuts your text into more units. That article makes the point; this one supplies the measurement procedure it leaves open.
The goal is one number per workload: a correction factor you multiply into the naive list-price forecast. It is built from three measured quantities per slice of traffic: the input-token ratio, the output-token ratio, and the share of cost each side carries at the new rates.
What to measure, and what not to fold in
The bill ratio between two models is a product of several separate effects. Mixing them makes the result impossible to debug later.
| Factor | What moves it | Measured by |
|---|---|---|
| Rate ratio | New model's list rates against current effective rates | Rate tables, your contract |
| Tokenizer factor | Same text, different token counts | This method |
| Behavior factor | Different answer length, reasoning or thinking volume | A replay of real prompts on the candidate |
| Cache factor | Hit rate, write premium, read multiplier | Provider-reported cache fields |
| Threshold factor | Rates that change with prompt length | Distribution of counted prompt sizes |
Keep the tokenizer factor pure. It answers one question: if the candidate produced exactly the text the current model produces, and read exactly the payloads you send today, how many tokens would each side bill? Anything about the candidate writing longer or shorter answers belongs in the behavior factor, which needs real generations and is covered in reasoning tokens and their cost.
Step 1: build a corpus that carries the whole payload
Sample real requests and keep the full payload, not just the user text: system prompt, tool and schema definitions, message history, and any documents. Counting only the text a user typed underestimates input, because system prompts, tools and message framing are billable input too.2
Then partition the sample into slices that tokenize differently. A workable starting set:
- Short conversational turns with a large shared system prompt.
- Retrieval prompts with long prose context.
- Code in the languages you actually use.
- Structured data: JSON, tables, logs.
- Tool-heavy requests with many function schemas.
- Non-English text, per language that matters to your volume.
Store the observed output of the current model beside each prompt. You need it in step 3. Aim for slices large enough that the ratio stops changing when you add samples, and weight each slice by its share of last month's token volume when you aggregate.
Redact before you copy. The corpus is production prompts, so it falls under your payload logging policy, not under a convenience script.
Step 2: count each payload with each target's own method
A local tokenizer counts plain text and misses roles, tools, images and files, so use each provider's counting endpoint on the exact payload you would send. INFRO's counting guide lists OpenAI's POST /v1/responses/input_tokens, Anthropic's POST /v1/messages/count_tokens and Gemini's countTokens.2 Anthropic's endpoint accepts the same structured inputs as message creation, including system prompts, tools, images and PDFs, and returns the total input tokens.3 Anthropic describes counting as a way to manage costs and make model routing decisions, which is the use here.3
Three cautions from the same sources:
- Anthropic says the real input count may differ by a small amount from the estimate.2 Treat ratios as accurate to a few percent, not to the token.
- Anthropic's endpoint refuses some inputs: server tools, the MCP connector, and media given by URL or file id.2 Slice those requests out and measure them from real usage instead.
- Counts belong to a model. Count against the exact model id you plan to use, and recount when a new generation appears.2
from openai import OpenAI
import anthropic
from google import genai
oa, an, gg = OpenAI(), anthropic.Anthropic(), genai.Client()
def count_openai(model, payload):
r = oa.responses.input_tokens.count(
model=model,
instructions=payload["system"],
input=payload["messages"],
tools=payload.get("tools_openai", []),
)
return r.input_tokens
def count_claude(model, payload):
r = an.messages.count_tokens(
model=model,
system=payload["system"],
messages=payload["messages"],
tools=payload.get("tools_claude", []),
)
return r.input_tokens
def count_gemini(model, payload):
r = gg.models.count_tokens(model=model, contents=payload["gemini_contents"])
return r.total_tokens
COUNTERS = {"current": count_claude, "candidate_a": count_openai, "candidate_b": count_gemini}
# one row per payload: slice, tokens per target; ratios are computed per sliceEach provider wants its own request shape, so the corpus needs one adapter per target that maps the stored payload to that shape. Keep the adapters in version control; a wrong adapter silently drops tools or history and biases the ratio low.
Step 3: count the outputs the same way
No endpoint counts generated output, because generation has not happened yet.2 But the text of an output you already hold can be counted. Send the stored output of the current model to each target's counting method as a single message, then subtract the count of a one-character message to cancel the fixed framing. The remainder is the output-side token count for that text under that tokenizer, to within a token or two.
This gives an output ratio for identical text. It is a different number from the input ratio, because outputs are mostly prose or the structured format you asked for, while inputs carry system prompts and tool schemas. Do not assume one ratio covers both: the sections below keep them separate, and the weighting step depends on it.
If a candidate emits reasoning or thinking tokens, the stored text will not include them. That volume is the behavior factor, not part of this ratio.
Step 4: compute ratios and the correction factor
For each slice, compute
r_in = tokens_in(candidate) / tokens_in(current)over the slice's payloads.r_out = tokens_out(candidate) / tokens_out(current)over the slice's stored outputs.
Aggregate by volume weight. Then price both ways with the candidate's rates:
- Naive cost
N = T_in × P_in + T_out × P_out, using last month's token totalsTfrom the current model. - Corrected cost
C = T_in × r_in × P_in + T_out × r_out × P_out. - Correction factor
CF = C / N = a × r_in + (1 − a) × r_out, wherea = T_in × P_in / Nis the input share of the naive cost at the new rates.
The weight a is why the factor depends on the rate card as well as on the tokenizer. A model with expensive output makes r_out count for more; one with a cheap output rate makes r_in dominate.
Report the factor per slice as well as in total. If tool-heavy requests carry a ratio of 1.4 and short chats 1.1, finance can see which product feature absorbs the movement, and the engineers can see where trimming schemas pays.
Step 5: check for threshold crossings
A token-count ratio above 1 does more than scale cost linearly. Some rates are set by prompt length, and a larger count can push a request across the line. Per Anthropic's rate table, Claude Haiku 5.5 is priced at $0.10 per million input tokens for prompts up to 100K tokens and $0.50 above that, with output at $0.50 and $2.50 respectively.4 INFRO's earlier article lists similar thresholds at OpenAI above 272K input tokens and Gemini 3.1 Pro above 200K, and notes a request over the line is re-priced as a whole.2
So take the histogram of counted prompt sizes per slice, apply r_in, and count the share of requests that now land above a threshold on the candidate. A request that was 90K tokens on the old tokenizer and is 117K tokens on the new one changes price tier, not just count.
Step 6: normalize caching before you compare
If your corpus replays real usage, make sure the cache fields are normalized per provider before computing totals. Anthropic reports cache reads and writes outside input_tokens, so the total is the sum of three fields; OpenAI reports cached tokens as a subset inside the input total.1 Add them wrongly and you double-count or drop the cached prefix, which changes T_in and every ratio built on it.
The counting endpoints give an uncached count. Apply the cache factor separately: your observed hit rate, the target's read multiplier, and its write premium. Anthropic's rate table shows how much these differ even inside one family: Sonnet 5.5 lists cache reads at $0.10 and writes at $2.50 per million against $2 input, while Opus 5.5 lists $0.20 and $5 against $4 input.4 A cached prefix that grows 28% under a new tokenizer grows 28% in its write cost as well.
Step 7: replace the forecast with a measured factor
The pre-switch factor is an estimate from a sample. After a canary on real traffic, compute the same ratios from provider-reported usage: tokens billed per request for the candidate, against the corpus's current-model counts for the same prompts. If the two factors differ by more than the sample's noise, the corpus is unrepresentative, and the usual cause is a slice you under-sampled.
INFRO records each request's token or unit counts and an estimated provider cost, as your provider reports it, and estimates what the provider will bill.5 That per-request record, queryable by model and project, is the data for the post-canary factor; the estimate for a request before it is sent is documented under billing (opens in a new tab).6 If your contract carries negotiated rates, enter them so the estimate uses them ahead of list rates, and reconcile against the provider's own cost reports so a persistent gap is attributed rather than guessed at. The tokenizer factor is a count-side correction; it does not replace a rate-side one. INFRO takes 0% of model spend, so none of this changes what your provider invoices.6
A checklist for the review:
- Corpus carries full payloads, with PII handled per policy.
- Slices cover prose, code, structured data, tools and each major language.
- Each target counted with its own method on its own request shape.
- Input and output ratios computed separately, per slice and volume-weighted.
- Correction factor computed with the candidate's rates, not the current ones.
- Threshold crossings estimated from the prompt-size histogram.
- Token-denominated limits converted.
- Behavior and cache factors reported as their own lines.
- A date set to recompute the factor from real usage after the canary.
For the broader question of what else a per-token estimate cannot produce, see tokens are not the unit you are billed in; for counting mechanics, see how to count tokens before you call the API.
