# How to Set Up Metered Billing for GPT Wrapper Apps

> Technical guide to implementing usage-based billing for GPT and LLM wrapper applications. Track API calls, ingest usage events, and bill customers based on actual consumption.
- **Author**: Ayush Agarwal
- **Published**: 2026-03-26
- **Category**: Payments, AI, How-To
- **URL**: https://dodopayments.com/blogs/metered-billing-gpt-wrapper

---

GPT wrappers are the most common new SaaS type today. They provide a layer of value over LLMs like OpenAI, Anthropic, or Google Gemini. However, many of these apps start with flat-rate pricing, which is a recipe for losing money. When each request has a real token cost, a single heavy user can wipe out your entire profit margin.

Flat pricing either overcharges light users or subsidizes heavy ones. If you charge $20 a month, a user who makes five requests is paying a massive premium, while a user who automates thousands of requests might cost you $50 in API fees. Metered billing solves this by aligning your revenue with your costs.

In this guide, we'll walk through how to implement metered billing for your AI application using Dodo Payments. We'll cover defining metered products, ingesting usage events, and handling the billing lifecycle.

## Why Metered Billing for AI?

The economics of AI SaaS are different from traditional software. In a standard CRUD app, the marginal cost of a user request is near zero. In an AI app, every request has a tangible cost in tokens.

> The billing model you choose in month one will constrain your pricing flexibility in year two. Build on infrastructure that supports subscriptions, usage, credits, and hybrid models from the start.
>
> \- Ayush Agarwal, Co-founder & CPTO at Dodo Payments

Usage varies 10-100x between users. A casual user might use your tool once a week, while a power user might integrate it into their daily workflow. If you don't track this usage, you're flying blind.

Metered billing allows you to:

- **Protect your margins**: Ensure you never pay more in API fees than you collect in revenue.
- **Scale with your users**: As your users grow and use your tool more, your revenue increases automatically.
- **Offer lower entry points**: You can offer a low base fee or even a "pay-as-you-go" model that attracts users who are hesitant to commit to a high monthly subscription.

