Skip to main content
API Gateway Blueprint आपकी सेवा द्वारा संभाली जाने वाली प्रत्येक API call के लिए Dodo Payments को usage event भेजता है, और Count meter इन events को प्रत्येक customer के लिए प्रति-call charge में बदल देता है। इसका उपयोग API endpoint usage को track करने, rate limits के लिए जानकारी देने और API usage के लिए bill करने हेतु करें। यह @dodopayments/ingestion-blueprints npm package में trackAPICall() के रूप में उपलब्ध है, जो प्रत्येक call के लिए एक event भेजता है, और createBatch() के रूप में, जो high request volumes के लिए events को queue करता है।

उपयोग के मामले

API Gateway Blueprint इन scenarios के लिए उपयुक्त है:

API-as-a-Service

API platform पर प्रत्येक customer की calls को track करें और calls की संख्या के आधार पर charge करें।

Rate Limiting

Usage-based rate limits के लिए जानकारी देने हेतु प्रत्येक customer की call volume record करें। Blueprint usage record करता है, लेकिन limits लागू नहीं करता।

Performance Monitoring

प्रत्येक event के साथ response times और status codes record करें, ताकि error rates billing data के साथ दिखाई दें।

Multi-Tenant SaaS

विभिन्न endpoints पर customers के API consumption के लिए bill करें।
हर event के लिए उस customer की Dodo Payments customer ID आवश्यक होती है जिसे आप bill करते हैं, और यह cus_ से शुरू होती है। Customer create करते समय इसे अपने user record के साथ store करें और इसे customerId के रूप में pass करें।

त्वरित शुरुआत

API calls को track करने के लिए package install करें, meter create करें और प्रत्येक call के लिए एक event भेजें।
1

Install the SDK

Dodo Payments Ingestion Blueprints package install करें:
2

Get Your API Keys

Dodo Payments dashboard में Developer → API Keys के अंतर्गत Dodo Payments API key create करें और इसे DODO_PAYMENTS_API_KEY environment variable में store करें। Build करते समय test mode key का उपयोग करें। Test mode key केवल test_mode के साथ काम करती है।
3

Create a Meter

Dodo Payments dashboard में Products → Meters पर जाएँ और Create Meter पर click करें। ये fields set करें:
  • Meter Name: एक वर्णनात्मक name, जैसे API Calls।
  • Event Name: api_call या अपनी पसंद का कोई name। इसे आपके code में मौजूद eventName से बिल्कुल match करना चाहिए (case-sensitive)।
  • Aggregation Type: calls की संख्या के आधार पर bill करने के लिए Count।
  • Measurement Unit: invoices पर दिखाई जाने वाली unit, जैसे calls।
केवल कुछ calls को count करने के लिए Enable Event Filtering चालू करें और endpoint, method या status_code जैसी metadata keys पर conditions जोड़ें।
4

Track API Calls

अपनी API key और event name के साथ एक Ingestion instance create करें, फिर कोई pattern चुनें: प्रत्येक call के लिए एक event, high volume के लिए batch, या प्रत्येक request को track करने वाला Express.js middleware। Middleware में req.user आपके authentication middleware से आता है और इसका id Dodo Payments customer ID होना चाहिए। बिना signed-in user वाली requests को customer ID anonymous के साथ भेजा जाता है, जो किसी customer से match नहीं करती।

Configuration

Ingestion Configuration

new Ingestion() को ये options pass करें:
string
आवश्यक
Dashboard से प्राप्त आपकी Dodo Payments API key।
string
Environment mode: test_mode या live_mode। Default रूप से test_mode। Dodo Payments SDKs इसके बजाय default रूप से live_mode का उपयोग करते हैं, इसलिए production में live_mode को स्पष्ट रूप से set करें।
string
आवश्यक
आपके meter के Event Name से match करने वाला event name (case-sensitive)। यह instance द्वारा भेजे जाने वाले प्रत्येक event में उपयोग होता है।

API Call Options को Track करना

trackAPICall() और batch.add() को ये options pass करें:
string
आवश्यक
Call के लिए bill किए जाने वाले Dodo Payments customer ID, उदाहरण के लिए cus_123।
object
API call के बारे में optional metadata, जैसे endpoint, method, status code और response time। प्रत्येक value string, number या boolean होनी चाहिए। API nested objects, arrays और null values को reject करती है।

Batch Configuration

createBatch(ingestion, options) events को memory में queue करता है और तीन methods वाला object return करता है: add() एक event को queue करता है, flush() queued events भेजता है, और cleanup() उन्हें भेजकर timer को रोकता है। एक flush प्रत्येक event के लिए parallel रूप से एक ingest request भेजता है।
number
Queued events की वह संख्या जो immediate flush trigger करती है। Default: 100।
number
सबसे हाल के add() के बाद batch flush होने से पहले प्रतीक्षा करने का समय, milliseconds में। प्रत्येक add() timer को फिर से शुरू करता है। Default: 5000 (5 seconds)।

सर्वोत्तम अभ्यास

उच्च वॉल्यूम के लिए Batching का उपयोग करें: अधिक ट्रैफ़िक वाले एप्लिकेशन के लिए, createBatch() का उपयोग करें। batch.add() तुरंत रिटर्न करता है, इसलिए tracking आपके request handler में latency नहीं जोड़ता।
एक batch events को flush होने तक memory में रखता है और भेजने में विफल रहने वाले events को retry नहीं करता। Automatic flush error को console.error के साथ log करता है। flush() या cleanup() को call करने पर यह error throw होता है।
Shutdown पर Batches को Clean Up करें: Application बंद होने पर batch.cleanup() को call करें, ताकि pending events खोने के बजाय flush हो जाएँ।
अंतिम संशोधन 26 सितंबर 2026