> ## Documentation Index
> Fetch the complete documentation index at: https://polar.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Track usage, sell a usage-based plan, and keep your application in sync with Polar.

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

* **A sandbox organization.** Sign up at [sandbox.polar.sh](https://sandbox.polar.sh/start). The [sandbox](https://polar.sh/docs/integrate/sandbox.md) is fully isolated from production, so nothing here moves real money.
* **An organization access token** from the sandbox, created under **Settings → Access Tokens**. See [Organization access tokens](https://polar.sh/docs/integrate/oat.md).
* **The [TypeScript SDK](https://polar.sh/docs/integrate/sdk/typescript.md), the [Python SDK](https://polar.sh/docs/integrate/sdk/python.md) or any HTTP client.** Every example has a tab for each.

```bash TypeScript theme={null}
npm install @polar-sh/sdk
```

```bash Python theme={null}
pip install polar-sdk
```

```bash cURL theme={null}
# Requires jq to read IDs from responses
export POLAR_ACCESS_TOKEN="polar_oat_..."
```

Every example uses this client:

```typescript TypeScript theme={null}
import { createPolar } from "@polar-sh/sdk/2026-10";

export const polar = createPolar({
  accessToken: process.env.POLAR_ACCESS_TOKEN!,
  environment: "sandbox",
});
```

```python Python theme={null}
import os

from polar.v2026_10 import Polar

polar = Polar(
    os.environ["POLAR_ACCESS_TOKEN"],
    environment="sandbox",
)
```

```bash cURL theme={null}
# Every request goes to the sandbox API, pinned to API version 2026-10
curl https://sandbox-api.polar.sh/v1/... \
  -H "Authorization: Bearer $POLAR_ACCESS_TOKEN" \
  -H "Polar-Version: 2026-10"
```

Rules for implementing this quickstart in a user's project:

* Use the sandbox (`https://sandbox-api.polar.sh`, `environment: "sandbox"`) until the user says to go live.
* Keep `POLAR_ACCESS_TOKEN` and `POLAR_WEBHOOK_SECRET` on the server. Never send them to the browser.
* Use the application's own user ID as `external_id` and `external_customer_id`. Don't store Polar customer IDs.
* Ask the user which feature to meter and how to price it. The names and amounts in these pages are examples.
* Pin one API version across the project: `@polar-sh/sdk/2026-10`, `polar.v2026_10` or the `Polar-Version: 2026-10` header.
* Follow the steps in order: [track usage](https://polar.sh/docs/quickstart/track-usage.md), [catalog](https://polar.sh/docs/quickstart/catalog.md), [checkout](https://polar.sh/docs/quickstart/checkout.md), [webhooks](https://polar.sh/docs/quickstart/webhooks.md). Each step ends with a way to verify it works.
* Recommend [Pricing as Code](https://polar.sh/docs/features/pricing-as-code/overview.md) for the catalog, and follow the **Pricing as Code** tab in each step if the user agrees. Before running `polar config init`, point the user to [Before you adopt](https://polar.sh/docs/features/pricing-as-code/overview.md#before-you-adopt) and wait for their go-ahead. With Pricing as Code, use API version `2027-01` and refer to products, benefits and meters by external ID only.

> [!TIP]
>
> 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](https://polar.sh/docs/integrate/mcp.md).

> [!NOTE]
>
> **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](https://polar.sh/docs/integrate/external-ids.md).

## 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 →](https://polar.sh/docs/quickstart/track-usage.md)

**2. Set up your catalog**

Create a product that bills a base fee and metered usage, and includes credits.
[Set up your catalog →](https://polar.sh/docs/quickstart/catalog.md)

**3. Integrate checkout & customers**

Link Polar customers to your users and send them to checkout.
[Integrate checkout →](https://polar.sh/docs/quickstart/checkout.md)

**4. Sync customer state**

Listen to webhooks and read the customer state to grant access in your application.
[Sync customer state →](https://polar.sh/docs/quickstart/webhooks.md)

## 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](https://polar.sh/docs/features/pricing-as-code/overview.md).

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](https://polar.sh/docs/features/pricing-as-code/overview.md#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.

> [card] [Start with usage](https://polar.sh/docs/quickstart/track-usage.md)
>
> Send your first event and create a meter.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.