- Google Gemini (AI SDK) का उपयोग करके AI conversations संचालित करता है
- token usage को automatically track करता है (किसी manual code की आवश्यकता नहीं)
- actual token consumption के आधार पर customers से charge करता है
- एक सुंदर chat interface शामिल करता है

हम क्या बनाएँगे
पहले अपनी AI chat service को समझते हैं:- Service: Google Gemini (AI SDK) का उपयोग करने वाली AI-powered chat
- Pricing Model: Pay-per-token ($0.01 प्रति 1,000 tokens)
- Free Tier: प्रति customer प्रति माह 10,000 free tokens
- Features: Conversation history, automatic token tracking
- एक Dodo Payments account
- Google AI API key (aistudio से प्राप्त करें)
- Node.js v16+ installed
Step 1: अपना Usage Meter बनाएँ
हम आपके Dodo Payments dashboard में एक meter बनाकर शुरू करेंगे, जो AI token usage को track करेगा।Open the Meters section
- अपने Dodo Payments dashboard में log in करें
- बाएँ sidebar में Products पर click करें
- Meters पर click करें
- Create Meter button पर click करें

Fill in the basic meter information
AI Token Usage MeterDescription → Tracks token consumption from AI chat conversations using AI SDKEvent Name → ai_chat_usageConfigure how we count tokens
totalTokensMeasurement Unit: Type → tokenstotalTokens भेजता है।Create your meter
- जाँच लें कि आपकी सभी settings ऊपर दिए गए values से match करती हैं
- Create Meter पर click करें

Step 2: अपनी API Keys प्राप्त करें
App बनाने से पहले आवश्यक API keys एकत्र करते हैं।Get Dodo Payments API Key
- अपने Dodo Payments dashboard में Developers → API Keys पर जाएँ
- Create API Key पर click करें
- API key copy करें—यह
test_abc123...जैसी दिखाई देगी
.env file में जोड़ेंगे।Get Google AI API Key
- aistudio.google.com पर जाएँ
- Get API Key पर click करें
- नई API key बनाएँ या मौजूदा key का उपयोग करें
- Key copy करें
.env file में जोड़ेंगे।Step 3: अपना Billing Product बनाएँ
अब हमें ऐसा product बनाना है जो हमारी pricing ($0.01 प्रति 1,000 tokens और 10,000 free tokens) define करे। इससे हमारा meter actual billing से connect होगा।Navigate to Products
- अपने Dodo Payments dashboard में बाएँ sidebar के Products पर click करें
- Create Product पर click करें
- Product type के रूप में Usage-Based चुनें
Enter product details
AI Chat ServiceDescription: → AI-powered chat service with automatic token-based billingProduct Image: संबंधित image upload करेंConnect your meter
0 पर set करें, ताकि customers से केवल उनके usage के आधार पर charge हो और कोई base fee न हो।अब आपके द्वारा बनाए गए meter को link करें:- नीचे scroll करके Associated Meter section पर जाएँ
- Add Meters पर click करें
- dropdown से “AI Token Usage Meter” चुनें (जिसे आपने पहले बनाया था)
- पुष्टि करें कि यह आपके product configuration में दिखाई दे रहा है
Set your pricing
0.00001 दर्ज करें (यह 1,000 tokens के लिए 0.00001 है)Free Threshold: → 10000 दर्ज करें (customers को प्रति माह 10,000 free tokens मिलेंगे)
Save your product
- अपनी सभी settings की समीक्षा करें:
- Name: AI Chat Service
- Meter: AI Token Usage Meter
- Price: $0.01 प्रति 1,000 tokens
- Free tier: 10,000 tokens
- Save Changes पर click करें
Step 4: Test Purchase करें
App बनाना शुरू करने से पहले purchase करके एक test customer बनाएँ।Get your payment link
- अपने Dodo Payments dashboard में Products पर जाएँ
- अपना “AI Chat Service” product खोजें
- Product के पास Share button पर click करें
- दिखाई देने वाले payment link को copy करें
Complete a test purchase
- Payment link को नए browser tab में खोलें
- Test payment details दर्ज करके purchase पूरा करें
Find your customer ID
- अपने Dodo Payments dashboard पर वापस जाएँ
- बाएँ sidebar में Sales -> Customers पर जाएँ
- अभी बनाए गए customer को खोजें (test email वाला)
- Customer ID copy करें—यह
cus_123जैसी दिखाई देगी
Step 5: Chat Application बनाएँ
अब हमारा billing setup complete है और एक test customer भी बनाया जा चुका है। अब automatic token tracking वाली AI chat application बनाएँ।Set up your project
Install dependencies
Configure TypeScript
tsconfig.json बनाएँ:package.json update करें:Create project structure
Set up environment variables
.env file बनाएँ:Create the backend server
src/server.ts बनाएँ और यह complete server code copy करें:Step 6: Chat Interface जोड़ें
अब full conversation history वाला सुंदर chat interface जोड़ें!public/index.html बनाएँ:
Step 7: अपनी Chat Application Test करें
अब अपनी AI chat app को test करने और billing को action में देखने का समय है! सुनिश्चित करें कि सब कुछ end-to-end काम कर रहा है।Start the server
- Verify करें कि आपकी
.envfile में Step 2 की सभी API keys हैं - Development server शुरू करें:
Open the chat interface
- अपना browser खोलें
http://localhost:3000पर जाएँ- आपको सुंदर chat interface दिखाई देना चाहिए
server.ts में CUSTOMER_ID को Step 4 की अपनी actual test customer ID से update करें।Have your first conversation
- “Artificial intelligence क्या है?”
- “Machine learning कैसे काम करती है?”
- “क्या आप neural networks समझा सकते हैं?”
Check your Dodo Payments dashboard
- अपना Dodo Payments dashboard खोलें
- Usage Billing → AI Token Usage Meter पर जाएँ
- Events tab पर click करें
- आपको अपने chat events की सूची दिखाई देनी चाहिए
- Event names:
ai_chat_usage - Customer ID: आपकी test customer id

