> ## Documentation Index
> Fetch the complete documentation index at: https://www.narev.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bill

> Connect application usage to customers and customer charges.

Connect model usage to the customer who generated it. **AI-billing** captures usage in Vercel AI SDK calls and sends normalized events to billing destinations such as Polar, Stripe, Lago, and OpenMeter.

## Capture your first event

Use Node.js 22 or later. Install compatible packages in your Node.js project:

```bash theme={null}
npm install ai@^6 @ai-sdk/provider@^3 @ai-sdk/gateway@^3 @ai-billing/gateway@^0.2 @ai-billing/core@^0.1.6
npm install --save-dev tsx
```

Set `AI_GATEWAY_API_KEY` in your server environment. Gateway inference can incur charges. Create `billing.ts`:

```typescript theme={null}
import { generateText, wrapLanguageModel } from 'ai';
import { createGateway } from '@ai-sdk/gateway';
import { createGatewayV3Middleware } from '@ai-billing/gateway';
import { consoleDestination } from '@ai-billing/core';

const apiKey = process.env.AI_GATEWAY_API_KEY;
if (!apiKey) throw new Error('Set AI_GATEWAY_API_KEY');

const gateway = createGateway({ apiKey });
const model = wrapLanguageModel({
  model: gateway('openai/gpt-4o'),
  middleware: createGatewayV3Middleware({
    destinations: [consoleDestination()],
  }),
});

await generateText({ model, prompt: 'Say hello in one sentence.' });
```

Run `npx tsx billing.ts` and inspect the console billing event for usage and cost. This meters a request; it does not charge a customer. Next, configure a billing destination and Customer Tagging from authenticated server state.

## Learn more

[Explore AI-billing](https://www.narev.ai/docs/ai-billing/index.md) and follow the [quickstart](https://www.narev.ai/docs/ai-billing/quickstart.md) for tagging and pricing sources. Choose a [billing integration](https://www.narev.ai/docs/ai-billing/integrations/index.md) when you are ready to send customer-attributed events.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.