Prerequisites: Start with Authenticate an Agent, then follow Route Traffic for the gateway path you chose.
MCP flow
The Lava MCP server handles gateway traffic routing. Billing setup (meters, plans, checkout) requires the SDK. A typical billing workflow:- SDK: Create a meter, plan, and checkout session (Steps 1–3 below)
- MCP:
loginto authenticate the gateway session - MCP:
promptorcallto route billable traffic through the gateway
SDK flow
Overview
The billing flow has four parts:- Meter - Defines how usage is priced (e.g., $3 per million tokens)
- Plan - A subscription that includes an optional monthly fee, credit allowance, and linked meters
- Checkout - An embedded flow where your customer subscribes and pays
- Forward tokens - Per-customer auth tokens that route traffic through the gateway with billing
Step 1: Create a Meter
A meter defines the pricing rules for a type of usage. For example, charging per token for AI model calls:Meter options
You can also add volume-based tiers for graduated pricing:
Step 2: Create a Plan
A plan ties together an optional recurring price, included credits, and one or more meters (product features included in your plan):The
meter_ids field links meters to the plan. You can link multiple meters to a single plan.Plan options
Example with credit bundles:
Step 3: Embed Checkout
Checkout is a two-step flow: your backend creates a session, your frontend opens it with the@lavapayments/checkout SDK.
Backend: Create a session
Frontend: Open checkout
onSuccess fires with the customerId.
The
checkout_session_token is an opaque token — do not try to construct URLs from it. Always use the SDK to open checkout.Step 4: Route Billable Traffic
Once a customer has completed checkout, generate forward tokens scoped to their customer ID and meter. Every request made with this token is tracked and billed against their subscription:Step 5: Monitor Customer Usage
Track usage and costs per customer:What’s Next?
Meters
Advanced meter configuration and pricing strategies
Checkout Guide
Checkout modes, completion handling, and webhooks
Webhooks
Get notified when customers subscribe, run low on balance, or cancel
SDK Reference
Full API for customers, subscriptions, and usage