Verify token counting
- अपने meter में Customers tab पर जाएँ
- अपना test customer खोजें
- “Consumed Units” column देखें—इसमें उपयोग किए गए total tokens दिखाई देने चाहिए

totalTokens values का योग automatically कर रहा है!Test the free tier
- कई और conversations करें (कुल ~15,000+ tokens का लक्ष्य रखें)
- Meter dashboard में अपने Customers tab को फिर से देखें
- अब आपको यह दिखाई देना चाहिए:
- Consumed Units: 15,000+ tokens
- Chargeable Units: 5,000 (10,000 free tokens लागू)
- Total Price: ~$0.05

Troubleshooting
सामान्य समस्याएँ और उनके solutions:Events not appearing in dashboard
Events not appearing in dashboard
- Event name meter configuration से exactly match नहीं करता
- Customer ID आपके account में मौजूद नहीं है
- API key invalid या expired है
- Network connectivity issues
- Verify करें कि event name meter configuration से exactly match करता है (case-sensitive:
ai_chat_usage) - जाँचें कि customer ID Dodo Payments dashboard में मौजूद है
- Simple API call से API key test करें
- Error messages के लिए server logs देखें
Token counts showing zero
Token counts showing zero
- Model usage information return नहीं कर रहा
- Incorrect SDK version
- Test करें कि model usage return करता है या नहीं:
- Latest Blueprints SDK पर update करें:
npm install @dodopayments/ingestion-blueprints@latest
API key invalid error
API key invalid error
- Environment के लिए गलत API key
.envfile में extra spaces या quotes
- सुनिश्चित करें कि test key
test_से शुरू होती है और live keylive_से .envfile में keys के आसपास के quotes हटाएँ- आवश्यकता होने पर नई key generate करें