In this article, you will learn how to build a billing system with Lago based on tokens. This template is suitable for Large Language Model (LLM) and Generative AI companies whose pricing can vary based on the application or model used.Documentation Index
Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Pricing structure
For OpenAI, pricing depends on the language model used. Here are several price points they offer: “Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1,000 tokens is about 750 words (learn more here).”| Model | Input | Output |
|---|---|---|
| 8K context | $0.03 / 1,000 tokens | $0.06 / 1,000 tokens |
| 32K context | $0.06 / 1,000 tokens | $0.12 / 1,000 tokens |
Get started
Create a billable metric
Create a single billable metric to track token usage across different models and input/output types.Refer to the API reference and guide on filters to learn more.
- Add a unique
codefor your billable metric - Set
aggregation_typetosum_agg - Set
field_nametotokens - Set
recurringtofalse - Set
filtersto distinguish between models and token types
Create a plan
Create a plan to price packages of tokens used with OpenAI’s specific pricing tiers.Refer to the API reference and guide on charges with filters to learn more.
- Add a unique
codefor your plan - Under
charges, configure pricing tiers for different models and token types
Create a customer
Create a subscription
Create a subscription for the customer with the plan’s Refer to the API reference to create a subscription.
code.Ingest usage via events
Send usage events to Lago to track usage.Refer to the API reference to create an event.
- Reference your billable metric with
code - Reference the customer’s subscription with
external_subscription_id - Include usage and filters data in
properties
Monitor current usage
Track real-time customer usage for the current billing period.Refer to the API reference to get the current usage.