Quick Start
Get started in 2 minutes with automatic token tracking.
API Reference - Events Ingestion
Complete API documentation for ingesting usage events.
API Reference - Meters
Learn how to create and configure meters for billing.
Usage-Based Billing Guide
Comprehensive guide to usage-based billing with meters.
Perfect for SaaS apps, AI chatbots, content generation tools, and any LLM-powered application that needs usage-based billing.
Quick Start
Get started with automatic LLM token tracking in just 2 minutes:1
Install the SDK
Install the Dodo Payments Ingestion Blueprints:
2
Get Your API Keys
You’ll need two API keys:
- Dodo Payments API Key: Get it from Dodo Payments Dashboard
- LLM Provider API Key: From AI SDK, OpenAI, Anthropic, Groq, etc.
Store your API keys securely in environment variables. Never commit them to version control.
3
Create a Meter in Dodo Payments
Before tracking usage, create a meter in your Dodo Payments dashboard:For detailed instructions, see the Usage-Based Billing Guide.
- Login to Dodo Payments Dashboard
- Navigate to Products → Meters
- Click “Create Meter”
- Configure your meter:
- Meter Name: Choose a descriptive name (e.g., “LLM Token Usage”)
- Event Name: Set a unique event identifier (e.g., llm.chat_completion)
- Aggregation Type: Select sumto add up token counts
- Over Property: Choose what to track:
- inputTokens- Track input/prompt tokens
- outputTokens- Track output/completion tokens (includes reasoning tokens when applicable)
- totalTokens- Track combined input + output tokens
 
 
The Event Name you set here must match exactly what you pass to the SDK (case-sensitive).
4
Track Token Usage
Wrap your LLM client and start tracking automatically:
That’s it! Every API call now automatically tracks token usage and sends events to Dodo Payments for billing.
Configuration
Tracker Configuration
Create a tracker once at application startup with these required parameters:Your Dodo Payments API key. Get it from the API Keys page.
The environment mode for the tracker.
- test_mode- Use for development and testing
- live_mode- Use for production
Always use 
test_mode during development to avoid affecting production metrics.The event name that triggers your meter. Must match exactly what you configured in your Dodo Payments meter (case-sensitive).
This event name links your tracked usage to the correct meter for billing calculations.
Wrapper Configuration
When wrapping your LLM client, provide these parameters:Your LLM client instance (OpenAI, Anthropic, Groq, etc.).
The unique customer identifier for billing. This should match your customer ID in Dodo Payments.
Use your application’s user ID or customer ID to ensure accurate billing per customer.
Optional additional data to attach to the tracking event. Useful for filtering and analysis.
Complete Configuration Example
Automatic Tracking: The SDK automatically tracks token usage in the background without modifying the response. Your code remains clean and identical to using the original provider SDKs.
Supported Providers
The LLM Blueprint works seamlessly with all major LLM providers and aggregators:AI SDK (Vercel)
AI SDK (Vercel)
Track usage with the Vercel AI SDK for universal LLM support.Tracked Metrics:
- inputTokens→- inputTokens
- outputTokens+- reasoningTokens→- outputTokens
- totalTokens→- totalTokens
- Model name
When using reasoning-capable models through AI SDK (like Google’s Gemini 2.5 Flash with thinking mode), reasoning tokens are automatically included in the 
outputTokens count for accurate billing.OpenRouter
OpenRouter
Track token usage across 200+ models via OpenRouter’s unified API.Tracked Metrics:
- prompt_tokens→- inputTokens
- completion_tokens→- outputTokens
- total_tokens→- totalTokens
- Model name
OpenRouter provides access to models from OpenAI, Anthropic, Google, Meta, and many more providers through a single API.
OpenAI
OpenAI
Track token usage from OpenAI’s GPT models automatically.Tracked Metrics:
- prompt_tokens→- inputTokens
- completion_tokens→- outputTokens
- total_tokens→- totalTokens
- Model name
Anthropic Claude
Anthropic Claude
Track token usage from Anthropic’s Claude models.Tracked Metrics:
- input_tokens→- inputTokens
- output_tokens→- outputTokens
- Calculated totalTokens
- Model name
Groq
Groq
Track ultra-fast LLM inference with Groq.Tracked Metrics:
- prompt_tokens→- inputTokens
- completion_tokens→- outputTokens
- total_tokens→- totalTokens
- Model name
Google Gemini
Google Gemini
Track token usage from Google’s Gemini models via the Google GenAI SDK.Tracked Metrics:
- promptTokenCount→- inputTokens
- candidatesTokenCount+- thoughtsTokenCount→- outputTokens
- totalTokenCount→- totalTokens
- Model version
Gemini Thinking Mode: When using Gemini models with thinking/reasoning capabilities (like Gemini 2.5 Pro), the SDK automatically includes 
thoughtsTokenCount (reasoning tokens) in outputTokens to accurately reflect the full computational cost.Advanced Usage
Multiple Providers
Track usage across different LLM providers with separate trackers:Use different event names for different providers to track usage separately in your meters.
Express.js API Integration
Complete example of integrating LLM tracking into an Express.js API:What Gets Tracked
Every LLM API call automatically sends a usage event to Dodo Payments with the following structure:Event Fields
Unique identifier for this specific event. Automatically generated by the SDK.Format: 
llm_[timestamp]_[random]The customer ID you provided when wrapping the client. Used for billing.
The event name that triggers your meter. Matches your tracker configuration.
ISO 8601 timestamp when the event occurred.
Token usage and additional tracking data:
- inputTokens- Number of input/prompt tokens used
- outputTokens- Number of output/completion tokens used (includes reasoning tokens when applicable)
- totalTokens- Total tokens (input + output)
- model- The LLM model used (e.g., “gpt-4”)
- provider- The LLM provider (if included in wrapper metadata)
- Any custom metadata you provided when wrapping the client
Reasoning Tokens: For models with reasoning capabilities, 
outputTokens automatically includes both the completion tokens and reasoning tokens.Your Dodo Payments meter uses the 
metadata fields (especially inputTokens, outputTokens or totalTokens) to calculate usage and billing.