LLM Price Catalog
The price catalog: the LLM prices that a new platform starts with, data/llm_prices.yaml.
Each entry is a model’s price as its provider publishes it, in USD per million input tokens and per
million output tokens, with the page that published it. An LLMPrices
row has one price per million tokens, which a charge’s total tokens are multiplied by, so each entry
is stored at its blended price, blended_price().
manage.py initialize_llm_prices, which initialize_platform runs, calls seed_llm_prices().
The catalog only starts a platform’s prices: they live in the database, where the Smarter LLM Price
Checker, smarter.apps.account.llm_price_checker, keeps them up to date every week, and a
person may change them in the Django admin.
- smarter.apps.account.llm_price_catalog.INPUT_TOKENS_PER_OUTPUT_TOKEN = 3
three input tokens to one output token.
It is the industry’s usual convention for a single price per token. An application whose prompts are long and whose answers are short, e.g. one with tools and a large system prompt, uses more input tokens than that, so its blended price slightly overstates its cost.
- Type:
The mix of tokens that a blended price assumes
- class smarter.apps.account.llm_price_catalog.LLMPriceCatalog(**data)[source]
Bases:
BaseModelThe catalog file,
data/llm_prices.yaml.- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- prices: list[LLMPriceCatalogEntry]
- class smarter.apps.account.llm_price_catalog.LLMPriceCatalogEntry(**data)[source]
Bases:
BaseModelA model’s price, as its provider publishes it.
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.apps.account.llm_price_catalog.SEEDED_CHARGE_TYPES = ('completion', 'plugin', 'tool')
a model call, and the plugin and tool calls that it makes.
('completion', 'plugin', 'tool')
- Type:
The charge types that each model is priced for
- smarter.apps.account.llm_price_catalog.adopt(row, entry, price)[source]
Mark an existing price as the catalog’s, when it is exactly the catalog’s price and has no source.
A price that was created before prices recorded their source is a person’s, by default. When it is still the catalog’s blended price, the catalog created it, so it becomes the catalog’s again, and the Smarter LLM Price Checker keeps it up to date. Any other price stays a person’s.
- Parameters:
row (
LLMPrices) – The existing price.entry (
LLMPriceCatalogEntry) – The catalog’s price of its model.price (
Decimal) – The entry’s blended price.
- Returns:
True if the row was adopted.
- Return type:
- smarter.apps.account.llm_price_catalog.blend(input_price, output_price)[source]
Return the single price per million tokens of an input and an output price.
- smarter.apps.account.llm_price_catalog.blended_price(entry)[source]
Return a model’s single price per million tokens, of three input tokens to one output token.
- Parameters:
entry (
LLMPriceCatalogEntry) – The model’s price.- Returns:
USD per million tokens, (3 * input + output) / 4. See
blend().- Return type:
- smarter.apps.account.llm_price_catalog.checked_at(entry)[source]
Return when a catalog entry’s price was checked, as a datetime: midnight UTC of its
checkedday.- Parameters:
entry (
LLMPriceCatalogEntry) – The model’s price.- Returns:
The datetime.
- Return type:
- smarter.apps.account.llm_price_catalog.load_llm_price_catalog(path='/Users/mcdaniel/Desktop/gh/smarter-sh/smarter/smarter/smarter/apps/account/data/llm_prices.yaml')[source]
Read and validate the price catalog.
- smarter.apps.account.llm_price_catalog.seed_llm_prices(catalog)[source]
Create the catalog’s prices that don’t exist yet, for each charge type, and keep those that do.
A price that exists, e.g. one that a person changed in the Django admin, is never changed. An existing price that is still exactly the catalog’s, with no source, is marked as the catalog’s (
adopt()), so that the Smarter LLM Price Checker keeps it up to date.- Parameters:
catalog (
LLMPriceCatalog) – The catalog.- Returns:
The number of prices created, and the number that already existed.
- Return type: