How to charge for your API (even if AI built it)
Short version: decide what is worth paying for, sell it in packages of uses, give each customer a key you can revoke, and make sure that when something fails, nothing is given away for free. If your backend is Express, your AI assistant can set this up with LicenRoute while you approve each change.
You built an app (maybe with Claude Code, Cursor, Lovable or Bolt) and people are using it. Some of what it does is clearly valuable: a report, a dataset, an export, an AI-powered endpoint that costs you money every time it runs. The question is how to charge for that part without breaking the rest.
1. Decide what is worth paying for
Don't put your whole app behind a paywall. Look for the parts that:
- cost you money each time they run (AI calls, heavy queries, third-party APIs);
- are what people come back for (the report, the data, the export);
- are used by programs, not people: other apps, scripts and AI agents calling your API.
Everything else should stay free: sign-up, login, your home page, health checks. Making those paid doesn’t earn money; it just locks people (and your monitoring) out.
2. Pick a pricing model
| Model | How it works | Good for |
|---|---|---|
| Monthly subscription | Fixed price, access while you pay | Apps used by people every day |
| Packages of uses | Buy 1,000 calls for a price; buy more when they run out | APIs used by programs and AI agents; costs that grow with use |
| Pay per call | Every single request is billed | High volume, with a billing system that can handle it |
For an API, packages of uses are usually the simplest place to start: the customer knows what they pay, and you never serve more than they bought.
3. The five pieces you need
- Keys. Each customer gets a secret key that they send with every request. Keys must be impossible to guess, and you should store only a fingerprint (hash) of them, never the key itself.
- A usage counter. Every request to a paid part uses one unit. When the package is used up, the next request is refused.
- Revocation. If someone stops paying or abuses the API, you switch their key off and the very next request is refused, without redeploying.
- A clear “pay first” answer. A request without a valid key should get a standard answer: HTTP
402 Payment Required, ideally saying which plan unlocks it and where to buy it. Programs and AI agents can read that; an error page they can’t. - Safe failure. If the system that checks keys is down, paid parts must close, not open. Free parts must keep working.
4. Mistakes that quietly give your API away
- Failing open. “If the key check times out, let the request through” sounds friendly. It means one outage serves everything for free.
- Protecting the path, not the method. Charging for
GET /api/reportsbut forgettingHEAD /api/reports, or accidentally charging for theOPTIONSrequests browsers send automatically. - Charging your own login. Putting sign-in or sign-up behind the paywall locks out the people who were about to pay.
- Counting before checking. Using up a unit even when the request is refused, or serving the response before the unit is counted.
- Letting your AI assistant ship it unreviewed. Billing code is exactly where a small, plausible-looking change can cost you money. Review the diff.
5. Build it yourself, or let your assistant set it up
You can ask your AI assistant to write all of this from scratch. It will produce something that looks right; the mistakes above are what it usually gets wrong, and you'll need tests for every case.
If your backend is Node.js with Express, LicenRoute does the five pieces for you. Paste this into your assistant:
Add paid access to my Express API with LicenRoute. First read https://licenroute.com/llms.txt and follow its rules. 1. Tell me which of my routes could be paid and which must stay free. 2. Show me the exact change before writing anything. 3. When I agree, give me the command to approve it in my own terminal. 4. Then run the LicenRoute tests and explain the results in plain words.
Your assistant reads your code, proposes what to charge for, and shows you the change. Nothing is written until you type a short code in your terminal: the one step it can’t do for you. Then LicenRoute tests your API like a customer would: no key (402), valid key (200), fake key (403), package used up, key revoked, and the system down.
Try it on your app
Copy the prompt from the home page, or follow the 10-minute tutorial on the example app. Using another framework? Tell us what you built.