Most platform teams that run more than one model vendor end up with the same architecture: a gateway in the middle. It might be LiteLLM, an Envoy filter, or a few hundred lines of FastAPI that someone wrote during an incident. It authenticates callers, routes requests, retries on 429s, and writes a log line with a token count and a cost. That cost column is where the trouble starts. The gateway treats “tokens” as one unit. The three big vendors don’t. Each of them puts a different quantity behind the same field name, and a cost function that is correct for one of them is wrong for the other two.
This is not a rounding problem. Claude Sonnet 5 and GPT-6 Sol currently list the same headline rates: $2.00 per million input tokens, $0.20 per million cached reads, $2.50 per million short-lived cache writes (a 5-minute write at Anthropic, a 30-minute write at OpenAI) and $10.00 per million output tokens. Send each of them an identical long agent turn (150,000 tokens of context, 140,000 of them read from cache, 8,000 newly written to cache, which leaves 2,000 uncached, and 3,000 tokens out) and both bill $0.082. The arithmetic is 2,000 uncached input tokens at $2.00 per million ($0.004), 140,000 cache reads at $0.20 per million ($0.028), 8,000 short-lived cache writes at $2.50 per million ($0.020) and 3,000 output tokens at $10.00 per million ($0.030). Those four lines sum to $0.082, and every later worked example in this article uses that same figure. Price the Anthropic response with an OpenAI-shaped function (subtracting cache reads and writes from an input field that is already exclusive of them) and you get a negative $0.214. Price the OpenAI response with an Anthropic-shaped function (treating the inclusive 150,000-token input as uncached) and you get $0.378, which is 4.6 times the real $0.082 and looks perfectly plausible on a dashboard. Nobody questions a positive number until finance reconciles the invoice.


