Repository navigation
lm15 2.0.0
In Python: Usage(...) raises ValueError on parts that do not fit; InferencePricing.estimate(usage) takes a Usage (the keyword form is gone) and returns a cost or None; PricingTier(above_input_tokens=272_000, ...); OpenAIChatCompat(reasoning_usage="separate").
A usage counter means one thing on every provider (MAP-19). Breaking for code that reads token counts or estimates cost.
input_tokensis every token the model read, cached tokens included;output_tokensis every token it wrote, reasoning included. The cache, reasoning and audio counts are parts of one of those two, andtotal_tokensis input + output. In 1.x each counter was the provider's own, so the same field meant different things.- What changes: Anthropic input (and DeepSeek, Meta and Moonshot on the Anthropic wire) now includes cache reads and writes; a call that read 4,873 cached tokens and 20 new ones reports 4,893, not 20. Gemini and Vertex output now includes the thinking, and input includes the tokens Gemini's own tools added. xAI output now includes reasoning. OpenAI and other Chat Completions servers: unchanged. The provider's own numbers stay in
provider_data, for checking a bill. - A counter is exact or empty, never a partial sum. When a provider's numbers do not add up the way its wire is documented to count, input and/or output are left empty rather than wrong.
- Building a usage record checks that parts fit inside wholes and that the total is input + output. A usage record saved by 1.x from Anthropic, Gemini or xAI can fail to load for this reason; the message says so.
Cost estimates are exact or unknown. The estimate takes a usage record and returns the list price, or nothing when an unknown count could change it (and for calls with audio tokens). 1.x charged cached tokens twice on OpenAI, Gemini and xAI (a call with 90,000 of its 100,000 input tokens cached cost $0.039 and was estimated at $0.219) and missed Gemini's and xAI's reasoning. Pricing tiers reprice a whole call above a prompt length, as OpenAI does above 272,000 input tokens and Claude Haiku 5.5 above 100,000; an absent price is unknown, never zero. A reasoning_usage compat setting covers servers that count reasoning beside the completion (the xai preset).
Major version 2 in every language. The major version is now the contract's generation, the same in every lm15 language (lm15-contract playbooks/api-family.md, rule 8); generation 2 begins with this change.
Contract cfc3edc (ratified on 2026-11-01 in 6b801f9, wording only): 1,968 of 1,968 checks, the same commit as Python 2.0.0, TypeScript 2.0.0, Rust 2.0.0-rc.1, Go v2.0.0-rc.1, Julia 2.0.0 (LanguageModel15, joining Julia's registry) and R 2.0.0. Rules in lm15-contract changes/2026-10-31-usage-one-meaning.md.
Also fixed: streaming a Gemini Live model through complete/stream (extensions={"transport": "live"}) raised TypeError while summing usage; it now reports the turn's last usage.
python3 -m pip install -U lm15