Documentation Index
Fetch the complete documentation index at: https://narev.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Polar billing platform integration
Use this guide after your framework-level integration is complete. This page covers Polar-specific setup:- Create the
@ai-billing/polardestination. - Map usage events to Polar customers.
- Sync user identity with
externalId.
Install polar dependencies
Configure environment variables
Set these on your server:sandbox until your metering flow is verified.
Create Polar billing destinations
Createlib/ai/destinations.ts:
lib/ai/destinations.ts
externalCustomerIdKey: 'userId'. Your billing tags must include userId.
Sync Polar customers on signup
Createlib/polar-client.ts:
lib/polar-client.ts
Required tag contract
In your generation routes, include:userIdinai-billing-tagsmust match PolarexternalId.- Each user should have one Polar customer record.
Verify polar metering
- Register a new user and confirm a Polar customer exists with
externalId = userId. - Trigger a model call and confirm an event named
llm_usageappears. - Validate metadata contains
userId,modelId, and route context. - Confirm your environment uses the expected Polar server (
sandboxorproduction).
Common issues
Events appear but don’t map to customers
- Confirm
userIdexists inai-billing-tags. - Confirm destination uses
externalCustomerIdKey: 'userId'. - Confirm customer creation uses
externalId = userId.
No events arrive in Polar
- Confirm
POLAR_ACCESS_TOKENis present at runtime. - Confirm
POLAR_SERVERmatches the Polar workspace you are checking. - Confirm framework routes call the billing-wrapped model helper.