- Generates images with OpenAI’s
gpt-image-2.5-flaremodel. - Tracks every image generation for billing.
- Charges customers for the images they generate.
- Handles two quality tiers,
mediumandhigh.
What We’re Building
PixelGen AI works like this:- Service: AI image generation with the OpenAI Image API
- Pricing Model: Pay per image ($0.05 per image)
- Free Tier: 10 free images per customer per month
- Quality Options:
mediumandhighquality images, at the same price
- A Dodo Payments account.
- Access to the OpenAI API. OpenAI may require API Organization Verification before you use GPT Image models.
- Node.js 22 or later, and working knowledge of TypeScript and Node.js.
Step 1: Create Your Usage Meter
Create a meter in the Dodo Payments dashboard that tracks every image the service generates. The meter counts the billable events.
Open the Meters Section
- Log in to the Dodo Payments dashboard.
- Go to Products → Meters in the sidebar.
- Click Create Meter.
Enter the Meter Details
Image Generation MeterDescription: Tracks each AI image generation request made by customers using our OpenAI image serviceEvent Name: image.generatedConfigure How Images Are Counted
imagesAdd Quality Filtering

- Turn on Enable Event Filtering.
- Set the match logic to OR, so an event counts when any condition matches.
- Add the first condition:
- Key:
quality - Operator:
equals - Value:
medium
- Key:
- Click Add condition and add the second one:
- Key:
quality - Operator:
equals - Value:
high
- Key:
Create Your Meter
- Check that every setting matches the values above. You can’t edit a meter after you create it.
- Click Create Meter.
Step 2: Create Your Billing Product
Create a product that defines the pricing: $0.05 per image, with 10 free images. The product connects the meter to billing.Navigate to Products
- In the Dodo Payments dashboard, click Products in the sidebar.
- Click Add Product.
- Under Pricing Type, select Usage Based Billing.
Enter Product Details
PixelGen AI - Image GenerationDescription: AI-powered image generation service with pay-per-use billingProduct Image: Upload a clear, relevant image.Connect Your Meter

0, so customers pay only for usage, with no base fee.Then link the meter you created:- Scroll to the Associated Meters section.
- Click Add meters.
- Select “Image Generation Meter” from the dropdown.
- Confirm that the meter appears in the product configuration.
Set Your Pricing

0.05, which is $0.05 per image.Free Threshold: 10. Each customer gets 10 free images per month.Save Your Product
- Review the 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
Buy the product once in test mode. The purchase creates the customer that the app sends usage events for.Get Your Payment Link
- In the Dodo Payments dashboard, go to Products.
- Find the “PixelGen AI - Image Generation” product.
- Click Share next to the product.
- Copy the payment link.
https://test.checkout.dodopayments.com/buy/pdt_IgPWlRsfpbPd5jQKezzW1?quantity=1.Complete a Test Purchase
- Open the payment link in a new browser tab.
- Enter test payment details and complete the purchase.
Find Your Customer ID
- Go back to the Dodo Payments dashboard.
- Go to Sales → Customers in the sidebar.
- Find the customer you created, by its test email address.
- Copy the customer ID. It looks like
cus_abc123def456.
Step 4: Build the Sample Application
With billing set up and a test customer created, build the sample PixelGen AI application. It generates an image and reports it to Dodo Payments for billing.gpt-image-2.5-flare model through the Image API. The Image API returns base64-encoded image data, so the sample saves each image as a PNG file. The Dodo Payments part (the meter, the product, and the image.generated usage event) doesn’t depend on the model.Set Up Your Project
Install Dependencies
Create the Main Application
index.ts and paste in the application code below..env and package.json:
Step 5: Test Your Sample Application
Test PixelGen AI end to end and watch the usage reach Dodo Payments.Set Up Your Environment
- Create a
.envfile in thepixelgen-aidirectory. - Add your API keys:
- Install the dependencies and run the app:
Generate Your First Test Image
sendUsageEvent prints are left out:Generate a Few More Images
npm start once per image, with these prompts:- “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 the Dodo Payments dashboard.
- Go to Products → Meters and open Image Generation Meter.
- Select the Events tab.
- Find your image generation events in the list.
- Event name:
image.generated - Customer ID: your test customer ID
Verify Billing Calculations

- In the meter, select the Customers tab.
- Find your test customer.
- Check the Consumed Units column.
Test the Billing Threshold
- Generate 8 more images, for 12 in total.
- Open the meter’s Customers tab again.
- Check the values:
- Consumed Units: 12
- Chargeable Units: 2 (12 − 10 free)
- Total Price: $0.10
Troubleshooting
Common problems and their fixes: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
- Check that the event name matches the meter exactly. It’s case-sensitive.
- Check that the customer ID exists in Dodo Payments.
- Test the API key with a simple API call.
- Check network connectivity and firewall settings.