- Generates images using OpenAI’s DALL-E API
- Tracks every image generation for billing
- Charges customers automatically based on usage
- Handles different quality tiers (standard vs HD)
What We’re Building
Let’s start by understanding our PixelGen AI service:- Service: AI image generation using OpenAI’s DALL-E API
- Pricing Model: Pay-per-image ($0.05 per image)
- Free Tier: 10 free images per customer per month
- Quality Options: Standard and HD images (same price for simplicity)
- A Dodo Payments account
- Access to OpenAI’s API
- Basic familiarity with TypeScript/Node.js
Step 1: Create Your Usage Meter
We’ll start by creating a meter in your Dodo Payments dashboard that will track every image our service generates. Think of this as the “counter” that tracks billable events.
Open the Meters section
- Log into your Dodo Payments dashboard
- Click on Meters in the left sidebar
- Click the Create Meter button
Fill in the basic meter information
Image Generation MeterDescription: Copy this → Tracks each AI image generation request made by customers using our DALL-E powered serviceEvent Name: This is crucial - copy exactly → image.generatedConfigure how we count images
imagesAdd quality filtering

- Enable Event Filtering: Toggle this ON
- Filter Logic: Select OR (this means “count if ANY of these conditions are true”)
- Add the first condition:
- Property Key:
quality - Comparator:
equals - Value:
standard
- Property Key:
- Click “Add Condition” for the second one:
- Property Key:
quality - Comparator:
equals - Value:
hd
- Property Key:
Create your meter
- Double-check all your settings match the values above
- Click Create Meter
Step 2: Create Your Billing Product
Now we need to create a product that defines our pricing ($0.05 per image with 10 free images). This connects our meter to actual billing.Navigate to Products
- In your Dodo Payments dashboard, click Products in the left sidebar
- Click Create Product
- Select Usage-Based as the product type
Enter product details
PixelGen AI - Image GenerationDescription: Copy this → AI-powered image generation service with pay-per-use billingProduct Image: Upload a clear, relevant image.Connect your meter

0 to ensure customers are only charged based on their usage, with no base fee.Now, link the meter you just created:- Scroll down to the Associated Meter section
- Click Add Meters
- From the dropdown, select “Image Generation Meter” (the one you created earlier)
- Confirm that it appears in your product configuration
Set your pricing

0.05 (this is $0.05 per image)Free Threshold: Enter → 10 (customers get 10 free images per month)Save your product
- Review all your settings:
- Name: PixelGen AI - Image Generation
- Meter: Image Generation Meter
- Price: $0.05 per image
- Free tier: 10 images
- Click Save Changes
Step 3: Make a Test Purchase
Before we start ingesting usage events, we need to make a test purchase.Get your payment link
- In your Dodo Payments dashboard, go to Products
- Find your “PixelGen AI - Image Generation” product
- Click the Share button next to your product
- Copy the payment link that appears
https://test.checkout.dodopayments.com/buy/pdt_IgPWlRsfpbPd5jQKezzW1?quantity=1Complete a test purchase
- Open the payment link in a new browser tab
- Enter test payment details and complete purchase.
Find your customer ID
- Torna alla tua dashboard di Dodo Payments
- Vai a Vendite → Clienti nella barra laterale
- Trova il cliente che hai appena creato (con l’email di test)
- Copia l’ID del cliente - sarà simile a
cus_abc123def456
Step 4: Build the Sample Application
Now we have our billing setup complete and a test customer created. Let’s build the sample PixelGen AI application that generates images and automatically tracks usage for billing.Set up your project
Install dependencies
Create the main application
index.ts and copy this complete application code:Step 5: Test Your Sample Application
Time to test our sample PixelGen AI service and see the billing in action! Let’s make sure everything works end-to-end.Set up your environment
- Create a
.envfile in yourpixelgen-aidirectory - Add your actual API keys:
- Install dependencies and run the app:
Generate your first test image
Generate a few more images
- “A sunset over mountains with purple clouds”
- “A steampunk coffee machine in a Victorian kitchen”
- “A friendly dragon reading a book in a library”
Check your Dodo Payments dashboard
- Open your Dodo Payments dashboard
- Go to Usage Billing → *Meters → Image Generation Meter
- Click on the Events tab
- You should see your image generation events listed
- Event names:
image.generated - Customer ID: Your test customer ID
Verify billing calculations

- In your meter, go to the Customers tab
- Find your test customer
- Check the “Consumed Units” column
Test the billing threshold
- Generate 8 more images (to reach 12 total)
- Check your meter dashboard again
- You should now see:
- Consumed units: 12
- Billable units: 2 (12 - 10 free)
- Billing amount: $0.10
Troubleshooting
Common issues and their solutions:Events not appearing in dashboard
Events not appearing in dashboard
- Event name doesn’t match meter configuration exactly
- Customer ID doesn’t exist in your account
- API key is invalid or expired
- Network connectivity issues
- Verify event name matches meter configuration exactly (case-sensitive)
- Check that customer ID exists in Dodo Payments
- Test API key with a simple API call
- Check network connectivity and firewall settings