This article covers the field-level differences that matter for metering, then gives you a normalization layer, a rates file, a log schema and a reconciliation job you can drop into a gateway. Every vendor behaviour described here comes from the vendors’ own API references and pricing pages, listed in the References section at the end. Rates are list prices for the standard tier on each vendor’s first-party API, checked on November 18, 2026.
One field name, three different numbers
The core issue is the input field. Here is what each API reports:
| API | Input field | Includes cache reads? | Includes cache writes? | Output field | Includes reasoning? |
|---|---|---|---|---|---|
| Anthropic Messages | input_tokens | No | No | output_tokens | Yes |
| OpenAI Responses | input_tokens | Yes | Yes | output_tokens | Yes |
| OpenAI Chat Completions | prompt_tokens | Yes | Yes | completion_tokens | Yes |
| Google Interactions | total_input_tokens | Yes | n/a | total_output_tokens | No |
| Google generateContent | promptTokenCount | Yes | n/a | candidatesTokenCount | No |
Anthropic’s Messages API reference defines total input as the sum of input_tokens, cache_creation_input_tokens and cache_read_input_tokens, so its input_tokens is only the uncached remainder. Cache writes are split by lifetime in usage.cache_creation.ephemeral_5m_input_tokens and ephemeral_1h_input_tokens. OpenAI’s prompt caching guide does the opposite operation: ordinary input is input_tokens − cached_tokens − cache_write_tokens, with the reads and writes found in usage.input_tokens_details (Responses) or usage.prompt_tokens_details (Chat Completions), and the Responses API further splits writes into cache_write_tokens_details.ttl_30m_tokens and ttl_12h_tokens. Google’s prompt count includes cached content, reported in total_cached_tokens (cachedContentTokenCount in generateContent), and because the Interactions API supports only implicit caching, there is no separate write charge to track.
So the same turn arrives in two shapes. Anthropic says input_tokens: 2000. OpenAI says input_tokens: 150000. Both are correct. A gateway that maps both to a column called prompt_tokens and multiplies by the input rate has already broken.
Reasoning tokens: inside the output at two vendors, outside at the third
All three vendors bill reasoning at the output rate. They disagree on where they count it.
- Anthropic:
output_tokensis the inclusive, authoritative total used for billing.output_tokens_details.thinking_tokensis a read-only breakdown for observability. - OpenAI: reasoning is reported in
output_tokens_details.reasoning_tokens(completion_tokens_details.reasoning_tokensin Chat Completions), and it is already insideoutput_tokens. - Google:
total_output_tokens(orcandidatesTokenCount) is only the visible answer. Thoughts sit intotal_thought_tokens(orthoughtsTokenCount), and Google’s thinking guide says response pricing is the sum of output and thinking tokens. The reference example makes it visible: 7 input, 23 output and 49 thought tokens add up tototal_tokens: 79.
That gives you two opposite bugs. Take the same turn on Gemini 3.8 Flash ($0.75 input, $0.075 cached, $3.75 output), where 2,400 of the 3,000 output tokens were thinking. The correct bill is $0.02925. A function that treats the visible output field as the whole output bills $0.02025, which is 30.8% short. Go the other way on GPT-6 Sol and add reasoning_tokens on top of output_tokens, and you bill 5,400 output tokens instead of 3,000: $0.106 instead of $0.082, 29.3% over.
The rule for your normalizer: price the inclusive output field where one exists, and add thoughts only where the vendor says they are separate. Google also reports tool-use prompt tokens in their own field (total_tool_use_tokens, or toolUsePromptTokenCount), so add those to input rather than dropping them.
When the top-level usage is only part of the request
Anthropic has two features that make the top-level usage object describe less than the whole request.
Compaction. When a long conversation crosses a token threshold, the API runs an extra sampling pass that summarizes the history. Anthropic’s compaction docs say the top-level input_tokens and output_tokens do not include compaction iteration usage; you have to sum the usage.iterations array. In the documentation’s own example, the top level shows 23,000 input and 1,000 output tokens, while a compaction entry records 180,000 in and 3,500 out. On Sonnet 5 that is $0.056 at the top level against $0.451 for the request. A dashboard reading top-level fields sees 12.4% of the cost, and it sees the cost fall at the moment it actually rose.
Server-side fallback. With fallbacks configured, a request declined by one model can be answered by another inside the same call. The top-level counts describe only the attempt that produced the message. Each attempt is listed in usage.iterations with its own model (the declining model as a message entry, the serving model as a fallback_message entry), and each is billed at that model’s rates. Anthropic’s docs are explicit that tokens from different models are never summed into one field. Sticky routing then sends later turns of that conversation straight to the fallback model for approximately an hour, and the only signs are the fallback_message entry and the top-level model field. If your gateway prices the model from the incoming request rather than the response, it is wrong on all of those turns.
Gateway rule: price the model the response names, and if iterations exists, price each entry at its own model’s rates instead of reading the top level.
The multiplier is often not in the token counts
Token counts are only half of a price. The other half is a multiplier that usually lives somewhere else:
| Modifier | Effect | Where to read it |
|---|---|---|
| OpenAI Flex | 0.5x | service_tier: "flex" in the response |
| OpenAI Fast (formerly Priority) | 2x on GPT-6 and GPT-5.6 families | service_tier in the response ("priority" for both fast and priority requests on GPT-5.6 and earlier) |
| OpenAI long context | 2x input, cached input and cache writes; 1.5x output; whole request | input over 272K tokens on GPT-6 Sol |
| OpenAI regional processing (data residency) | 1.1x on models released on or after March 5, 2026 | not in the response; known from the endpoint you routed to |
| Anthropic Batch | 0.5x | usage.service_tier: "batch" |
| Anthropic fast mode | 2x on the models that offer it, such as Opus 5.5 and Opus 5 | usage.speed: "fast" |
| Anthropic US-only inference | 1.1x on every token category (input, output, cache writes, cache reads), Claude 4.6 and later | usage.inference_geo: "us" |
| Google Flex / Priority | 0.5x / 1.8x on Gemini 3.8 Flash | x-gemini-service-tier response header |
Anthropic’s multipliers stack. US-only inference applies on top of the Batch discount, prompt caching multipliers and fast mode, so a batch request pinned to the US costs 0.5 × 1.1 = 0.55x of standard. It applies on the Claude API, Claude Platform on AWS and Claude Models on Google Cloud (Anthropic managed). Earlier models such as Sonnet 4.5 and Haiku 4.5 reject the inference_geo parameter with a 400 error, and Bedrock and Google-managed Vertex endpoints have their own regional pricing. The geography can also be set as a workspace default (default_inference_geo), so a request that never mentions it can still be billed at 1.1x. That is why the multiplier must come from usage.inference_geo in the response, not from your request body.
Three of these catch gateways out regularly. First, OpenAI can downgrade Fast requests to standard speed when traffic ramps too quickly, and the response then says service_tier: "default" and is billed at standard rates. Google does the same with Priority under congestion and reports it in the x-gemini-service-tier header. If you price from the tier your client asked for, you over-bill those requests. Read the tier from the response.
Second, the GPT-6 Sol long-context rule is a cliff, not a slope. A call with 300,000 input tokens (280,000 cached) and 2,000 output costs $0.222. A function that only knows short-context rates says $0.116, roughly half. OpenAI’s input count includes the cached part, so a good cache hit rate does not keep you under the 272K line.
Third, the US-only multiplier is easy to miss because nothing in the token counts changes. The shared Sonnet 5 turn from the introduction costs $0.082 globally and $0.0902 with inference_geo: "us". Across a month of agent traffic that 10% is real money, and it is the kind of gap that reconciliation flags without explaining.
Streaming changes where the numbers arrive
On Anthropic streams, message_start carries a usage block and each message_delta carries cumulative counts. Price the last one. Adding them double-counts, and the counts in message_start are not final.
On OpenAI Chat Completions, streamed responses carry no usage unless you send stream_options: {"include_usage": true}. The totals then arrive in one extra chunk before [DONE]. The API reference warns that if the stream is interrupted, that chunk may never arrive, but the tokens generated so far are still billed. Your gateway should record interrupted streams with a flag so the reconciliation job can explain the gap later.
Step 1: normalize usage at the gateway
The fix is to stop passing raw vendor fields downstream. Convert every response into one canonical shape at the edge, with fields whose meaning never changes: uncached input, cache reads, cache writes by lifetime, output that always includes reasoning, and the tier, speed and geography the request was actually served with. Because a single Anthropic response can contain attempts by different models, the normalizer returns a list.
from dataclasses import dataclass
@dataclass
class Usage:
vendor: str
model_served: str
uncached_in: int = 0 # fresh input, billed at the base input rate
cache_read: int = 0
cache_write_short: int = 0 # Anthropic 5-minute / OpenAI 30-minute writes
cache_write_long: int = 0 # Anthropic 1-hour / OpenAI 12-hour writes
output: int = 0 # ALWAYS includes reasoning after normalization
reasoning: int = 0 # observability only, never priced on top
tier: str = "standard" # batch / flex / priority / fast, as SERVED
speed: str = "standard" # Anthropic fast mode
geo: str = "global" # Anthropic inference_geo, as SERVED
raw_input_total: int = 0 # what the vendor counts for long-context thresholds
kind: str = "message" # Anthropic iteration type
def from_anthropic(resp: dict) -> list[Usage]:
"""One Usage per billed attempt. Fallback attempts can be different models."""
u = resp["usage"]
rows = u.get("iterations") or [u] # compaction + fallback live here
tier = u.get("service_tier") or "standard" # "standard" | "priority" | "batch"
speed = u.get("speed") or "standard" # "standard" | "fast"
geo = u.get("inference_geo") or "global" # "us" => 1.1x on Claude 4.6+
out = []
for it in rows:
cc = it.get("cache_creation") or {}
total_write = it.get("cache_creation_input_tokens") or 0
w1h = cc.get("ephemeral_1h_input_tokens", 0)
w5m = cc.get("ephemeral_5m_input_tokens", total_write - w1h)
x = Usage("anthropic", it.get("model") or resp["model"],
uncached_in=it.get("input_tokens") or 0, # excludes cache
cache_read=it.get("cache_read_input_tokens") or 0,
cache_write_short=w5m, cache_write_long=w1h,
output=it.get("output_tokens") or 0, # includes thinking
reasoning=(it.get("output_tokens_details") or {}).get("thinking_tokens", 0),
tier=tier, speed=speed, geo=geo,
kind=it.get("type", "message"))
x.raw_input_total = x.uncached_in + x.cache_read + w5m + w1h
out.append(x)
return out
def from_openai(resp: dict) -> list[Usage]:
"""Responses API (input_tokens) or Chat Completions (prompt_tokens)."""
u = resp["usage"]
inp = u.get("input_tokens", u.get("prompt_tokens", 0))
d = u.get("input_tokens_details") or u.get("prompt_tokens_details") or {}
od = u.get("output_tokens_details") or u.get("completion_tokens_details") or {}
read, write = d.get("cached_tokens", 0), d.get("cache_write_tokens", 0)
wd = d.get("cache_write_tokens_details") or {}
w12h = wd.get("ttl_12h_tokens", 0)
w30m = wd.get("ttl_30m_tokens", write - w12h)
return [Usage("openai", resp["model"],
uncached_in=inp - read - write, # input INCLUDES cache
cache_read=read, cache_write_short=w30m, cache_write_long=w12h,
output=u.get("output_tokens", u.get("completion_tokens", 0)),
reasoning=od.get("reasoning_tokens", 0),
tier=resp.get("service_tier") or "default", # the tier that RAN
raw_input_total=inp)]
def from_gemini(resp: dict, tier_header: str | None = None) -> list[Usage]:
"""Interactions API. Pass the x-gemini-service-tier response header."""
u = resp["usage"]
inp, read = u.get("total_input_tokens", 0), u.get("total_cached_tokens", 0)
tool = u.get("total_tool_use_tokens", 0) # tool-use prompts
thoughts = u.get("total_thought_tokens", 0)
return [Usage("google", resp["model"],
uncached_in=inp - read + tool, cache_read=read,
output=u.get("total_output_tokens", 0) + thoughts, # thoughts are OUTSIDE
reasoning=thoughts,
tier=tier_header or resp.get("service_tier") or "standard",
raw_input_total=inp)]
Three design choices are deliberate. reasoning is stored but never priced, because at two vendors it is already inside output. Each Anthropic iteration keeps its own model, so a fallback attempt is priced at the rates of the model that ran it. And tier, speed and geo are read from the response (or, for Google’s tier, from the x-gemini-service-tier header), because all three can differ from what the client asked for.
Step 2: keep rates in a dated config file
Hard-coded rates are the other common failure. Prices change, and some changes are published months in advance. Gemini 3.8 Flash, for example, is listed at $0.75 / $3.75 through December 31, 2026, and at $1.50 / $7.50 from January 1, 2027. Rates also move in the other direction: Anthropic’s pricing page notes that Sonnet 5’s $2 / $10 launch pricing became the standard price and the scheduled September 1, 2026 increase did not happen. A rate table without an end date will be wrong on a known morning.
# $ per 1M tokens, standard tier. Copy from the vendor pricing page; date every row.
claude-sonnet-5:
input: 2.00
cache_read: 0.20
cache_write_short: 2.50 # 5-minute write
cache_write_long: 4.00 # 1-hour write
output: 10.00
tiers: {batch: 0.5}
fast_mult: 2.0 # usage.speed "fast"; 2x on models that offer it
us_geo_mult: 1.1 # inference_geo "us", Claude 4.6 and later
checked: 2026-11-18
valid_until: 2026-12-31 # re-verify, don't extend blindly
gpt-6-sol:
input: 2.00
cache_read: 0.20
cache_write_short: 2.50 # 30-minute write
cache_write_long: 5.00 # 12-hour write
output: 10.00
tiers: {flex: 0.5, batch: 0.5, priority: 2.0, fast: 2.0}
long_context_over: 272000 # whole request reprices above this
long_in_mult: 2.0 # input, cached input and cache writes
long_out_mult: 1.5
regional_processing: # 1.1x data-residency endpoints
as_of: 2026-03-05 # models released on or after this date
multiplier: 1.1
checked: 2026-11-18
valid_until: 2026-12-31
gemini-3.8-flash:
input: 0.75
cache_read: 0.075
output: 3.75
tiers: {flex: 0.5, batch: 0.5, priority: 1.8}
checked: 2026-11-18
valid_until: 2026-12-31 # Google's published change: $1.50 / $7.50 from 2027-01-01
The pricing function refuses to price anything past valid_until, and it also refuses a tier, speed or geography it has no rate for. OpenAI’s regional-processing multiplier is read from a dated regional_processing block in the same file, not hard-coded in Python. A loud failure in the gateway log is cheaper than a quiet month of wrong numbers.
import yaml
from datetime import date
from meter import Usage
RATES = yaml.safe_load(open("rates.yaml"))
DEFAULT_TIERS = ("standard", "default", "auto")
def price(u: Usage, on: date, regional_endpoint: bool = False) -> float:
r = RATES[u.model_served]
if on > r["valid_until"]:
raise ValueError(f"{u.model_served}: rates expired {r['valid_until']}")
k_in = k_out = 1.0
if "long_context_over" in r and u.raw_input_total > r["long_context_over"]:
k_in, k_out = r["long_in_mult"], r["long_out_mult"]
usd = (k_in * (u.uncached_in * r["input"]
+ u.cache_read * r["cache_read"]
+ u.cache_write_short * r.get("cache_write_short", 0)
+ u.cache_write_long * r.get("cache_write_long", 0))
+ k_out * u.output * r["output"]) / 1_000_000
# Tier multiplier: from the tier the response says RAN, never the one requested.
if u.tier not in DEFAULT_TIERS:
if u.tier not in r.get("tiers", {}):
raise ValueError(f"{u.model_served}: no rate for tier {u.tier!r}")
usd *= r["tiers"][u.tier]
# Anthropic fast mode (usage.speed): 2x on the models that offer it.
if u.speed == "fast":
if "fast_mult" not in r:
raise ValueError(f"{u.model_served}: no fast-mode rate")
usd *= r["fast_mult"]
# Anthropic US-only inference (usage.inference_geo): 1.1x on every token category.
if u.geo == "us":
if "us_geo_mult" not in r:
raise ValueError(f"{u.model_served}: inference_geo 'us' not priced")
usd *= r["us_geo_mult"]
# OpenAI regional-processing endpoints: not in the response, so pass it from routing.
# The multiplier and as-of date come from the dated rates file, not from a hard-coded default.
if regional_endpoint:
rp = r.get("regional_processing")
if not rp or "multiplier" not in rp or "as_of" not in rp:
raise ValueError(f"{u.model_served}: no dated regional-processing rate")
usd *= rp["multiplier"]
return usd
def price_response(rows: list[Usage], on: date, **kw) -> float:
return sum(price(u, on, **kw) for u in rows)
Before shipping, test it against known cases. The examples in this article make good fixtures, and all of them pass with the code above: the shared turn prices at $0.082 on both Sonnet 5 and GPT-6 Sol, $0.0902 on Sonnet 5 with inference_geo: "us" and $0.0451 when that request also ran on the Batch tier, the Gemini turn at $0.02925, the compaction example at $0.451, the long-context GPT-6 Sol call at $0.222, and the shared turn in Chat Completions shape on OpenAI Flex at $0.041.
from datetime import date
from meter import from_anthropic, from_gemini
from pricing import price_response
turn = {"model": "claude-sonnet-5", "usage": {
"input_tokens": 2000, "cache_read_input_tokens": 140000,
"cache_creation_input_tokens": 8000,
"cache_creation": {"ephemeral_5m_input_tokens": 8000, "ephemeral_1h_input_tokens": 0},
"output_tokens": 3000, "service_tier": "standard", "inference_geo": "us"}}
assert round(price_response(from_anthropic(turn), date(2026, 11, 18)), 6) == 0.0902
gem = {"model": "gemini-3.8-flash", "usage": {
"total_input_tokens": 150000, "total_cached_tokens": 140000,
"total_output_tokens": 600, "total_thought_tokens": 2400}}
assert round(price_response(from_gemini(gem, "standard"), date(2026, 11, 18)), 6) == 0.02925
Step 3: a log schema that can answer finance’s questions
Store the normalized fields, not just a cost. When a rate turns out to be wrong, you can reprice history from the table without replaying traffic. One row per billed attempt keeps fallback and compaction passes visible.
CREATE TABLE llm_requests (
request_id text NOT NULL,
attempt smallint NOT NULL DEFAULT 0, -- index in usage.iterations
attempt_kind text NOT NULL DEFAULT 'message', -- message / compaction / fallback_message
ts timestamptz NOT NULL DEFAULT now(),
team text NOT NULL, -- from the gateway API key
feature text, -- caller-supplied header
vendor text NOT NULL,
model_requested text NOT NULL,
model_served text NOT NULL, -- price THIS one
tier text NOT NULL, -- as served, from the response
speed text NOT NULL DEFAULT 'standard',
inference_geo text NOT NULL DEFAULT 'global',
uncached_in integer NOT NULL,
cache_read integer NOT NULL,
cache_write_short integer NOT NULL, -- 5m (Anthropic) / 30m (OpenAI)
cache_write_long integer NOT NULL, -- 1h (Anthropic) / 12h (OpenAI)
output_tokens integer NOT NULL, -- includes reasoning
reasoning_tokens integer NOT NULL,
stream_complete boolean NOT NULL DEFAULT true,
est_cost_usd numeric(12,6) NOT NULL,
rates_checked date NOT NULL, -- which rates.yaml row priced it
PRIMARY KEY (request_id, attempt)
);
CREATE INDEX ON llm_requests (vendor, ts);
CREATE INDEX ON llm_requests (team, feature, ts);
Logging model_requested next to model_served gives you a cheap fallback detector: any row where they differ is an attempt answered by a different model than the caller asked for. Logging inference_geo does the same for the 1.1x US-only premium, which otherwise shows up only as an unexplained gap.
Step 4: reconcile daily against the vendor’s cost endpoint
Per-request pricing is for attribution: cost per team, per feature, per prompt version. The vendor’s organization-level cost endpoint is the source of truth for the total. Both OpenAI and Anthropic expose one behind an admin key, and they use different units:
- OpenAI’s
GET /v1/organization/costsreturnsamount.valueas a number in the currency named byamount.currency(dollars for"usd"), in daily buckets. - Anthropic’s Usage and Cost API reports costs in USD as decimal strings in the lowest unit, cents. A value of
"123.45"therefore means $1.2345.
A job that sums both without converting overstates Anthropic spend by exactly 100x. Parse Anthropic’s string as a decimal and divide by 100.
from decimal import Decimal
def anthropic_usd(amount: str) -> Decimal:
return Decimal(amount) / 100 # "123.45" (cents) -> 1.2345 USD
def openai_usd(value: float) -> Decimal:
return Decimal(str(value)) # already dollars when currency == "usd"
Then compare per vendor per day and alert when the gap leaves the band you have learned to expect:
WITH ours AS (
SELECT vendor, date_trunc('day', ts) AS day, sum(est_cost_usd) AS est
FROM llm_requests
WHERE ts >= now() - interval '8 days'
GROUP BY 1, 2
)
SELECT o.vendor, o.day, o.est, v.billed_usd,
round((v.billed_usd - o.est) / nullif(v.billed_usd, 0) * 100, 1) AS gap_pct
FROM ours o
JOIN vendor_daily_costs v USING (vendor, day) -- filled by the cost-endpoint job
WHERE abs(v.billed_usd - o.est) / nullif(v.billed_usd, 0) > 0.05
ORDER BY o.day DESC;
The two numbers will never match exactly, and the direction of the gap tells you where to look:
| Cause | Your estimate is |
|---|---|
Unbilled refusals still report tokens in usage | Too high |
| Interrupted streams lose the final usage chunk | Too low |
| Code execution containers, explicit cache storage, search grounding past a free allowance | Too low (never in per-response usage) |
| US-only inference or regional endpoints priced at the global rate | Too low (about 9% of the bill on affected traffic) |
| A rate row past its real end date | Either way |
A sudden jump in the gap is almost always something that changed this week: a team turned on compaction, a new server tool, a workspace default geography, a model started refusing, or a price moved.
Step 5: price a model before you pin it in CI
The same machinery answers a question platform teams get every week: “Can we use model X for this nightly job?” Do not answer it from the vendor’s homepage rates. Run twenty representative requests through the gateway against each candidate, take the normalized est_cost_usd, and multiply by the job’s real volume.
SELECT model_served,
count(DISTINCT request_id) AS sample_requests,
sum(est_cost_usd) / count(DISTINCT request_id) AS avg_cost,
sum(est_cost_usd) / count(DISTINCT request_id) * 4000 * 30 AS monthly_at_4k_per_day,
sum(reasoning_tokens)::float / nullif(sum(output_tokens), 0) AS reasoning_share,
sum(cache_read)::float / nullif(sum(uncached_in + cache_read), 0) AS cache_hit_share
FROM llm_requests
WHERE feature = 'ci-eval-trial'
GROUP BY 1
ORDER BY monthly_at_4k_per_day;
The reasoning_share column is the one that surprises people. Two models with identical list prices can differ by several times on a real job because one of them thinks much longer before answering, and that thinking is billed as output.
When not to bother
Not every gateway needs all of this:
- One vendor, low volume. If you only call one API and the monthly bill is small, use that vendor’s own cost function and its dashboard. The cross-vendor bugs cannot happen.
- No caching, no reasoning models, no agents. Most of the divergence comes from cache fields, reasoning tokens and multi-pass features. Plain single-shot completions on a non-reasoning model price the same way everywhere, as long as you still read the tier and geography from the response.
- You only need a monthly total. If nobody needs cost per team or per feature, pull the vendor cost endpoints and skip per-request pricing entirely.
If you are past those thresholds, the short version fits on a sticky note: know which vendor’s input_tokens you are holding, price the model and tier the response names, price each iterations entry at its own model’s rates, add thoughts at Google and nowhere else, apply 1.1x when inference_geo says "us", take the last streaming count, put an expiry date on every rate, and let the vendor’s cost endpoint have the final word.
References
All pages were checked on November 18, 2026.
Anthropic
- Pricing (model rates, batch, fast mode, data residency multiplier): https://platform.claude.com/docs/en/about-claude/pricing
- Data residency and
inference_geo: https://platform.claude.com/docs/en/build-with-claude/data-residency - Messages API reference (
usageobject fields): https://platform.claude.com/docs/en/api/messages - Compaction and
usage.iterations: https://platform.claude.com/docs/en/build-with-claude/compaction-threshold - Refusals, server-side fallback and sticky routing: https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback
- Streaming messages: https://platform.claude.com/docs/en/build-with-claude/streaming
- Usage and Cost API: https://platform.claude.com/docs/en/build-with-claude/usage-cost-api
OpenAI
- API pricing (standard, flex, fast, long context, regional processing): https://developers.openai.com/api/docs/pricing
- Prompt caching (cached and cache-write token fields): https://developers.openai.com/api/docs/guides/prompt-caching
- Fast mode and ramp-rate downgrades: https://developers.openai.com/api/docs/guides/fast-mode
- Flex processing: https://developers.openai.com/api/docs/guides/flex-processing
- Responses API reference: https://developers.openai.com/api/reference/resources/responses/methods/create
- Chat Completions API reference (
stream_options.include_usage,prompt_tokens_details): https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create - Usage and Costs API: https://platform.openai.com/docs/api-reference/usage/costs
- Gemini Developer API pricing: https://ai.google.dev/gemini-api/docs/pricing
- Understand and count tokens (Interactions
usagefields): https://ai.google.dev/gemini-api/docs/tokens - Thinking (pricing of thought tokens): https://ai.google.dev/gemini-api/docs/thinking
- Context caching: https://ai.google.dev/gemini-api/docs/caching
- Priority inference and downgrade header: https://ai.google.dev/gemini-api/docs/priority-inference
- Flex inference: https://ai.google.dev/gemini-api/docs/flex-inference
- Interactions API reference: https://ai.google.dev/api/interactions
- generateContent reference (
usageMetadata): https://ai.google.dev/api/generate-content
