Getting started
A billing config is managed through the Polar CLI. Install it, let it set up your agent if you want, and sign in to your sandbox organization:Terminal
Terminal
Prompt
What it looks like
At its core, a billing config is a JSON representation of your catalog: your meters, benefits, products and prices, and how they link to each other. That means it works from any language, aspolar.config.json.
In a JavaScript or TypeScript project, the config is polar.config.ts, written with @polar-sh/config. Say you’re building an AI assistant with a Pro plan at $20 per seat per month, and you want to track the tokens each customer uses:
polar.config.ts
events describes the shape of the events your app sends, meters adds them up per customer, and products is what you sell. Each entry’s key, such as pro or tokens, is its external ID. It stays the same across versions, which makes it what your code refers to.
Because the package is fully typed, a meter on an event you never declared, or a sum over a property the event doesn’t have, fails as a type error instead of showing up on an invoice. .withTokens() and .withCosts() declare the _llm and _cost properties that the LLM ingestion strategy sends with every model call, and that Cost Insights reads to show what each customer costs you next to what they pay.
For every option and the JSON format, see Billing config.
How it works
polar config init writes the billing config from the meters, benefits and products your organization already has, and turns Pricing as Code on. From then on, every change follows the same three commands:
Polar doesn’t read your repository. The CLI sends the file when you run
polar config draft, whether that’s from a terminal, from your agent or from CI.
Reviewable changes
Because the config is a file, a pricing change goes through the same review as any other change: a diff, a pull request and an approval. The change doesn’t have to start with an engineer, either. A founder, or someone in finance or sales, can ask an agent for it, and the agent edits the config and opens a pull request for an engineer to review and merge. Your pricing also lives in the same repository as the features it charges for, so one history shows when a feature shipped and when its price changed.polar config validate --pr-comment posts the plan on the pull request in GitHub Actions or Buildkite, so reviewers see which products, prices and benefits change, with their old and new values, before anything is drafted. Once it’s merged, run polar config draft --confirm && polar config publish --confirm from your deploy pipeline.
See Run it in CI.
Safe versioning
Every publish creates a new catalog version, named after what you pass topolar config draft --name, or v1, v2 and so on when you don’t name it.
- New checkouts sell the live version.
- Existing customers stay on the version they bought: same price, same benefits, same renewals.
- Polar IDs can change between versions, but external IDs don’t, so your code should refer to external IDs.
- A product with active subscriptions can’t be dropped from the file. Instead you mark it deprecated, so it stops being sold while its subscribers keep it.
Before you adopt
Pricing as Code changes how your whole organization manages its catalog, so know these trade-offs first. The dashboard and API become read-only for the catalog. Oncepolar config init turns Pricing as Code on, products, benefits, meters and custom fields can only change through the billing config, including for teammates who used to edit pricing in the dashboard.
Turning it off is possible only at first. polar config disable returns the catalog to the dashboard, but only until a publish replaces your live catalog. That’s your first polar config publish if your organization already had a catalog when you ran init, or your second if it started from scratch. After that, Pricing as Code stays on for the organization for good.
Not everything is covered yet. License key, file download, Discord and GitHub repository benefits can’t be in a config, and neither can pay-what-you-want prices. If your organization has any of them, polar config init stops and lists them.
Start in sandbox. Sandbox is a separate organization with its own catalog and versions, so you can try the whole flow there first. The same file works for both organizations.
Availability
Pricing as Code is in beta.@polar-sh/config follows semantic versioning from 1.0.0, so configs that work today will keep working, but expect more of the catalog to be covered and tighter SDK integrations as it develops.

