Skip to main content
The hard part of charging for AI isn’t the model call — it’s everything downstream. A request can burn 200 tokens or 200,000. Each provider reports usage with a different schema. Cached tokens are cheaper than fresh ones. And underneath the price you quote a customer sits a cost you pay a model provider that shifts every quarter. Get the gap between those two numbers wrong and you either bleed money on power users or scare off everyone else. This guide compares the two realistic paths — build your own metering stack, or run it on Macropay — and then shows how to set margin, included credits, and overage so your AI product actually makes money.
Macropay is a Merchant of Record. When a customer pays for your AI product, we are the legal seller, so we calculate and remit sales tax and VAT worldwide, keep you off the hook for that liability, and stay PCI DSS Level 1 compliant. You ship the product; we handle the money, the tax, and the compliance.

What “billing for inference” actually requires

Before picking an approach, it helps to see the full surface area. Charging for LLM usage means owning all of this: Whoever owns that last row is the merchant of record. With a DIY stack, that’s you. With Macropay, that’s us.

Approach 1 — Build it yourself

The do-it-yourself route is a real option, and for some teams the right one. Here’s the shape of what you’re signing up for.
To stand this up you’ll write and then maintain:
  1. A usage table keyed by customer, with tokens, model, and cost on every event
  2. An aggregation layer that computes usage per customer per billing period
  3. A pricing engine that applies your markup and produces a charge
  4. A payment integration to actually collect — plus retries and dunning
  5. A customer-facing view of usage and estimated charges
Budget roughly 4–8 weeks to a first version, then ongoing work every time a provider changes pricing or response shape.

Three traps teams hit

OpenAI returns usage.prompt_tokens and usage.completion_tokens. Anthropic returns usage.input_tokens and usage.output_tokens. Google returns usageMetadata.promptTokenCount. Support more than one model and you’ve built a normalization layer whether you wanted to or not.
When a customer challenges a charge, “trust me, you used 4.2M tokens” doesn’t hold up. You need per-request logs you can point to — not just monthly aggregates — which means storing and querying detail at scale.
What you paid the model provider and what you charge the customer are separate numbers. Margin lives in the gap, and you can’t see it without tracking both — a second accounting layer most teams discover late.

Approach 2 — Run it on Macropay

Macropay is usage-based billing infrastructure built for AI products. You instrument your LLM calls with the @macropayments/ingestion SDK; we handle metering, aggregation, invoicing, collection, tax, and the customer portal.

Step 1 — Install the SDK

Step 2 — Wrap your model with the LLM ingestion strategy

The strategy intercepts each call and records token counts, model, and your cost automatically — attributed to the customer who made the request. TypeScript (Vercel AI SDK)
Python (PydanticAI)
Every call now lands in Macropay with:
  • Input, output, and cached token counts
  • Model name and provider
  • Your cost for the request
  • The customer it belongs to
Prefer to keep your code untouched? Point your OpenAI client at the Macropay AI proxy — an OpenAI-compatible endpoint at POST /ai/v1/chat/completions. It forwards the request and captures token cost on the way through, no SDK wiring required.

Step 3 — Create a meter

A meter turns raw events into a billable quantity. For token billing, sum totalTokens from your ingestion events.
1

Open Usage Based Billing in the dashboard

Go to the Meters section and choose Create Meter.
2

Configure the meter

  • Name: LLM Tokens
  • Filter: events named research-query
  • Aggregation: sum of metadata.totalTokens
3

Attach a metered price to your product

Add a metered price to the product — for example, $0.01 per 1,000 tokens.

Step 4 — Customers watch it update live

Usage and estimated charges appear in the self-serve customer portal and refresh as events arrive — so the invoice is never a surprise.

Setting your margin

Capturing usage is the easy half. Choosing what to charge is where products win or lose. Three patterns cover most AI businesses.

Flat markup

Add a fixed percentage on top of your model cost. Easy to reason about, easy to explain — but your margin moves whenever the provider’s pricing does.

Volume tiers

Lower the per-token rate as usage climbs, which rewards your biggest customers for consolidating spend with you. Configure the tiers directly on the metered price — no custom code.

Prepaid credits

Sell credits up front and burn them down per request. You get predictable revenue; the customer gets a price that’s easy to budget against. Grant a credit allotment with each tier using the meter credits benefit.

Beyond tokens: billing agents on outcomes

Tokens are the obvious meter, but they measure your cost, not the value a customer receives. If you ship autonomous agents, Macropay lets you bill on what the agent did or achieved — not just what it consumed.
  • Activity and outcome signals. Send POST /v1/signals to record agent activity (a research run, a ticket resolved) or an outcome (a meeting booked, a refund prevented), attributed to the agent that produced it.
  • Value receipts. Certify ROI — time saved, revenue generated, cost avoided — so a customer sees the value behind the invoice, not just the line item.
  • Agentic margin. Compare billed revenue against the AI cost (COGS) behind each agent, so you know which agents actually earn their keep.
This is the difference between charging for compute and charging for results — and outcome-based pricing is where agent products command the strongest margins.

Worked example: an AI writing tool

Here’s the whole thing end to end for a tool that drafts blog posts, emails, and marketing copy. The model: a monthly subscription with included credits and metered overage. Plans Implementation
That’s the entire billing integration. From there, Macropay:
  • Meters tokens per customer
  • Draws down the included credits on their tier
  • Bills overage at the right tier rate
  • Issues the invoice each period and collects the payment
  • Remits sales tax and VAT in every market you sell to
  • Surfaces live usage in the customer portal

Know your margins in real time

Pricing isn’t set-and-forget — upstream model costs drift, and a power user who was profitable in January may not be in June. Cost Insights puts your upstream LLM spend next to customer revenue so you can answer:
  • Gross margin per customer — are your heaviest users still in the black?
  • Cost trend — is a provider price change quietly eating your margin?
  • Model efficiency — which model gives the best margin for this workload?

Start here

Create your account

Sign up and ship a metered product in under ten minutes.

Usage-based billing

Events, meters, and metered pricing, explained.

LLM ingestion strategy

SDK reference for capturing token usage and cost.

Cost Insights

Track upstream costs and watch margins live.