For more on the strategic side of this, check out our post on [usage-based billing vs flat fees for AI SaaS](https://dodopayments.com/blogs/usage-based-billing-vs-flat-fees-ai-saas).

## Choosing Your Billing Metric

Before you write a single line of code, you need to decide what you're billing for. For a GPT wrapper, this is usually one of three things:

### 1. API Calls (Count)

This is the simplest model. You charge a flat fee per request, regardless of how many tokens are used. This works well if your prompts and responses are relatively consistent in length. It's easy for users to understand, but it carries the risk that a few very long responses could cost you more than the fee you collect.

### 2. Tokens (Sum)

This is the most accurate model. You charge based on the total number of tokens (input + output) consumed. This perfectly aligns your revenue with your costs from providers like OpenAI. While it's the most fair, it can be harder for non-technical users to visualize. A common solution is to present this as "credits" in your UI.

### 3. Compute Time (Sum)

If you're running your own models on GPUs or using a provider that bills by the second, you might bill based on the number of seconds or minutes of compute time used. This is common for image generation or video synthesis apps.

Most GPT wrappers choose tokens because it's the most transparent and fair metric for both the developer and the user.

## How Metered Billing Works with Dodo Payments

Dodo Payments makes it easy to implement [usage-based billing](https://docs.dodopayments.com/features/usage-based-billing/introduction). The process follows a simple flow:

1. **Define a Metered Product**: You create a product in the Dodo dashboard and define a "meter" (e.g., tokens used or API calls).
2. **Ingest Usage Events**: Every time a user makes an API call, your application sends a usage event to Dodo.
3. **Aggregation**: Dodo aggregates these events based on your configuration (Sum, Count, Max, etc.).
4. **Billing**: At the end of the billing period, Dodo calculates the total usage, generates an invoice, and processes the payment.

```mermaid
flowchart TD
    A[User Request] --> B[Process LLM Call]
    B --> C[Calculate Tokens Used]
    C --> D[Ingest Event to Dodo]
    D --> E[Dodo Aggregates Usage]
    E --> F[Period Ends]
    F --> G[Invoice Generated]
    G --> H[Payment Processed]
```

## Step-by-Step Implementation

### 1. Define Your Meter

First, you need to decide what you're billing for. For a GPT wrapper, this is usually either "API Calls" or "Tokens."

In the Dodo Payments dashboard, navigate to the Usage Billing section and create a new meter.

- **Event Name**: `gpt_request`
- **Aggregation Type**: `Sum` (if billing for tokens) or `Count` (if billing for requests).
- **Property Name**: `tokens_used` (if using Sum).

### 2. Create a Metered Product

Next, create a product and link it to your meter. You can set a base price (e.g., $10/month) and then a per-unit price for usage (e.g., $0.01 per 1,000 tokens). You can also include a free tier of usage within the base price. For example, the first 100,000 tokens could be included in the $10 base fee, with overage charged after that.

### 3. Ingest Usage Events

This is where the technical implementation happens. You need to send an event to Dodo every time a user consumes your service. The best way to do this is via a middleware or a post-processing step after your LLM call.

Here's an example using the [Dodo Payments TypeScript SDK](https://docs.dodopayments.com/developer-resources/sdks/typescript).

```typescript
import DodoPayments from "dodopayments";

const client = new DodoPayments({
  bearerToken: process.env["DODO_PAYMENTS_API_KEY"],
});

async function handleGptRequest(userId: string, prompt: string) {
  // 1. Call your LLM (e.g., OpenAI)
  const response = await openai.chat.completions.create({
    model: "gpt-4",
    messages: [{ role: "user", content: prompt }],
  });

  const tokensUsed = response.usage.total_tokens;
  const customerId = await getDodoCustomerId(userId);

  // 2. Ingest the usage event to Dodo
  await client.usageEvents.ingest({
    events: [
      {
        event_id: `req_${Date.now()}_${userId}`, // Unique ID for idempotency
        customer_id: customerId,
        event_name: "gpt_request",
        metadata: {
          tokens_used: tokensUsed.toString(),
          model: "gpt-4",
        },
      },
    ],
  });

  return response.choices[0].message.content;
}
```

### 4. Handling Idempotency

Notice the `event_id` field. This is crucial. If your application retries a request, you don't want to bill the user twice for the same usage. Dodo uses the `event_id` to ensure that each event is only counted once. Always generate a unique ID for every billable action. A combination of the request ID and the user ID is usually a safe bet.

## Advanced Billing Strategies

### Usage Caps and Alerts

One of the biggest fears users have with metered billing is a "surprise bill." To build trust, you should implement usage caps and alerts.

You can use Dodo's [webhooks](https://docs.dodopayments.com/developer-resources/webhooks) to monitor usage. While Dodo handles the billing, your application should track the current period's usage to show it in the UI.

When a user approaches a limit, send them an email or show a notification. If they hit a hard cap, you can pause their access until the next billing cycle or until they increase their limit. This is a key part of [billing UX and usage caps](https://dodopayments.com/blogs/billing-ux-usage-caps-alerts).

### Credit-Based Billing

For AI apps, [credit-based billing](https://docs.dodopayments.com/features/credit-based-billing) is often a better fit than pure metered billing. Instead of billing at the end of the month, users buy "credits" upfront.

As they use the app, credits are deducted. This is great for cash flow and reduces the risk of failed payments at the end of the month. Dodo supports this natively. You can link a meter to a credit balance, and Dodo will handle the deduction automatically. This model is very popular for AI tools because it feels like a "prepaid" phone plan, which users are already comfortable with.

Check out our guide on [billing credits and pricing cashflow](https://dodopayments.com/blogs/billing-credits-pricing-cashflow) for more details.

### Showing Real-Time Usage

Don't make users wait for their invoice to see what they've spent. Use the Dodo API to fetch a customer's current usage and display it in their dashboard.

```typescript
const usage = await client.usageEvents.list({
  customer_id: "cus_abc123",
  event_name: "gpt_request",
  start: currentPeriodStart,
  end: currentPeriodEnd,
});

// Calculate total from the list or use Dodo's aggregation endpoints
```

## Global Tax Compliance for AI SaaS

When you sell your AI app globally, you're suddenly responsible for VAT in the EU, GST in India, and sales tax in the US. This is a massive headache for a small team. Each country has different thresholds, filing requirements, and tax rates.

By using a [merchant of record for AI](https://dodopayments.com/blogs/saas-payments-merchant-of-record), you offload all of this. Dodo Payments acts as the legal seller of your service. We calculate, collect, and remit taxes in every country where your users are located. This means you don't have to register for VAT in 20 different countries just because you have a few users in each.

This is especially important for AI apps because your users can be anywhere. A developer in Brazil might use your tool just as much as a developer in Germany. Dodo ensures that every transaction is compliant, no matter where it happens. This allows you to focus on improving your LLM prompts instead of filling out tax forms in foreign languages.

## The Benefits of a Merchant of Record

Beyond tax compliance, a Merchant of Record (MoR) provides several other benefits for AI startups:

- **Localized Payment Methods**: Dodo supports UPI in India, Pix in Brazil, and local cards in 220+ countries and regions. This significantly increases conversion rates compared to only accepting US credit cards. In many emerging markets, credit card penetration is low, and local methods are the only way to get paid.
- **Fraud Protection**: We handle the risk of fraudulent transactions and chargebacks, which can be common in the AI space. Our systems are trained to spot suspicious patterns before they become a problem.
- **Simplified Payouts**: You get paid in your local currency, and we handle the cross-border transfers. This saves you money on exchange rates and wire transfer fees.

For more on why this matters, read our post on [monetizing AI](https://dodopayments.com/blogs/monetize-ai).

## How to Choose Your Billing Metric

Choosing the right metric is a balance between accuracy and simplicity.

### Tokens vs. Requests

Tokens are more accurate but harder for users to understand. Requests are simpler but can be risky if your costs vary wildly. A good middle ground is to use "credits" where 1 credit = 1,000 tokens. This makes the billing feel more tangible to the user while still being accurate for you. You can even show a "token to credit" conversion chart in your documentation.

### Tiered Usage

You can also implement tiered usage. For example:

- **Free**: 10,000 tokens/month
- **Pro**: $20/month for 1,000,000 tokens + $0.01 per 1,000 tokens overage.

This provides predictable revenue from the base subscription while still capturing the upside from heavy users. It's a "best of both worlds" approach that many successful AI companies use.

## Common Pitfalls to Avoid

- **Not tracking tokens**: If you bill per request but your costs are per token, you're still exposed to margin compression. Always try to bill on the metric that most closely matches your costs.
- **Ignoring failed events**: If your ingestion call to Dodo fails, you lose revenue. Implement a simple retry logic or a background worker to ensure events are eventually delivered.
- **Poor communication**: Metered billing requires transparency. If a user doesn't understand why they were charged $50 instead of $20, they will churn.
- **No usage visibility**: If users can't see their usage in real-time, they will feel anxious about their bill. Always provide a dashboard that shows their current consumption.
- **Forgetting about input tokens**: Many developers only think about the output tokens, but input tokens (the prompt) also cost money. Make sure your meter tracks the total tokens consumed.

## Conclusion

Implementing metered billing is the most effective way to build a sustainable AI business. It protects your margins, scales with your users, and provides a fair pricing model for everyone. It turns your variable costs into a predictable revenue stream.

By using a [merchant of record for AI](https://dodopayments.com/blogs/saas-payments-merchant-of-record) like Dodo Payments, you don't just get a billing engine. You get a partner that handles global tax compliance, localized payment methods, and the complexities of usage-based billing so you can focus on building your product.

Ready to start? Check out our [guide on implementing usage-based billing](https://dodopayments.com/blogs/implement-usage-based-billing) or dive into the [Dodo Payments documentation](https://docs.dodopayments.com).

## FAQ

### What is the difference between metered billing and usage-based billing?

Metered billing is a type of usage-based billing where usage is tracked (metered) and billed at the end of a period. Usage-based billing is a broader term that also includes models like prepaid credits or tiered usage.

### How do I handle OpenAI's different token costs for different models?

You can create different meters for different models (e.g., `gpt-4-usage` and `gpt-3.5-usage`) and set different prices for each. Alternatively, you can normalize usage into a single "credit" value before sending it to Dodo. For example, 1 token of GPT-4 might equal 10 credits, while 1 token of GPT-3.5 equals 1 credit. This keeps your billing simple for the user while maintaining accuracy for your costs.

### Can I set a maximum monthly charge for a user?

Yes, you can implement this in your application logic by tracking usage and stopping the ingestion of events (and service access) once a certain threshold is reached. Dodo also allows you to configure usage caps on specific products to prevent runaway costs for your customers. This is a great way to build trust with your users.

### What happens if a usage event fails to send to Dodo?

You should implement a retry mechanism in your application. Dodo's ingestion API is highly available, but network issues can happen. Using a background job queue to send events is a best practice for reliability. Dodo's API is idempotent, so you can safely retry the same event ID multiple times without fear of double-billing.

### Is metered billing better than a flat subscription for AI apps?

For most AI apps, yes. It ensures that your revenue always covers your variable costs (tokens). However, a hybrid model with a base subscription fee plus metered overage is often the most stable for predictable revenue. This gives you a baseline of income while still allowing you to profit from high-volume users.

### How does Dodo Payments handle global taxes for my AI app?

Dodo Payments is a Merchant of Record. This means we are the legal seller of your service. We calculate the correct tax based on the customer's location, collect it during checkout, and remit it to the appropriate tax authorities. You don't have to worry about VAT, GST, or sales tax compliance. We handle the registrations and filings so you don't have to.

### Can I offer a free trial with metered billing?

Absolutely. You can configure your metered product to have a "free threshold." For example, the first 50,000 tokens every month could be free, and you only start charging once the user exceeds that amount. This is a great way to let users try your product before they commit to paying.

---

For more information on pricing strategies, visit [dodopayments.com/pricing](https://dodopayments.com/pricing).
---
- [More Payments articles](https://dodopayments.com/blogs/category/payments)
- [All articles](https://dodopayments.com/blogs)