Skip to main content

Use Cases

Explore common scenarios supported by the API Gateway Blueprint:

API-as-a-Service

Track usage per customer for API platforms and charge based on number of calls.

Rate Limiting

Monitor API usage patterns and implement usage-based rate limiting.

Performance Monitoring

Track response times and error rates alongside billing data.

Multi-Tenant SaaS

Bill customers based on their API consumption across different endpoints.
Ideal for tracking API endpoint usage, rate limiting, and implementing usage-based API billing.

Quick Start

Track API calls at the gateway level with automatic batching for high-volume scenarios:
1

Install the SDK

npm install @dodopayments/ingestion-blueprints
2

Get Your API Keys

3

Create a Meter

Create a meter in your Dodo Payments Dashboard:
  • Event Name: api_call (or your preferred name)
  • Aggregation Type: count for tracking number of calls
  • Configure additional properties if tracking metadata like response times, status codes, etc.
4

Track API Calls

import { Ingestion, trackAPICall } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'api_call'
});

// Track a single API call
await trackAPICall(ingestion, {
  customerId: 'customer_123',
  metadata: {
    endpoint: '/api/v1/users',
    method: 'GET',
    status_code: 200,
    response_time_ms: 45
  }
});

Configuration

Ingestion Configuration

apiKey
string
required
Your Dodo Payments API key from the dashboard.
environment
string
required
Environment mode: test_mode or live_mode.
eventName
string
required
Event name that matches your meter configuration.

Track API Call Options

customerId
string
required
The customer ID for billing attribution.
metadata
object
Optional metadata about the API call like endpoint, method, status code, response time, etc.

Batch Configuration

maxSize
number
Maximum number of events before auto-flush. Default: 100.
flushInterval
number
Auto-flush interval in milliseconds. Default: 5000 (5 seconds).

Best Practices

Use Batching for High Volume: For applications handling more than 10 requests per second, use createBatch() to reduce overhead and improve performance.
Always Clean Up Batches: Call batch.cleanup() on application shutdown to flush pending events and prevent data loss.
I