Saltar al contenido principal

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:
  1. Login to Dodo Payments Dashboard
  2. Navigate to Products → Meters
  3. Click “Create Meter”
  4. 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
      • 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).
For detailed instructions, see the Usage-Based Billing Guide.
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:
apiKey
string
requerido
Your Dodo Payments API key. Get it from the API Keys page.
environment
string
requerido
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.
eventName
string
requerido
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:
client
object
requerido
Your LLM client instance (OpenAI, Anthropic, Groq, etc.).
customerId
string
requerido
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.
metadata
object
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:
Track usage with the Vercel AI SDK for universal LLM support.
Tracked Metrics:
  • inputTokensinputTokens
  • outputTokens + reasoningTokensoutputTokens
  • totalTokenstotalTokens
  • 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.
Track token usage across 200+ models via OpenRouter’s unified API.
Tracked Metrics:
  • prompt_tokensinputTokens
  • completion_tokensoutputTokens
  • total_tokenstotalTokens
  • Model name
OpenRouter provides access to models from OpenAI, Anthropic, Google, Meta, and many more providers through a single API.
Track token usage from OpenAI’s GPT models automatically.
Tracked Metrics:
  • prompt_tokensinputTokens
  • completion_tokensoutputTokens
  • total_tokenstotalTokens
  • Model name
Track token usage from Anthropic’s Claude models.
Tracked Metrics:
  • input_tokensinputTokens
  • output_tokensoutputTokens
  • Calculated totalTokens
  • Model name
Track ultra-fast LLM inference with Groq.
Tracked Metrics:
  • prompt_tokensinputTokens
  • completion_tokensoutputTokens
  • total_tokenstotalTokens
  • Model name
Track token usage from Google’s Gemini models via the Google GenAI SDK.
Tracked Metrics:
  • promptTokenCountinputTokens
  • candidatesTokenCount + thoughtsTokenCountoutputTokens
  • totalTokenCounttotalTokens
  • 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

event_id
string
Unique identifier for this specific event. Automatically generated by the SDK.Format: llm_[timestamp]_[random]
customer_id
string
The customer ID you provided when wrapping the client. Used for billing.
event_name
string
The event name that triggers your meter. Matches your tracker configuration.
timestamp
string
ISO 8601 timestamp when the event occurred.
metadata
object
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.

Última modificación el 1 de abril de 2026