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 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
sum
to add up token counts - Over Property: Choose what to track:
inputTokens
- Track input/prompt tokens onlyoutputTokens
- Track output/completion tokens onlytotalTokens
- 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 testinglive_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: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
AI SDK (Vercel)
AI SDK (Vercel)
Track usage with the Vercel AI SDK for universal LLM support.Tracked Metrics:
- Native AI SDK usage format
- Automatically normalized to standard format
- Model name
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 usedoutputTokens
- Number of output/completion tokens usedtotalTokens
- 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
Your Dodo Payments meter uses the
metadata
fields (especially totalTokens
, inputTokens
, or outputTokens
) to calculate usage and billing.