LLMPrices Model
Account LLMPrices Model
This module defines the LLMPrices model for managing provider/model-specific markup factors
used in account billing. It enables proportional billing across all accounts based on their usage
of different LLM providers and models.
Classes
LLMPrices: Stores markup prices for each (charge_type, provider, model) combination.
Key Features
Tracks markup factors for each provider/model/charge type.
Enforces uniqueness for (charge_type, provider, model) combinations.
Supports flexible billing and cost allocation for LLM usage.
Example
from smarter.apps.account.models import LLMPrices
markup = LLMPrices.objects.get(provider="openai", model="gpt-4").price
account_charge = provider_cost * markup * account_usage_ratio
- class smarter.apps.account.models.llm_prices.LLMPriceSource(*values)[source]
Bases:
TextChoicesWho set an
LLMPricesrow’s price.The Smarter LLM Price Checker,
smarter.apps.account.llm_price_checker, keeps the prices of the catalog and its own up to date, and never changes a person’s.- CATALOG = 'catalog'
manage.py initialize_llm_pricescreated it, from the price catalogdata/llm_prices.yaml.
- HUMAN = 'human'
A person set it, e.g. in the Django admin.
It is never changed automatically.
- LLM = 'llm'
The Smarter LLM Price Checker read it on its source’s page.
- class smarter.apps.account.models.llm_prices.LLMPrices(*args, **kwargs)[source]
Bases:
TimestampedModelLLMPrices model for managing markup factors in account billing.
Stores provider/model-specific price markups, enabling proportional billing across all accounts based on their usage.
- Parameters:
charge_type – String. The type of charge (e.g., completion, plugin, tool).
provider – String. The LLM provider (e.g., OpenAI, Meta AI).
model – String. The model name.
price – Decimal. The price in USD per million tokens, markup included.
cost_of()uses it to price charges, which budgets that measure cost compare to their limits.source – String. Who set the price, an
LLMPriceSource. A row created any other way than by the catalog or the Smarter LLM Price Checker is a person’s.source_url – String. The provider’s page that publishes the model’s price, which the Smarter LLM Price Checker reads every week.
input_price – Decimal, optional. The provider’s price per million input tokens.
output_price – Decimal, optional. The provider’s price per million output tokens.
checked_at – Datetime, optional. When the price was last checked against its source.
Note
Markup factors are used to calculate each account’s share of provider costs.
Example usage:
# Calculate account charge for provider/model usage markup = LLMPrices.objects.get(provider="openai", model="gpt-4").price account_charge = provider_cost * markup * account_usage_ratio
- TODO:
create a Choice or FK to charge_type field.
- TODO:
create some form of referential integrity for model and provider fields.
- TODO:
establish reasonable boundaries on price field.
See also
Account,Charge- Parameters:
id (Unknown) – Primary key: ID
created_at (Unknown) – Created at
updated_at (Unknown) – Updated at
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- exception NotUpdated
Bases:
ObjectNotUpdated,DatabaseError
- checked_at
-
Checked at. When the price was last checked against its source.
- Type:
Type
- classmethod cost_of(charge_type, provider, model, total_tokens)[source]
The cost in USD of total_tokens, where price is USD per million tokens.
Budgets that measure cost use it. Without a price for the charge type, provider and model, the cost is 0.
- Return type:
- created_at
-
Created at
Timestamp indicating when the model instance was created.
This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.
- Type:
Type
- get_source_display(*, field=<django.db.models.CharField: source>)
Shows the label of the
source. Seeget_FOO_display()for more information.
- id: int
-
Primary key: ID
The row’s primary key, which Django adds to every concrete model. Declared, without a value, only so that type checkers know it: Django ignores a bare annotation.
- Type:
Type
- input_price
-
Input price. The provider’s price, in USD per million input tokens, that the price was blended from.
- Type:
Type
- objects = <django.db.models.Manager object>
- output_price
-
Output price. The provider’s price, in USD per million output tokens, that the price was blended from.
- Type:
Type
- price
-
Price
- Type:
Type
- source
-
Source. Who set the price. The Smarter LLM Price Checker never changes a price that a person set.
Choices:
catalogllmhuman
- Type:
Type
- source_url
-
Source url. The provider’s page that publishes the model’s price. The Smarter LLM Price Checker reads it.
- Type:
Type
- updated_at
-
Updated at
Timestamp indicating when the model instance was last updated.
This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.
- Type:
Type