Skip to main content
Pricing as Code means you manage your catalog from your repository instead of the dashboard. Your events, meters, benefits, products and custom fields live in one file, which the Polar CLI compares with what is on Polar before saving the difference as a draft and publishing it as a new version of your catalog. Pricing changes more often than it used to, because model prices and your own costs keep moving and your plans have to follow. Each change matters to finance and sales as much as to engineering, yet a dashboard edit has no review step. With Pricing as Code, a pricing change becomes a code change. It can be reviewed in a pull request, checked in CI and shipped as a new version that doesn’t touch existing customers.

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
You can opt in to Pricing as Code with a single command:
Terminal
or ask your agent to take it from here:
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, as polar.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 to polar 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.
Read Versioning for how versions work, what existing customers keep and how to deprecate a product.

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. Once polar 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.

Learn more