polar config commands that create, check, draft and publish it. Read the overview for what Pricing as Code changes for your organization, and Versioning for how drafts, versions and existing customers work.
Create the config
Install the Polar CLI, sign in to your sandbox organization and runinit:
Terminal
init writes the file from your current catalog. A new organization starts from scratch.
- Format: TypeScript in a project with a
package.json, for whichinitalso installs@polar-sh/config, and JSON otherwise. Pass--format tsor--format jsonto choose. - External IDs:
initsuggests an external ID for each existing resource that doesn’t have one, and asks you to confirm it. - Skipped resources:
initlists anything it left out of the file, and those stay on Polar as they are.
Write the config
A config holds at most 100 meters, 100 benefits, 100 products and 100 custom fields. For what can’t be in a config yet, see Before you adopt.
The examples below are small. For every option, read the types of
@polar-sh/config, or with a JSON config let polar config validate tell you which field is wrong and which values it accepts.
- TypeScript
- JSON
Each section is a function that receives its helpers and returns the entries by external ID.The package is fully typed. A wrong helper, or a meter or benefit key that does not exist, is a type error.
polar.config.ts
- Never rename an external ID. Changing it removes the old resource and creates a new one, so change the name when you want customers to see something different.
- A section you leave out is left alone, so a file without
metersdoesn’t touch your meters. - A section you include is complete. A product missing from
productsis left out of the next catalog version, and an empty list takes every product off sale.validatelists each one as removed, but nothing is deleted and customers keep what they have.
Organization settings
An optionalsettings section holds organization-wide settings: payments, subscriptions, the Customer Portal and customer notifications. Keys are camelCase in TypeScript and snake_case in JSON.
One trade-off: a file with settings describes every setting, so any setting it leaves out goes back to its default, and validate shows that reset as a change. Leave the section out entirely to keep your settings as they are.
Check, draft and publish
1
Check what would change
Terminal
validate lists every entry as created, updated, unchanged or removed, with the old and new value of each changed field. It also reports errors and warnings with their location in the file.2
Save the draft
Terminal
draft shows the same plan, asks you to confirm, then saves the file to the draft catalog. Nothing a customer sees changes.3
Publish
Terminal
publish makes the draft the live catalog and needs the owner or admin role.draft again before you publish. publish warns you when the file has changes the draft doesn’t. You can name the version with --name on either command. Existing customers keep the version they bought, see What existing customers keep.
When the draft and the file disagree
draft stops with a conflict when the draft on Polar has changes your file lacks, such as a teammate’s changes that were never committed to the config file. Pick one:
Sandbox and production
Sandbox and production are separate organizations with separate catalogs, but the file doesn’t record which one it belongs to, so the same file works for both. Check which organization is active withpolar auth whoami, or pass --org to target one for a single command.
Generate types
Supported languages: Pythongenerate only writes Python. Skip this section if you have a TypeScript config, which is already type-checked as you write it.Terminal
polar_types.py:
- Run it again after every change to the config and commit the file. Don’t edit it by hand.
polar config generate --checkwrites nothing and fails when the file is missing or out of date.
Deprecate and prune
You can’t remove a product from the file while customers still use it:validate reports it as an error. Mark it deprecated instead, then draft and publish:
Terminal
prune removes every deprecated entry nothing uses any more. It only edits your file and changes nothing on Polar.
Change what a meter counts
Polar rejects a change to the filter or aggregation of a meter with billed usage. Add a new meter under a new external ID, point your prices and benefits at it, and deprecate the old one.Run it in CI
CI can show every pricing change on its pull request and release it when the pull request merges.1
Create two access tokens
CI signs in with two organization access tokens stored as repository secrets: a read-only one for pull requests and a write one for the main branch. Only an owner or admin can create them.Piping into
Terminal
gh secret set keeps the token off your screen.2
Add the workflow
This one is for GitHub Actions and a TypeScript config at the root of the repository.
.github/workflows/polar-config.yml
- On a pull request that changes the config,
validate --pr-commentposts what would change as one comment and updates it on every push. The job fails when the config has errors, so a broken config can’t merge. Pull requests from forks are skipped, because they get no secrets. - On a merge to main, it saves the draft and publishes it. Remove the
publishstep if a person should publish after the merge.
- JSON config: drop
npm ciand pointpathsatpolar.config.json. Addpolar config generate --checkto thevalidatejob if you generate types. - Sandbox organization: set
POLAR_ENVIRONMENT: sandboxon the steps that runpolar. - Approval before release:
environment: productionis a GitHub environment, so giving it a required reviewer makes every pricing change wait for a person’s approval after the merge. - Other CI systems:
--pr-commentalso works in Buildkite for a repository on GitHub. Elsewhere, run the same commands without it.

