Design, write, and debug Limitr pricing policies (credits, plans, limits, caps, grants, feature flags, overhead costs) and integrate the in-process Limitr engine into TypeScript, JavaScript, and Python apps, including Limitr Network services that agents pay for with signed vouchers.
Most flexible usage billing & limits for AI.
Credits, metering, caps, and custom deals for every user and agent, in one policy that runs in your app and changes live.
Limitr decides what each customer can use and what it costs. You write your plans, limits, and prices in one
policy file. Before your app does something a customer pays for (a model call, an export, an API request), it asks
Limitr: is this allowed? Limitr answers, counts the usage, and tells you what to bill and what it cost you.
The engine is open source and runs inside your app, in TypeScript/JavaScript or Python. Limitr Cloud
is the hosted side: change pricing from a dashboard, keep customer data, and send invoices.
Quick start
npm i @formata/limitr # TypeScript / JavaScript (Node, Bun, Deno, the browser)
pip install limitr # Python
Here's a policy, policy.yaml. AI tokens cost the customer $20 per million and cost you $8. The free plan gets 50k
tokens a month. The pro plan gets 2M, can go over (and pay for it), and can export PDFs:
import { Limitr } from '@formata/limitr';
import { readFile } from 'node:fs/promises';
const limitr = await Limitr.new(await readFile('policy.yaml', 'utf8'), 'yaml');
limitr.addHandler('billing', (name, value) => {
if (name === 'meter-overage') console.log('bill acme:', JSON.parse(value as string).overage_price);
});
await limitr.ensureCustomer('acme', 'pro');
await limitr.allow('acme', 'export_pdf'); // true
await limitr.allow('acme', 'chat', 2_100_000); // true, 100k over the limit, so it prints "bill acme: 2"
await limitr.ensureCustomer('ada'); // no plan given, so ada is on free
await limitr.allow('ada', 'chat', 60_000); // false: free only allows 50k
Or in Python:
from limitr import Limitr
limitr = Limitr(open('policy.yaml').read(), 'yaml')
limitr.add_handler('billing', lambda name, event: print('bill acme:', event['overage_price']) if name == 'meter-overage' else None)
limitr.ensure_customer('acme', 'pro')
limitr.allow('acme', 'export_pdf') # True
limitr.allow('acme', 'chat', 2_100_000) # True, 100k over the limit, so it prints "bill acme: 2.0"
limitr.ensure_customer('ada') # no plan given, so ada is on free
limitr.allow('ada', 'chat', 60_000) # False: free only allows 50k
To change a price or a limit, you change the policy, not your code. With Limitr Cloud, the change goes live without a
deploy. The TypeScript and
Python tutorials pick up from here, in 15 short
chapters you can run.