How It Works

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.

Step 1

Check

Verify customer is within limits before the call

Step 2

Call

Call OpenAI, Anthropic, or any LLM provider

Step 3

Record

Log tokens and costs per customer

Step 4

Bill

Pull usage data via API for billing

Simple Check-Record Pattern

Two API calls per request. Full control. Works with any LLM.

app/api/chat/route.ts
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,
  });
}

Then bill.

At the end of each cycle, query your meters and send usage to Stripe, Orb, Metronome, or your own billing system. Two API calls — one to read, one to bill.

billing/invoice.ts
import Stripe from "stripe";
import Limitry from "limitry";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const limitry = new Limitry({ apiKey: process.env.LIMITRY_API_KEY });

// Query this month's usage
const meter = await limitry.meters.get({
  customerId: "cust_acme",
  meterId: "llm-tokens",
  period: "current_month",
});

// Send to Stripe as a usage line item
await stripe.invoiceItems.create({
  customer: "cus_abc123",
  quantity: meter.value,
  price: "price_per_token",
});

Core Capabilities

Built for AI-Powered Products

Everything you need to meter, limit, and bill for AI usage — so you can monetize with confidence.

Custom Meters

Define how usage is aggregated. Track any metric — tokens, requests, costs, or custom values.

  • Flexible aggregation (sum, count, max)
  • Filter by event type or dimension
  • Per-customer breakdowns
  • Real-time & historical data

Usage Limits

Set usage caps per customer, team, or pricing plan. Enforce limits automatically.

  • Per-customer limits
  • Plan-based tiers (Free/Pro/Enterprise)
  • Time-based periods (hourly/daily/monthly)
  • Lifetime limits for resources

Prepaid Balances

Let customers pre-purchase credits. Track balances and debit atomically with usage.

  • Credit & debit transactions
  • Minimum balance reserves
  • Full transaction history
  • Atomic deductions (no overdraw)

Events & Billing API

Query usage data via API to power your billing. Accurate data for accurate invoices.

  • Per-customer usage summaries
  • Date range & dimension queries
  • Webhook notifications
  • CSV and API export

Provider Agnostic

Works With Any LLM

Limitry doesn't proxy your requests. Record usage from any provider — we handle the rest.

Track usage from

OpenAIAnthropicGoogle AICohereAzure OpenAIAWS BedrockMistralAny provider

Export usage to

StripeOrbMetronomeYour billing system

Use Cases

Monetize Every AI Feature

AI-Powered SaaS

Offer AI features with usage-based pricing. Free tier limits, paid tiers with higher caps.

API Products

Meter every API call. Enforce limits by plan. Bill per request or token.

Multi-Tenant Platforms

Per-customer usage tracking. Limits per org. Fair billing for everyone.

Enterprise Apps

Department chargebacks. Per-team budgets. Full audit trails.

AI Agents

Track agent runs and token usage. Bill customers per execution.

Chat Products

Meter conversations and messages. Enforce daily or monthly limits.

Start monetizing AI usage today

Free to start. Simple API. Bill your customers with confidence.