Charging for an API involves two separate problems. The first is commercial: what to charge for, and how to structure the price. The second is technical: counting usage accurately, enforcing limits, and billing for the result. This article covers both, for developers and founders who have a working API and want it to pay for itself.
Decide what you are charging for
Before picking a model, pick the unit. The unit you bill on, often called the value metric, should rise when the customer gets more value and should be something they can predict and you can measure.
For most APIs the unit is the request. It is easy to count and easy to explain. It fits badly when requests differ widely in cost or value: a call that validates one email address and a call that generates a long document should not cost the same. In those cases bill on what the request consumes or produces, such as records processed, minutes of audio, or tokens generated, or give expensive endpoints a higher weight in the same quota.
Some APIs should not charge per call at all. If the API moves money or completes a sale, a share of each transaction tracks value better than a request count. If the API exists to make another product more useful, it may be worth more free, as a reason to buy that product.
Compare the pricing models
Four models cover almost every paid API. They are not exclusive, and most providers combine two.
| Model | How the customer pays | Works well when | Main risk |
|---|---|---|---|
| Freemium | Nothing up to a limit, then a paid plan | Developers need to try the API before anyone approves a budget | Free usage costs you money and most free users never pay |
| Tiered subscription | A fixed monthly fee for a quota | Customers want a predictable bill | Customers between tiers feel overcharged or get cut off |
| Pay per use | An amount per call or per unit consumed | Usage varies a lot month to month | Revenue is unpredictable for you, and the bill is for them |
| Transaction fee | A share of the money the API moves | The API is in the path of a payment or sale | Only applies where there is a transaction to share in |
Freemium is a way to acquire users, not a price in itself. The free tier has one job, which is to let a developer build and test a real integration without talking to anyone. Size it for evaluation and small projects, and make sure serving it is cheap, because you will serve far more free accounts than paid ones.
Tiered subscriptions are the simplest to sell and to forecast. The work is in choosing the boundaries: each tier should match a recognisable kind of customer, and the step between tiers should be large enough that the upgrade is an obvious decision once someone hits the limit.
Pay per use removes the tier problem, since nobody pays for capacity they do not use. It adds a different one: customers cannot predict their bill, and some will refuse to integrate an API with an open-ended cost. Spending caps and usage alerts are part of the product in this model, not extras.
Transaction pricing is the model payment providers use. Stripe, for example, publishes a percentage plus a fixed fee per successful charge, so its revenue grows exactly as its customers' sales do.
A worked example: tiers with top-ups
APIStack's own pricing is a combination of freemium, tiers, and a prepaid top-up, and it shows how the pieces fit. One quota is shared across every API on the platform.
| Plan | Price | Calls per month | Price per 1,000 calls |
|---|---|---|---|
| Free | $0 | 1,000 | $0 |
| Pro | $19.99 a month | 100,000 | about $0.20 |
| Enterprise | $79.99 a month | 1,000,000 | about $0.08 |
| Top-up | $4.99 once | 1,000 extra | $4.99 |
The free plan is also limited to 10 calls a minute, which is enough to develop against and too little to run a busy production service on. The paid tiers are a factor of ten apart in volume, so a growing customer is not forced to change plan every month. The top-up covers the case tiers handle badly, an occasional spike, and it is priced well above the per-call rate of a subscription, so anyone who needs it regularly is better off upgrading. The current figures are on the pricing page.
The general pattern is a free tier for evaluation, two or three subscription tiers aimed at distinct customers, and a defined answer to "what happens when I go over". The possible answers are a hard stop, automatic overage billing, or a prepaid top-up. Choose one deliberately and state it on the pricing page, because it is the first thing a careful buyer looks for.
Meter usage accurately
Billing is only as good as the count behind it. The usual first version of a metering middleware reads the customer's current usage, compares it with the limit, lets the request through, and increments the counter afterwards. That has a race: under concurrent requests, many of them read the same count and all pass, so a customer can run well past the quota.
The fix is to make the check and the increment a single atomic operation. With one row per account per month, PostgreSQL can do it in one statement:
CREATE TABLE api_usage (
account_id BIGINT NOT NULL REFERENCES accounts(id),
period DATE NOT NULL,
calls INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (account_id, period)
);The middleware below inserts the row for the month or increments it, but only while the count is under the limit. If the statement returns no row, the quota is used up. It assumes every plan allows at least one call.
const COUNT_CALL = `
INSERT INTO api_usage (account_id, period, calls)
VALUES ($1, date_trunc('month', now() AT TIME ZONE 'UTC')::date, 1)
ON CONFLICT (account_id, period)
DO UPDATE SET calls = api_usage.calls + 1
WHERE api_usage.calls < $2
RETURNING calls`
async function meter(req, res, next) {
try {
const account = await findAccountByApiKey(req.get('x-api-key'))
if (!account) {
return res.status(401).json({ error: 'Missing or invalid API key' })
}
const limit = account.plan.callsPerMonth
const { rows } = await pool.query(COUNT_CALL, [account.id, limit])
if (rows.length === 0) {
return res.status(429).json({ error: 'Monthly quota exceeded', limit })
}
res.set('X-Quota-Limit', String(limit))
res.set('X-Quota-Remaining', String(limit - rows[0].calls))
req.account = account
next()
} catch (error) {
next(error)
}
}Two policy decisions sit behind this code, and both belong in your documentation. The first is which requests count. Charging for a request that failed because of your own server error makes customers distrust the bill; a common policy is to count only successful responses, or everything except 5xx. If you count before the handler runs, as above, subtract the call again when the response turns out to be a server error. The second is when the period resets: on the first of the calendar month, as here, or on each customer's billing date.
A database write on every request is fine at moderate volume. At higher volume, keep the counter in an in-memory store such as Redis, which has atomic increments, and write totals to the database periodically. Whatever the store, keep a per-request log as well. It is what lets you answer a customer who disputes a bill, and what powers a usage page in their dashboard.
Enforce limits without surprising customers
A monthly quota controls cost. A per-minute rate limit protects the service from a single client's bug or burst. Paid APIs need both, and they fail differently: a rate-limited client should wait a few seconds, while a client out of quota needs to upgrade or wait for the reset.
Make the two cases distinguishable. Return 429 for both, with a machine-readable code in the body saying which limit was hit, and a Retry-After header on rate-limit responses so clients know how long to back off. APIStack follows this pattern: over-limit calls get a 429 with Retry-After, as described in the limits section of the docs.
Running out of quota should never be the first the customer hears of it. Show current usage in the dashboard, return the remaining quota in response headers, and send an email before the limit as well as at it. A customer who is warned at 80 percent can upgrade; one whose production integration stops without notice is more likely to leave.
Handle billing
Do not build payment handling yourself. A payment provider takes care of card storage, tax, invoices, failed-payment retries and the compliance that goes with them. Your side of the integration is smaller, and has three parts that need to be right.
Plan state must come from the provider, not from your own guess. Update a customer's plan when the provider's webhook confirms a payment, a cancellation or a failed renewal, and verify the webhook signature before trusting it.
Plan changes need defined behaviour. Decide what an upgrade in the middle of a month does to the quota and the charge, and what a downgrade does to a customer who has already used more than the smaller plan allows.
Failed payments need a grace period. Cards expire and banks decline valid charges, so cutting off access on the first failure punishes customers who intend to pay. Retry, notify, and downgrade only after a stated number of days.
Avoid the common mistakes
A few errors account for most monetization problems.
- A free tier generous enough to run a real business on gives the customers you most want no reason to pay.
- Pricing that needs a calculator loses buyers. If a developer cannot estimate the monthly cost from the pricing page in a minute, simplify it.
- Changing prices for existing customers without notice breaks trust quickly. Keep existing customers on their current price for a published period when you raise prices.
- Limits that are not documented generate support requests and chargebacks. Publish every limit and what happens when it is reached.
Summary
- Bill on a unit that grows with the value the customer gets; requests are the default, not the only option.
- Combine models: a free tier for evaluation, subscription tiers for predictability, and a defined overage or top-up path.
- Check and increment usage in one atomic operation, and decide in writing which requests count.
- Use both a monthly quota and a per-minute rate limit, return
429withRetry-After, and warn customers before they hit a limit. - Let a payment provider handle payments, and drive plan state from its verified webhooks.