Skip to main content
Why start here? Events are the raw record of what customers do. Send them early and you’ll have real usage data, whether you charge for it or not. See Usage.
In this step you’ll send events for an AI feature and create a meter that sums the tokens each customer uses. The examples use the sandbox client from the quickstart overview, on API version 2026-10.

Send your first event

Send an event whenever a customer does something you want to measure, whether you’ll bill for it, limit it or just track it. Identify the customer with your own user ID as external_customer_id (see External IDs):
track() adds the event to the SDK’s queue and returns. The SDK sends queued events in batches in the background. flush() waits until they’re delivered, and in Python leaving the async with block does the same. In Python, track() is only on the async client, PolarAsync. See Send events for running the queue in a server or serverless function. You don’t need to create the customer first. Polar accepts the event now, and links it to the customer once one exists with external_id set to user_123. You’ll do that in step 3.
Send raw facts, like the tokens used by one request, not running totals. Polar does the aggregation, so the same events can feed several meters later.
For LLM calls, streams and S3 uploads, an ingestion strategy can send these events for you.

Create a meter

A meter selects events with a filter and aggregates them into usage. Create one that sums total_tokens across ai_usage events:
  • Open Catalog → Meters
  • Click Create Meter
  • Set Name to “AI tokens”
  • Under Filters, add a condition: Name equals ai_usage
  • Set Aggregation to Sum over the property total_tokens
  • Click Create Meter
Metadata keys are used directly as properties, without a metadata. prefix. Polar backfills a new meter from events you’ve already sent, so your first event counts. Save the meter’s ID as POLAR_METER_ID in your application’s environment. You’ll use it in step 2 and to check balances in step 4. In the dashboard, open the AI tokens meter and click Copy meter ID. The CLI example exports it already.
Using Pricing as Code? Skip this and refer to the meter by its external ID, ai_tokens. A Polar ID changes when a new catalog version changes the meter, but the external ID stays the same across versions.

Verify it works

Read the meter’s usage for user_123. It includes the 77 tokens from your event.
  • Open Catalog → Meters
  • Select AI tokens
  • Open the Customers tab to see usage per customer, or Events to see the event you sent

Learn more

Next: Set up your catalog

Turn this meter into a price, and include credits in a plan.