Key concepts
Meter: Pricing rules for usage. Defines how you calculate cost: per token, per request, percentage markup, tiered pricing, etc. You wrap your billable operations with a meter to track usage. You might use one meter for all usage, or different meters for different features. Plan: A monthly subscription. Defines how much customers pay each month (e.g., $25/month) and whether unused credits roll over. The subscription amount becomes their usage budget. Plans link to one or more meters that determine how usage depletes the balance. Overage: When a customer uses more than their plan covers. If someone on a 30 worth of usage, they go $5 over. Lava auto-charges their card for overages so service isn’t interrupted. Checkout: A hosted payment flow where customers subscribe to your plan. They verify their phone, add a payment method, and fund their wallet. You can embed checkout in your app with a button, or send customers an email with a checkout link. Connection: A link between your app and a customer’s wallet. Created when a customer completes checkout. You use the connection to identify who to charge for each request. Forward token: A credential for each request. Combines your API key + connection + meter. Tells Lava who to charge and how to price it.Terminology note: In the SDK and API, plans are called “subscription configs” (
subscription_config_id) and meters are called “products” (product_secret). The dashboard uses “plan” and “meter.”How meters and plans work together
Meters define pricing. Plans set the monthly budget and link to meters. Example:- You create a meter set to $0.02 per 1K tokens
- You wrap your AI calls (OpenAI, Claude, Gemini, etc.) with that meter
- You create a $25/month plan and attach the meter
- Customer subscribes to the plan
- Each request costs tokens × 25 balance
- If they exceed $25, Lava auto-charges for the overage at the same meter rate
Path 1: Gateway + Billing
Your app calls AI providers (OpenAI, Claude, Gemini, Mistral, etc.) through Lava instead of directly. We see every request, track usage, and charge the customer in real time.Step 1: Create a meter
Go to Dashboard → Meters → Create Meter. A meter defines how you price usage:- Fixed fee: e.g., $0.02 per 1K tokens
- Percentage markup: e.g., 20% on top of provider costs
- Tiered pricing: Volume discounts at higher usage
- Billing basis: Charge for input+output tokens, output only, characters, etc.
product_secret in code).
Step 2: Route your AI calls through Lava
If you’re building something new, make your AI calls through Lava from the start. If you’re already calling AI providers, swap out those calls to route through Lava instead.?u= parameter.
You can organize meters however makes sense:
- One meter for all AI calls
- One meter per feature (e.g., “chat” vs “summarization”)
- One meter per provider
- One meter per product tier
connectionSecret comes from checkout (next steps). For now, you can test with your self-forward token from the dashboard.
Step 3: Create a plan
Go to Dashboard → Plans → Create Plan. A plan defines the monthly subscription:- Name: What customers see (e.g., “Pro Plan”)
- Amount: Monthly charge (e.g., $25.00), this becomes their usage credit
- Rollover: Whether unused credits carry to next month
- Meters: Select which meters track usage against this plan
Step 4: Add checkout to your app
There are two ways to get customers through checkout: Option A: Embed checkout in your app (most common) Install the checkout library:When a customer completes checkout, they’ll:
- Verify their phone number
- Add a payment method (for overages and renewal)
- Subscribe to your plan
connectionSecret in your metered AI requests from Step 2.
Step 5: Verify it worked
Go to Dashboard → Requests to see requests with cost breakdown. Go to Dashboard → Connections to see customer balances. Lava:- Forwards requests to the provider
- Tracks token usage
- Calculates cost using your meter pricing
- Deducts from the customer’s plan balance
- If balance hits zero, auto-charges their card for overages
Path 2: Post-Request + Billing
You track usage yourself and report it to Lava. This works for AI calls, but also for any billable operation: API requests, database queries, compute time, file storage, or any cost you want to pass through. This path is common when you bring your own API keys (BYOK) and want Lava to handle billing while you call providers directly.Step 1: Create a meter
Dashboard → Meters → Create Meter. For non-AI usage, you’ll typically use:- Per-request pricing: e.g., $0.001 per API call
- Fixed fee: e.g., $0.05 per operation
- Tiered pricing: Volume discounts
Step 2: Report usage after each operation
After each billable operation, report it to Lava:Usage fields reference
| Field | Type | Use case |
|---|---|---|
request_id | string (required) | Idempotency key to deduplicate requests |
connection_secret | string (required) | Identifies which customer wallet to charge |
product_secret | string (required) | Determines which meter/pricing rules apply |
input_tokens | integer | LLMs (GPT-4, Claude, etc.) |
output_tokens | integer | LLMs - typically priced higher than input |
input_characters | integer | TTS, translation, embeddings |
output_characters | integer | Text generation APIs |
input_seconds | float | Speech-to-text, media processing |
output_seconds | float | TTS, voice synthesis, video generation |
metadata | object | Optional data for filtering/analytics |
Examples by use case
LLM (OpenAI, Claude, etc.)connectionSecret comes from checkout (next steps).
Step 3: Create a plan
Dashboard → Plans → Create Plan. Attach the meter(s).Step 4: Add checkout to your app
Same as Path 1. Embed a checkout button or send a checkout link via email. When checkout completes, save the connection ID and retrieve the connection secret to use in your usage reporting from Step 2.Step 5: Verify it worked
Same as Path 1. Check Dashboard → Requests and Dashboard → Connections.Terminology
| Dashboard | SDK / API | Used for |
|---|---|---|
| Meter | Product | Request pricing |
| Meter secret | product_secret | Forward tokens, reporting usage |
| Plan | Subscription Config | Checkout (what customers subscribe to) |
| Plan ID | subscription_config_id | Creating checkout sessions |
Next steps
Why Gateway Routing?
Understand the benefits of routing AI calls through Lava vs post-request reporting
Checkout Integration
Deep dive into checkout customization and webhook handling
Pricing Configuration
Configure tiered pricing, markups, and fee structures
Forward Proxy
Learn more about routing requests through Lava’s proxy