Skip to main content
In this quickstart you’ll build a complete usage-based billing integration. You’ll follow the same path as data through Polar: usage first, then pricing, then customers buying and your application reacting.

What you’ll build

  • Usage events flowing from your application into a meter
  • A subscription product with a base fee, metered usage and included credits
  • A checkout that links each purchase to the user in your application
  • A webhook handler that keeps your application in sync with each customer’s access

Prerequisites

Every example uses this client:
Prefer to let your agent do it? Run polar agent setup to connect Claude Code, Codex or Cursor to Polar, then ask it to follow this quickstart. See MCP.
Use your own user IDs. Every Polar customer can carry an external_id, set to the user’s ID in your application. The quickstart uses user_123 this way throughout, so you never store Polar’s customer IDs or map them back to your users. See External IDs.

The path

1

Track usage

Send events from your application and aggregate them with a meter. Start here, even before you’ve decided on pricing. Track usage →
2

Set up your catalog

Create a product that bills a base fee and metered usage, and includes credits. Set up your catalog →
3

Integrate checkout & customers

Link Polar customers to your users and send them to checkout. Integrate checkout →
4

Sync customer state

Listen to webhooks and read the customer state to grant access in your application. Sync customer state →

Why usage comes first

Events are raw facts about what customers do in your product. Polar stores every event and computes usage from them when you ask, so:
  • You can start sending events before you’ve settled on pricing, and decide later what to charge for, if anything.
  • Events sent with your own user ID are linked to the customer as soon as a customer with that external ID exists, even if the events came first.
  • New meters work on events you’ve already sent, so you see real usage the moment you create them.
The sooner events flow, the more real data you have when you set your prices.

Manage your Pricing as Code Beta

Every step that creates part of your catalog has a Pricing as Code tab. We recommend it: your meters, benefits and products live in a billing config in your repository, change through a pull request and ship as a new catalog version, while existing customers keep the version they bought. See Pricing as Code. With Pricing as Code, your code refers to products, benefits and meters by external ID, such as pro or ai_tokens, and never by Polar ID, which changes when you publish a new version. Looking them up by external ID needs API version 2027-01, so the checkout and customer state steps show a 2027-01 example for it. Read Before you adopt first. The config becomes the only way to change your catalog, it can’t be turned off once a publish has replaced your live catalog, and some benefit types and prices aren’t supported yet.

Start with usage

Send your first event and create a meter.