Move LLM prices to a config file refreshed on release
Follow-up to #4638, as suggested in the review comment: move the prices out of app/models/llm_usage.rb into a config file that a GitHub workflow can update on every release.
Problem
LlmUsage::PRICING was a Ruby hash. Every provider price change or new model needed a hand-written code PR. When nobody wrote one, new models showed N/A on the LLM usage screen (Opus 5.5 before #4638).
Resulting behavior
Config file. config/llm_pricing.yml holds the same rows, one model per line. The family and tier fallbacks (claude-opus, gpt-sol, …) and the gpt-5.6 alias are now YAML aliases of the row they copy, not duplicate numbers. LlmUsage loads the file into the unchanged PRICING / PRICING_VERIFIED_ON constants, so lookups, providers' order and costs are identical. I checked that the loaded hash, including key order, equals the old constant. No call sites change.
Updater. bin/update_llm_pricing (logic in lib/llm_pricing_updater.rb, stdlib only) reads LiteLLM's price list and:
- rewrites a listed row only when its prices changed. The edit happens in place, so comments, anchors and aliases survive. It maps input, output, Anthropic cache-read (only when not 0.1x input) and the
*_above_<N>k_tokenslong-context tier. - adds new Claude (
claude-opus-6) and GPT tier (gpt-6.2-sol) releases, which are exactly the models the fallbacks would otherwise only estimate. Dated snapshots and-4-0aliases are skipped. - accepts only entries from the matching LiteLLM provider (
openai,anthropic,gemini/…), with finite, non-negative, sane numbers. It rejects an entry with a partial long-context tier, or an Anthropic entry without a cache-read price. It keeps a configured long-context tier that LiteLLM doesn't list, and reports those rows as left unchanged. It refuses to write a file that no longer loads. - prints a Markdown summary: what changed, what was added, and which rows LiteLLM lacks.
Workflow. .github/workflows/llm-pricing.yml (Refresh LLM pricing) runs on v* tags and on demand, on we-promise/sure only. When the file changes and no refresh PR from this repository is open, it force-pushes automation/refresh-llm-pricing, opens a PR with that summary, and dispatches pr.yml, like the version-bump flow in publish.yml, because PRs opened with GITHUB_TOKEN don't trigger CI. While a refresh PR is open, later runs skip with a warning, so a review in progress is never rewritten. A failed PR lookup fails the run. The job runs on ubuntu-24.04 like ci.yml. verified_on is never bumped automatically. The PR body asks the reviewer to check the changes against the official pages first.
A dry run against today's LiteLLM list changes one row: it adds a 272K long-context tier to gpt-5.6-cyber, which OpenAI's page does not list. That is the kind of thing the PR review is for. It adds no models. It reports 6 rows LiteLLM lacks: o1-mini, gemini-3.1-pro, gemini-3-flash, claude-opus-4, claude-opus-4-1, claude-sonnet-4.
docs/hosting/ai.md points at the config file and describes the workflow.
Notes for maintainers
- The workflow needs the existing "Allow GitHub Actions to create and approve pull requests" setting, which
publish.ymlalready relies on. - LiteLLM is a third-party list. Today it matches the official Claude and OpenAI prices to the cent, but it can lag. The workflow therefore only proposes changes and never merges them.
Validation
bin/rails test test/lib test/models/llm_usage_test.rb test/models/provider test/controllers/settings/llm_usages_controller_test.rb: green. NewLlmPricingUpdaterTestcovers in-place rewrites with comments and aliases, adding releases while skipping snapshots, aliases, other providers and non-tier IDs, rejecting bad source data, and that the bundled config round-trips unchanged when LiteLLM agrees with it.bin/rubocop: no offenses.bin/brakeman: 0 warnings.actionlint(with shellcheck) on the new workflow: clean. No UI, ERB or JS changes.
Summary by cubic
Follow-up to #4638: moves LLM pricing from a Ruby hash in LlmUsage into config/llm_pricing.yml, refreshed by a new GitHub workflow so provider price changes and new model releases no longer need hand-written code PRs.
Behavior
PRICINGandPRICING_VERIFIED_ONload from the YAML file; lookups, fallbacks, costs, and the LLM usage screen are unchanged.bin/update_llm_pricingreads LiteLLM's price list, rewrites changed rows in place (comments, anchors, aliases, and trailing comments containing braces survive), adds new Claude and GPT tier releases, and prints a Markdown summary.- It validates source data, refuses to write a file that no longer loads, and leaves unchanged any row with a partial long-context tier, a reviewed tier LiteLLM lacks, or an Anthropic entry without a valid cache-read price, reporting them as missing.
Workflow
- Refresh LLM pricing runs on
v*tags and on demand. If the file changes and no refresh PR from this repository is open, it force-pushesautomation/refresh-llm-pricingand opens a PR with that summary, then dispatchespr.yml(PRs opened withGITHUB_TOKENdon't trigger CI). - While a refresh PR is open, later runs skip with a warning. The lookup uses
gh pr list, so an API error fails the run instead of force-pushing over a review. It never merges, keepsverified_onmanual, and asks reviewers to check changes against provider pricing pages. - Requires the existing "Allow GitHub Actions to create and approve pull requests" setting that
publish.ymlalready relies on.
Summary by CodeRabbit
- New Features
- LLM usage pricing lists rates for supported OpenAI, Google, and Anthropic models, including applicable long-context and cache rates.
- Pricing can be refreshed on releases or on demand using LiteLLM’s published prices. When prices change, a review pull request is opened; automatic refresh skips if one is already open.
- Pricing updates can include newly listed eligible GPT and Claude models while retaining reviewed rates when source data is incomplete.
- Documentation
- Cloud Costs guidance explains where listed prices and their verification date come from and how to review pricing updates, including checking provider pricing pages and model-family fallbacks.