Skip to main content

Documentation Index

Fetch the complete documentation index at: https://narev.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Narev introduction hero image

What’s Narev?

Narev is the billing and cost-tracking platform for AI products. Instead of building custom data pipelines to meter LLM usage, drop in the Narev SDK to capture raw tokens and use Narev Cloud to sync invoice-ready data directly to Stripe, Lago, or Polar.sh.

Usage-based billing

Implement true usage-based billing and charge users for exactly what they consume.

Profitability analytics

Gain deep visibility into your unit economics: cost per user, cost per paying user, cost per request.

Problems Narev solves

The problem: Model prices change constantly, and providers calculate costs differently across input, output, and cached tokens.The solution: Narev Cloud syncs live pricing, while the Narev SDK maps raw token usage to normalized dollar amounts you can confidently invoice.
The problem: Moving usage data from an LLM call into Stripe, Lago, or Polar.sh requires custom data pipelines that turn token counts into dollar amounts, manual reconciliation, and brittle webhooks.The solution: The open-source Narev SDK provides middleware that automatically pushes billable events from your framework directly to your billing provider.
The problem: AI gateways make it easier to connect to providers and estimate your costs, but introduce extra latency, another point of failure, and charge an additional fee layer.The solution: Narev gives you the primitives to run your own metering pipeline. You own the data, remove the middleman, and keep full control of your profit margins.
The problem: Without precise cost tracking, you can’t tell if a specific customer or prompt change is destroying your profit margins.The solution: Narev attributes exact Cost of Goods Sold (COGS) to specific users via Customer Tagging, letting you optimize based on real dollar impact.

Core features

Focus on building your product while we handle the complexity of AI monetization and cost management.

Prebuilt UI components

Add billing and usage dashboards directly to your app in minutes with drop-in React components.

Managed usage-based billing

Let us handle the heavy lifting of syncing metered usage data directly to Stripe and Polar.sh.

Margin improvement tools

Evaluate prompts across models with built-in benchmarking to optimize unit economics and protect profits.

Quick start guide

Start with usage-based billing so you can measure usage and bill customers correctly from day one.
1

Get your API keys

Create a free Narev Cloud account to get your NAREV_API_KEY. You will also need credentials for your billing provider (like a Polar access token or Stripe secret key) to sync usage.
2

Install the packages

Install the core billing package along with your preferred billing provider and Next.js UI components.
npm install @ai-billing/core @ai-billing/polar @ai-billing/nextjs
3

Add the backend middleware

Use the wrapLanguageModel function from the Vercel AI SDK to attach the billing middleware to your model. This automatically tracks token usage and sends it to your billing provider.
backend.ts
import { wrapLanguageModel, openai } from 'ai';
import { createOpenAIV3Middleware } from '@ai-billing/openai';
import { createPolarDestination } from '@ai-billing/polar';

// 1. Configure where the billing events should be sent
const billingMiddleware = createOpenAIV3Middleware({
  destinations: [
    createPolarDestination({
      accessToken: process.env.POLAR_ACCESS_TOKEN,
      eventName: 'llm_usage',
    })
  ]
});

// 2. Wrap your model to automatically meter all generations
export const billedModel = wrapLanguageModel({
  model: openai('gpt-4o'),
  middleware: billingMiddleware
});
4

Use the model in your API route

Pass the wrapped model into Vercel’s streamText. Use providerOptions to pass the user’s ID so the billing destination knows who to charge.
app/api/chat/route.ts
import { streamText } from 'ai';
import { billedModel } from '@/lib/billing';
export async function POST(req: Request) {
  const { messages } = await req.json();
  
  // Get the authenticated user ID (e.g., from your auth provider)
  const userId = 'user_123'; 
  const result = streamText({
    model: billedModel,
    messages,
    providerOptions: {
      // These tags are automatically forwarded to your billing destination
      'ai-billing-tags': {
        userId: userId,
      },
    },
  });
  return result.toDataStreamResponse();
}
5

Add the Pre-build billing components

Embed the prebuilt React components in your Next.js frontend to show users their real-time usage and provide a native checkout experience for buying credits.
components/usage-dashboard.tsx
import { CreditUsagePolar, CreditTopUpPolar } from '@ai-billing/nextjs';

export default function BillingDashboard({ userId }: { userId: string }) {
  return (
    <div className="flex flex-col gap-6 p-4">
      <h2 className="text-xl font-semibold">Usage & Billing</h2>
      
      {/* Shows current consumption and remaining budget/credits */}
      <CreditUsagePolar userId={userId} />
      
      {/* Renders a checkout component to buy more credits */}
      <CreditTopUpPolar userId={userId} />
    </div>
  );
}
6

Voila! You're ready to bill

Your application is now fully equipped with AI monetization, cost tracking, and a self-serve top-up dashboard.
Billing dashboard using Narev prebuild components showing real-time usage
Billing dashboard using Narev prebuild components showing top-up options

Why choose Narev?

Launch with usage billing from day one

Instrument requests with the Narev SDK so you can meter and bill without building custom pipelines.

Integrate with your existing stack

Connect Narev Cloud to Stripe, Lago, or Polar.sh and keep your current billing workflow.

Improve model efficiency quickly

Benchmark your real prompts, then route traffic to lower-cost model variants with quality safeguards.

See true AI unit economics

Track AI spend and COGS with normalized usage data so you can price features with confidence.

Open source

We build in the open. Our core billing primitives are open-source and free to self-host, giving you the flexibility to choose the right deployment model for your workload.

narevai/ai-billing

Open-source middleware to easily add usage-based billing to your AI applications.

narevai/narev

Self-hosted finops platform for tracking and mapping your infrastructure costs.

Ready to start?

Create Account

Free sign-up, no credit card requiredGet started in under 2 minutes

Quickstart Guide

Start billing AI usageConnect a Vercel AI SDK app to Narev Cloud

Read the Guides

Framework-specific tutorialsStep-by-step integration guides

Join Our Community

Get help from the Narev teamActive community and support