The Metering Infrastructure
for AI Products
Two API calls in your request handler. One API call at billing time. That's the entire integration — and you never build metering infrastructure again.
Check · Call · Record · Bill
Check limits, make your AI call, record usage. We handle the rest.
Check
Verify customer is within limits before the call
Call
Call OpenAI, Anthropic, or any LLM provider
Record
Log tokens and costs per customer
Bill
Pull usage data via API for billing
Simple Check-Record Pattern
Two API calls per request. Full control. Works with any LLM.
import Limitry from "limitry";
import OpenAI from "openai";
const limitry = new Limitry({ apiKey: process.env.LIMITRY_API_KEY });
const openai = new OpenAI();
export async function POST(req: Request) {
const { customerId, prompt } = await req.json();
// 1. Check — is the customer within limits?
const check = await limitry.limits.check({
customerId,
meterId: "llm-tokens",
});
if (!check.allowed) {
return Response.json(
{ error: "Usage limit reached", resetsAt: check.resetsAt },
{ status: 429 },
);
}
// 2. Call — make the AI request as usual
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: prompt }],
});
// 3. Record — tell Limitry what happened
await limitry.events.record({
customerId,
eventType: "llm.completion",
value: completion.usage?.total_tokens ?? 0,
dimensions: { model: "gpt-4o", team: "engineering" },
});
return Response.json({
text: completion.choices[0].message.content,
});
}