falaw.llm_prices#
One first-party LLM price table: what a direct Anthropic / OpenAI call costs (falaw#81).
falaw.llm_rates prices LLMs routed through fal (fal-ai/any-llm).
This module prices calls made straight to the model vendor, the way reelee’s
agent loop and chat relay and foley’s rungs make them. Those three used to keep
a private copy of the same numbers and drifted; this is the one home.
>>> llm_call_cost_usd("anthropic", "claude-opus-4-7",
... {"input_tokens": 1_000_000, "output_tokens": 0})
(5.0, True)
The answer is (usd, known). A model the table does not list is **unknown,
not free**: it is priced at the dearest rates listed for that provider and
known is False. The cost is then a floor on a guess, not a ceiling: an
unlisted model can cost more than the dearest listed one (an older, pricier
model). A spend cap can count it; a caller that must never under-count should
refuse an unpriced model by testing known:
>>> usd, known = llm_call_cost_usd("anthropic", "claude-from-the-future",
... {"input_tokens": 1_000_000})
>>> known, usd > 0
(False, True)
usage is the vendor’s own reported usage, a mapping or an object with
attributes, in either of OpenAI’s two shapes (Responses or Chat Completions):
>>> llm_call_cost_usd("openai", "gpt-5", {"prompt_tokens": 1000,
... "completion_tokens": 100, "prompt_tokens_details": {"cached_tokens": 1000}})
(0.001125, True)
The table is data, not code: PRICES_FILENAME under falaw/data, one
row per model, each row carrying its own source and date. Nothing here
touches the network. Model ids are matched exactly: a dated snapshot is not
priced as its family, because older snapshots can cost more.
Module Attributes
Basename of the price table under |
|
Token count the table's |
|
Digits the returned USD is rounded to, which only removes float noise. |
|
First-party providers the table prices. |
Functions
|
The row for |
|
Every row, or the rows of one |
|
|
The table's version, a digest of its bytes (see |
|
The committed table, keyed by |
Classes
|
One row of the first-party table: a model's rates and where they came from. |
|
USD per million tokens for one prompt-length regime of one model. |
- falaw.llm_prices.COST_DECIMALS = 9#
Digits the returned USD is rounded to, which only removes float noise.
- class falaw.llm_prices.LlmPrice(*, provider, model, rates, long_prompt_over_tokens=None, long_prompt_rates=None, source='', date='', notes='')[source]#
Bases:
objectOne row of the first-party table: a model’s rates and where they came from.
- class falaw.llm_prices.LlmPriceRates(*, input_usd_per_mtok, output_usd_per_mtok, cache_read_usd_per_mtok=None, cache_write_usd_per_mtok=None, cache_write_1h_usd_per_mtok=None)[source]#
Bases:
objectUSD per million tokens for one prompt-length regime of one model.
- falaw.llm_prices.PRICES_FILENAME = 'first_party_llm_prices.json'#
Basename of the price table under
falaw/data.
- falaw.llm_prices.PROVIDERS = ('anthropic', 'openai')#
First-party providers the table prices.
- falaw.llm_prices.TOKENS_PER_PRICE_UNIT = 1000000#
Token count the table’s
*_usd_per_mtokcolumns are quoted per.
- falaw.llm_prices.get_llm_price(provider, model, *, prices=None)[source]#
The row for
model(exact id), orNonewhen the table does not list it.
- falaw.llm_prices.list_llm_prices(provider=None, *, prices=None)[source]#
Every row, or the rows of one
provider.
- falaw.llm_prices.llm_call_cost_usd(provider, model, usage, *, prices=None)[source]#
(USD, known)for one first-party call from the vendor’s reportedusage.provider="anthropic":input_tokens(uncached),output_tokens,cache_read_input_tokens,cache_creation_input_tokens.provider="openai": Responses (input_tokens/output_tokens/input_tokens_details.cached_tokens) or Chat Completions (prompt_tokens/completion_tokens/prompt_tokens_details.cached_tokens). Input includes the cached part, which is billed at the cached rate; reasoning tokens are already in output.
knownisFalsewhen the model is not in the table; the cost is then priced at the provider’s dearest listed rates, which is not a ceiling for a model pricier than any listed (see the module docstring).prices=swaps in the caller’s own table, e.g. one reconciled against an invoice.- Raises:
ValueError –
provideris not one ofPROVIDERS.- Return type:
- falaw.llm_prices.llm_prices_table_version()[source]#
The table’s version, a digest of its bytes (see
falaw.base.data_table_version()).- Return type: