LLM Price Checker
The Smarter LLM Price Checker: an LLMClient that keeps the LLM prices up to date, every week.
Every LLMPrices row that the price catalog or the checker
itself set, and that has a source_url, is checked against that page: the provider’s pricing
page. The platform fetches each page once, converts it to Markdown, and prompts the staff-only
LLMClient smarter_llm_price_checker of the Smarter account with the page and the models that it
prices. The LLMClient answers with each model’s standard price per million input and output
tokens, as JSON.
Its answer is checked again here, whatever its system prompt says (check_price()):
a price must be of a model that it was asked about;
its input and output prices must both be dollar amounts that are written on the page, so that it can’t invent a number;
the new blended price may differ from the current one by a factor of at most
LLM_PRICE_CHECKER_MAX_CHANGE, up or down. A larger change is more likely a misreading, e.g. of a batch rate or of another model’s row, than a new price.
A price that fails is refused, logged, and kept as it was. A price that a person set
(HUMAN), e.g. in the Django admin, is never
checked or changed. Celery Beat runs smarter.apps.account.tasks.check_llm_prices() every week,
while the enable_llm_price_checker switch is on.
The LLMClient is prompted in-process, as its owner, with
smarter.apps.llmclient.prompting.prompt_in_process(): its system prompt, guardrails and
budget apply, as they would to a person’s prompt.
- class smarter.apps.account.llm_price_checker.LLMPriceCheckerAnswer(**data)[source]
Bases:
BaseModelThe checker’s answer.
- model_config = {'extra': 'ignore'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- prices: list[LLMPriceCheckerPrice]
- class smarter.apps.account.llm_price_checker.LLMPriceCheckerPrice(**data)[source]
Bases:
BaseModelThe checker’s price of one model.
Extra fields are ignored: an LLM adds some.
- model_config = {'extra': 'ignore'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.account.llm_price_checker.LLMPriceCheckerRequest(**data)[source]
Bases:
LLMPriceCheckerModelThe checker’s prompt: a pricing page, and the models that it prices.
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.account.llm_price_checker.LLMPriceCheckerResult(**data)[source]
Bases:
BaseModelWhat the checker did with one pricing page.
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.apps.account.llm_price_checker.apply_price(price)[source]
Apply a checked price to every charge type’s row of its model that the checker keeps.
A row whose price is unchanged is only marked as checked, and keeps its source.
- Parameters:
price (
LLMPriceCheckerPrice) – The price, whichcheck_price()accepted.- Returns:
True if the price changed.
- Return type:
- smarter.apps.account.llm_price_checker.check_change(provider, model, new)[source]
Check that a model’s new price is within a factor of its current price, up or down.
- smarter.apps.account.llm_price_checker.check_llm_prices()[source]
Check every price that the checker keeps, page by page, while the
enable_llm_price_checkerswitch is on.- Returns:
What was done with each pricing page, or nothing if the switch is off or the checker doesn’t exist on this platform.
- Return type:
- smarter.apps.account.llm_price_checker.check_page(llmclient, url, models)[source]
Ask the checker for the prices of a page’s models, and apply those that pass the checks.
- Parameters:
- Returns:
What was checked, changed and refused.
- Return type:
- smarter.apps.account.llm_price_checker.check_price(price, request, amounts)[source]
Check a price that the checker read, against its request and its page.
- Parameters:
price (
LLMPriceCheckerPrice) – The checker’s price of a model.request (
LLMPriceCheckerRequest) – The request that it answers.amounts (
set[Decimal]) – The dollar amounts written on the page, fromdollar_amounts().
- Returns:
Why the price is refused, or
Noneif it is fine.- Return type:
- smarter.apps.account.llm_price_checker.checked_prices()[source]
Return the models whose prices the checker keeps up to date, by the page that publishes them.
- smarter.apps.account.llm_price_checker.dollar_amounts(page)[source]
Return the dollar amounts that are written on a page.
- smarter.apps.account.llm_price_checker.page_markdown(url)[source]
Fetch a pricing page, and return it as Markdown, whose tables keep their rows and columns.
- Parameters:
url (
str) – The page’s url.- Returns:
The page’s main content, at most
LLM_PRICE_CHECKER_MAX_PAGE_CHARACTERScharacters.- Return type:
- Raises:
safe_http.SafeHttpError – If the page can’t be fetched.
SmarterValueError – If the page has no text.