genai-prices
AGENTS.md416 starsChanged 31 days agoMITView on GitHub
CLAUDE.md is a symlink to this file, so every harness reads the same instructions. This is the GenAI Prices project - a database and tools for calculating LLM inference API pricing. The project includes: - Price Data: YAML files in prices/providers/ with pricing information for 30+ LLM providers - Unit Registry: prices/units.yml defines every billable unit and its price key - Packages: packages/python/ (PyPI genai-prices), packages/js/ (npm @pydantic/genai-prices), packages/go/ (Go module github.com/pydantic/genai-prices/packages/go) and packages/rust/ (crate genai-prices) — four implementations that…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,315 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- add-price-modelSkill
- add-providerSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
13 rules. About 0 are common, 4 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 85
Always run make build, not make build-prices alone.
- Very specific: line 128
Every generated artifact is marked linguist-generated in .gitattributes, so GitHub collapses its diff.
- Very specific: line 141
When a model has price_variants, verify every tier separately when its standard rates change.
- Very specific: line 151
When updating prices in YAML files, always update the prices_checked field to current date
- Very specific: line 152
Add price_comments to explain changes and provide references
- Very specific: line 195
Use uv for dependency management (not pip/conda), npm for the JS workspace, go modules for packages/go/ and cargo for packages/rust/
- Very specific: line 205
Run make build after editing anything under prices/
- Distinctive: line 206
Always run the full test suite before submitting changes
- Very specific: line 224
Use make test-all-python to test across Python 3.11-3.15
- Distinctive: line 251
Follow existing patterns in the codebase
- Very specific: line 255
Create a GitHub release with a vX.Y.Z tag.
- Distinctive: line 263
After opening or updating a PR, don't go idle until it's genuinely in its desired end state.
- Distinctive: line 267
every reviewer comment (cubic included) is addressed or explicitly dismissed.
≈ “Common” is an estimate: at least 1 in 5 of the 42,283 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
This file provides guidance to AI coding agents working in this repository. CLAUDE.md is a symlink
to this file, so every harness reads the same instructions.
Repository Overview
This is the GenAI Prices project - a database and tools for calculating LLM inference API pricing. The project includes:
- Price Data: YAML files in
prices/providers/with pricing information for 30+ LLM providers - Unit Registry:
prices/units.ymldefines every billable unit and its price key - Packages:
packages/python/(PyPIgenai-prices),packages/js/(npm@pydantic/genai-prices),packages/go/(Go modulegithub.com/pydantic/genai-prices/packages/go) andpackages/rust/(crategenai-prices) — four implementations that must match the Python reference (see "Python/JS/Go/Rust parity") - Data Pipeline: Tools to build JSON schemas, validate data, and update from external sources
- Price Sources: Integration with Helicone, OpenRouter, LiteLLM, and other pricing sources
Architecture
Core Components
- Price Data Sources (
prices/providers/*.yml): YAML files containing model pricing information for each provider - Unit Registry (
prices/units.yml): the vocabulary of billable units — every valid price key and extractor destination is derived from it - Data Pipeline (
prices/src/prices/): Python modules that build, validate, and process pricing data - Packages (
packages/python/,packages/js/,packages/go/,packages/rust/): published libraries for end users to calculate costs - External Data Integration: Tools to pull and compare prices from external sources
Key Directories
prices/: Core pricing data and build toolsproviders/: YAML files with provider-specific pricingunits.yml: the unit registry (see "Adding a unit" below before editing)src/prices/: Python package for data processingnew_data/v2/: the live published data —data.json,data_slim.jsonand their schemas (generated)data.json,data_slim.json+ schemas: frozen v1 compatibility snapshots (see "Pricing Data")
packages/python/,packages/js/,packages/go/,packages/rust/: the packages. Their provider data (data.py,data.ts,internal/data/prices.json,data/prices.json) and unit data (data_units.py,dataUnits.ts,data_units.go,src/data_units.rs) are generated — never hand-edit themtests/: Python test suite; JS tests live inpackages/js/src/__tests__/, Go tests inpackages/go/*_test.go, Rust tests inpackages/rust/tests/specs/data-driven-unit-registry/: authoritative design docs for the unit registry and the v1/v2/v3 contract rules. Read these before changing anything about units or published artifactsscratch/: Development/testing files IGNORE THESE FILES
Development Commands
Setup
make install # Install dependencies and pre-commit hooks
make sync # Update local packages and uv.lockCore Development
make format # Format code with ruff
make lint # Check code style and linting
make typecheck # Run static type checking with basedpyright
make test # Run the Python tests with coverage (does NOT run the JS, Go or Rust suites)
make testcov # Run tests and generate HTML coverage report
npm run ci # Build and test the JS package
make format-go # Format the Go package with gofmt
make lint-go # Lint the Go package with golangci-lint
make test-go # Run the Go tests with the race detector; fails below 90% coverage
make format-rust # Format the Rust crate with rustfmt
make lint-rust # Check rustfmt and run clippy with warnings as errors
make test-rust # Run the Rust tests with cargo-llvm-cov; fails below 95% line coveragemake all covers Python, JavaScript, Go and Rust. Run npm run ci directly to verify only JavaScript, make test-go
to verify only Go, and make test-rust to verify only Rust.
Building and Data Processing
make build # build-prices + package-data + inject-providers — use this one
make build-prices # Validate providers and write prices/new_data/v2/* + prices/providers/.schema.json
make package-data # Regenerate the bundled data in packages/python/, packages/js/, packages/go/ and packages/rust/Always run make build, not make build-prices alone. The installed packages read their bundled
data (packages/python/genai_prices/data.py, packages/js/src/data.ts, packages/go/internal/data/prices.json,
packages/rust/data/prices.json), which only package-data regenerates — so a calc_price check run after
build-prices verifies stale data.
Price Data Management
make get-all-prices # Download prices from all external sources
make helicone-get # Get Helicone prices
make openrouter-get # Get OpenRouter prices
make litellm-get # Get LiteLLM prices
make simonw-prices-get # Get Simon Willison's prices
make huggingface-get # Get HuggingFace prices
make ovhcloud-get # Get OVHcloud AI Endpoints prices
make quicksilverpro-get # Get QuickSilver Pro prices
make get-update-price-discrepancies # Download and update price discrepancies
make check-for-price-discrepancies # Check for price discrepancies
make detect-deprecated # Detect models that may be deprecated or removed
make collapse-models # Collapse duplicate similar modelsmake help lists every target. These importers run against live third-party APIs and nothing in CI
exercises them, so they break silently when an upstream schema changes — if one returns suspiciously
little, suspect the importer before the data. Every importer goes through ProviderYaml.upsert_models, which
never deletes a model, adds a dated entry for each rate change, and exits non-zero when the source returns fewer
models than the importer's MIN_MODEL_COUNT.
Important Notes
Pricing Data
- v2 is the live feed.
prices/new_data/v2/data.jsonis what the published packages auto-update from, and it goes live on merge tomain— independent of any package release. - v1 is frozen.
prices/data.json,prices/data_slim.jsonand their two schemas are compatibility snapshots for pre-0.1.0 clients. No build step writes them any more, and they receive no provider, model or price updates. Don't regenerate them, don't hand-edit them, and don't treat their staleprices_checkeddates as a bug.tests/test_frozen_v1_data.pypins their sha256 digests, so an edit fails the test suite — because no build step rewrites them, that test is the only thing that catches it. - NEVER hand-edit any generated file: the v2 payloads and schemas,
prices/providers/.schema.json, or the bundleddata.py/data.ts/prices.json/data_units.py/dataUnits.ts/data_units.go. Edit the provider YAML orprices/units.ymland runmake build. The pre-commitbuildhook regenerates all of these and fails when the result differs, so CI catches an edit to any of them. - Every generated artifact is marked
linguist-generatedin.gitattributes, so GitHub collapses its diff. Review the provider YAML andunits.yml; trust the build hook and the digest test for the rest. - Published artifact URLs must not change — new contracts go in a new
prices/new_data/v<version>/directory rather than moving or renaming existing files. - Never overwrite a
prices:block when a provider changes its rates. Editing those values in place re-prices every past request at the new rate — a request from before the change gets billed at today's price. Add a dated conditional price entry instead: makeprices:a list, keep the existing rates as the first entry with noconstraint, and append the new rates underconstraint: { start_date: <date the new price took effect> }. All three engines take the last matching entry, so the dated entry goes at the end.openai.yml(o3) andanthropic.yml(1M-context surcharge) show the shape. Overwrite in place only to correct a value that was already wrong when it was written — a correction has no history worth keeping. The/add-price-modelskill covers the full procedure. - When a model has
price_variants, verify every tier separately when its standard rates change. The rates a variant lists are absolute; omitted keys inherit standard prices for that date. Preserve existing variant entries and prepend dated entries for changed tier rates: variants use the first matching value per price key. Record a source confirming any tier whose rates stayed unchanged, and test each affected context before and after the change in Python, JavaScript, Go and Rust. - The importers do this automatically through
ProviderYaml.upsert_models(prices/src/prices/variants.py). When a standard rate changes, a variant whose rates are all one share of the standard rates gets a dated entry at that share of the new rates. A 50% batch discount and a 2x priority surcharge are examples, and the provider's cent rounding is allowed for. A variant with no single share, such as flat batch rates on tiered standard rates, is logged asupdate them by hand. - When updating prices in YAML files, always update the
prices_checkedfield to current date - Add
price_commentsto explain changes and provide references
Authoring provider YAML
- The valid
prices:keys and extractordest:values are derived fromprices/units.yml, not hardcoded anywhere.prices/providers/.schema.jsonis the generated list; your IDE reads it via the# yaml-language-server:header, but on the CLI readunits.ymldirectly. - Not every price key is per-million-tokens.
_mtokis per 1M,_kcountis per 1,000 (e.g.requests_kcount,web_searches_kcount),_mcharsper 1M characters,_hoursper 3,600 seconds,_gpixelsper 1e9,_kpagesper 1,000. Putting a per-Mtok figure under a_kcountkey is valid YAML and silently wrong by 1000×. - Prices must cover their ancestors and joins: a model priced with
cache_write_1h_mtokalso needscache_write_mtok, and so on.make buildenforces this; the error names the missing key. - An extractor that maps
completion_tokensmust also mapoutput_reasoning_tokens. OpenAI-compatible chat responses count reasoning tokens insidecompletion_tokensand report the breakdown undercompletion_tokens_details.reasoning_tokens; an unmapped response field is dropped with no warning, so omitting it silently loses the breakdown.make buildenforces this and names the provider and flavor.openai.yml'schatextractor is the reference shape to copy for any OpenAI-compatible provider —huggingface_*.ymlandovhcloud.ymlare generated copies of it. - Each extractor has an
api_flavorthat names the API whose responses it reads. A caller that doesn't pass a flavor asks fordefault; a provider with nodefaultextractor, such as OpenAI, raises an error instead. Sodefault, when a provider has one, should read the provider's own API, since that's what most callers send. Give every other API the provider serves its own flavor name. Example: Anthropic's own API is Messages, so Messages responses go underdefault, and its OpenAI-compatible endpoint goes underchat. OpenRouter passes along TypeSafe's System One API, which reports usage differently, so that goes undersystemone. If System One were under OpenRouter'sdefault, a response sent without a flavor would be read with System One's rules and lose its cached and reasoning token counts. One temporary exception: OpenRouter'sdefaultstill holds a copy of System One, because the gateway asks fordefaulttoday. Don't remove it until the gateway sendssystemone; the comment above it inopenrouter.ymlsays the same.
Adding a unit
Adding a unit to prices/units.yml is a v3 change, not a v2 price update. make build regenerates
prices/new_data/v2/data.schema.json from the registry, so adding a unit silently widens the published
v2 contract — and clients that haven't upgraded warn-and-drop the unknown key rather than failing, which
means silently under-priced usage in production. Nothing currently blocks this; the constraint is stated
in specs/data-driven-unit-registry/phase-1-static-unit-registry-release/code-spec.md and is a
maintainer responsibility. Read that spec first, and see the header comment in units.yml for the
closure rules.
Development Workflow
- Use
uvfor dependency management (not pip/conda),npmfor the JS workspace,gomodules forpackages/go/andcargoforpackages/rust/ make buildneeds a Go toolchain onPATH:package-datarunsgofmton the generateddata_units.go. It does not need a Rust toolchain: the generateddata_units.rsis excluded from rustfmt- The pre-commit
buildhook fires on any change underprices/and rewrites fourteen paths:prices/providers/.schema.json, the fourprices/new_data/v2/*files,data.py,data_units.py,data.ts,dataUnits.ts,packages/go/internal/data/prices.json,packages/go/data_units.go,packages/rust/data/prices.json,packages/rust/src/data_units.rs, plusREADME.md(provider list). Your firstgit commitwill abort after it rewrites them — re-stage the regenerated files and commit again. Never reach for--no-verify: that hook is the only thing keeping the published data in sync with the YAML. - Run
make buildafter editing anything underprices/ - Always run the full test suite before submitting changes
Testing
- Python tests use pytest and are in
tests/; JS tests are inpackages/js/src/__tests__/and run vianpm run ci; Go tests arepackages/go/*_test.goand run viamake test-go; Rust tests arepackages/rust/tests/*.rsand run viamake test-rust - CI and local
make testenforce 100% coverage acrosspackages/python/**,prices/src/**, andtests/**. CI and localmake test-goenforce 90% coverage ofpackages/go/, andmake test-rust95% line coverage ofpackages/rust/. - Never hand-edit
tests/dataset/usages.jsonor add synthetic feature cases to it. It is the cross-language golden dataset generated bytests/dataset/extract_usages.pyfrom recorded raw bodies; synthetic behavior belongs in focused Python, JavaScript, Go and Rust tests.tests/test_dataset.pycompares in memory and fails if the file is stale; regenerate withpython tests/dataset/extract_usages.pyand commit the diff. - Price changes are pinned by assertions in
tests/test_price_calc.py,tests/test_price_regressions.py,packages/js/src/__tests__/andpackages/go/api_test.go. Update the expected values; don't weaken or delete the assertion. - Use
make test-all-pythonto test across Python 3.11-3.15
Python/JS/Go/Rust parity
The four packages are independent implementations of the same behaviour and are the easiest place to
introduce drift. Any change to pricing, extraction, matching or unit handling must land in all four. The
runtime data updater and the CLI exist only in Python and JS; Go callers load fresh data with
NewCalculatorFromJSON and Rust callers with Calculator::from_json.
tests/dataset/usages.json is generated by Python and asserted by JS, Go (packages/go/dataset_test.go) and Rust
(packages/rust/tests/dataset.rs),
so it catches arithmetic drift on the models real data covers — but it pins a single UTC instant and only the
units shipped prices use, so it does not catch constraint-resolution, matching, warning or error-shape divergence.
packages/go/parity_test.go covers matching, constraint resolution, tiered pricing, usage decomposition and
usage extraction for Go against synthetic provider data. It asserts hardcoded expectations, not the other
engines' output, so update it together with the matching Python and JS tests.
packages/rust/tests/parity.rs is a port of it; keep the two in step. Where the engines disagree, Rust follows
Python, the reference: it does not trim model references, looks up a provider ID or API URL that is set but blank,
lets a provider ID win over an API URL, and only routes LiteLLM for an untrimmed litellm ID, all unlike Go.
The Rust tests mark each of these where they differ from parity_test.go. Rust ports the Go price
pins that exercise engine behaviour (tier and batch variants, long-context boundaries, API-URL matching, array-match
extraction) in packages/rust/tests/price_context.rs and packages/rust/tests/api.rs, but not the per-model pins;
when a ported pin's price changes, update the Go and Rust expectations together.
Code Style
- Code formatted with ruff (single quotes, 120 char line length)
- Type checking with basedpyright in strict mode
- Follow existing patterns in the codebase
Releasing
Create a GitHub release with a vX.Y.Z tag; CI publishes the Python and JS packages from it and creates the
matching packages/go/vX.Y.Z tag for the Go module. The version lives only in the tag -
packages/python/pyproject.toml is dynamic (uv-dynamic-versioning) and the 0.0.0 in
packages/js/package.json is a placeholder the release job overwrites. Never add a version bump to a PR. See
RELEASE.md.
Pull Requests
After opening or updating a PR, don't go idle until it's genuinely in its desired end state. After pushing, poll (~every 30s) until both:
- CI is green, and
- every reviewer comment (cubic included) is addressed or explicitly dismissed.
A PR with unresolved review threads is not mergeable. Resolve each one — fix and reply, or dismiss with a reason — except threads left intentionally as informational (not meant to be resolved).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

