{"id":47706132,"url":"https://github.com/narevai/ai-billing","last_synced_at":"2026-05-26T21:05:54.140Z","repository":{"id":347752875,"uuid":"1190106781","full_name":"narevai/ai-billing","owner":"narevai","description":"Easy billing for vercel/ai-sdk","archived":false,"fork":false,"pushed_at":"2026-04-24T15:05:17.000Z","size":1359,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-24T17:33:16.144Z","etag":null,"topics":["ai-sdk","ai-tools","billing","finops"],"latest_commit_sha":null,"homepage":"https://www.narev.ai/docs/sdk/ai-billing","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/narevai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-24T01:13:10.000Z","updated_at":"2026-04-24T15:02:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/narevai/ai-billing","commit_stats":null,"previous_names":["narevai/ai-billing"],"tags_count":92,"template":false,"template_full_name":null,"purl":"pkg:github/narevai/ai-billing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narevai%2Fai-billing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narevai%2Fai-billing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narevai%2Fai-billing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narevai%2Fai-billing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/narevai","download_url":"https://codeload.github.com/narevai/ai-billing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narevai%2Fai-billing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32454170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-sdk","ai-tools","billing","finops"],"created_at":"2026-04-02T17:58:35.493Z","updated_at":"2026-05-26T21:05:54.126Z","avatar_url":"https://github.com/narevai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ai-billing\n\n- Middleware for the [Vercel AI SDK](https://sdk.vercel.ai/docs)\n- Sends billing events directly to billing platforms (Stripe, Polar, and Lago)\n- Ships with components to make usage-based billing easy\n\n[![codecov](https://codecov.io/github/narevai/ai-billing/graph/badge.svg?token=KZG0YE4THI)](https://codecov.io/github/narevai/ai-billing)\n![Node Current](https://img.shields.io/node/v/%40ai-billing%2Fcore)\n![NPM License](https://img.shields.io/npm/l/%40ai-billing%2Fcore)\n\u003ca href=\"https://discord.gg/eAFaCwmEEy\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/chat-on%20discord-7289DA.svg\" alt=\"Discord Chat\" /\u003e\n\u003c/a\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/header-1.png\" alt=\"AI Billing Header 1\"\u003e\n\u003c/p\u003e\n\n## UI Components\n**Storybook:** [Explore the `@ai-billing/nextjs` components](https://ai-billing-storybook.vercel.app/)\n\n### `\u003cCreditTopUpPolar\u003e`\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/topup-component.png\" alt=\"Topup Component from @ai-billing/nextjs\"\u003e\n\u003c/p\u003e\n\n### `\u003cCreditUsagePolar\u003e`\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/usage-component.png\" alt=\"Usage Component from @ai-billing/nextjs\"\u003e\n\u003c/p\u003e\n\n## Full-stack examples\n| Name | Demo Link | Repo | Deploy |\n| :--- | :--- | :--- | :--- |\n| **Chatbot (OpenRouter + Polar)** | [View Demo](https://chatbot-with-billing-polar-three.vercel.app/) | [GitHub](https://github.com/narevai/chatbot-with-billing-polar) | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fnarevai%2Fai-billing%2Ftree%2Fmain%2Fexamples%2Fchatbot-with-billing-polar) |\n| **Chatbot (OpenAI + Polar)** | [View Demo](https://chatbot-openai-with-billing-polar.vercel.app/) | [GitHub](https://github.com/narevai/chatbot-openai-with-billing-polar) | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fnarevai%2Fchatbot-openai-with-billing-polar\u0026env=AUTH_SECRET,OPENAI_API_KEY,POSTGRES_URL,POLAR_ACCESS_TOKEN,POLAR_SERVER,NAREV_API_KEY\u0026envDefaults=%7B%22POLAR_SERVER%22%3A%22sandbox%22%7D) |\n| **Chatbot (Stripe)** | [View Demo](https://chatbot-with-billing-stripe.vercel.app/) | [GitHub](https://github.com/narevai/chatbot-with-billing-stripe) | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fnarevai%2Fchatbot-with-billing-polar\u0026env=AUTH_SECRET,AI_GATEWAY_API_KEY,POSTGRES_URL,POLAR_ACCESS_TOKEN,POLAR_SERVER\u0026envDefaults=%7B%22POLAR_SERVER%22%3A%22sandbox%22%7D) |\n\n\n## Billing Architecture\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/header-2.png\" alt=\"AI Billing Header 2\"\u003e\n\u003c/p\u003e\n\n### Supported Providers\n\n| Provider | Package | Size |\n| :--- | :--- | :--- |\n| [**OpenRouter**](https://ai-sdk.dev/providers/community-providers/openrouter) | [`@ai-billing/openrouter`](https://www.npmjs.com/package/@ai-billing/openrouter) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fopenrouter) |\n| [**OpenAI**](https://ai-sdk.dev/providers/ai-sdk-providers/openai) | [`@ai-billing/openai`](https://www.npmjs.com/package/@ai-billing/openai) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fopenai) |\n| [**Vercel AI Gateway**](https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway) | [`@ai-billing/gateway`](https://www.npmjs.com/package/@ai-billing/gateway) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fgateway) |\n| [**OpenAI Compatible**](https://ai-sdk.dev/providers/openai-compatible-providers) | [`@ai-billing/openai-compatible`](https://www.npmjs.com/package/@ai-billing/openai-compatible) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fopenai-compatible) |\n| [**Groq**](https://ai-sdk.dev/providers/ai-sdk-providers/groq) | [`@ai-billing/groq`](https://www.npmjs.com/package/@ai-billing/groq) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fgroq) |\n| [**Google Generative AI**](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai) | [`@ai-billing/google`](https://www.npmjs.com/package/@ai-billing/google) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fgoogle) |\n| [**Anthropic**](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic) | [`@ai-billing/anthropic`](https://www.npmjs.com/package/@ai-billing/anthropic) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fanthropic) |\n| [**xAI Grok**](https://ai-sdk.dev/providers/ai-sdk-providers/xai) | [`@ai-billing/xai`](https://www.npmjs.com/package/@ai-billing/xai) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fxai) |\n| [**MiniMax**](https://ai-sdk.dev/providers/community-providers/minimax) | [`@ai-billing/minimax`](https://www.npmjs.com/package/@ai-billing/minimax) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fminimax) |\n| [**DeepSeek**](https://ai-sdk.dev/providers/ai-sdk-providers/deepseek) | [`@ai-billing/deepseek`](https://www.npmjs.com/package/@ai-billing/deepseek) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fdeepseek) |\n| [**Chutes**](https://ai-sdk.dev/providers/community-providers/chutes) | [`@ai-billing/chutes`](https://www.npmjs.com/package/@ai-billing/chutes) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fchutes) |\n\n### Supported Destinations\n\n| Destination | Package | Size |\n| :--- | :--- | :--- |\n| **Polar.sh** | [`@ai-billing/polar`](https://www.npmjs.com/package/@ai-billing/polar) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fpolar) |\n| **Stripe** | [`@ai-billing/stripe`](https://www.npmjs.com/package/@ai-billing/stripe) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fstripe) |\n| **OpenMeter** (Kong) | [`@ai-billing/openmeter`](https://www.npmjs.com/package/@ai-billing/openmeter) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fopenmeter) |\n| **Lago** | [`@ai-billing/lago`](https://www.npmjs.com/package/@ai-billing/lago) | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Flago) |\n\n### UI \u0026 SDKs\n\n| Package | Description | Size |\n| :--- | :--- | :--- |\n| [`@ai-billing/nextjs`](https://www.npmjs.com/package/@ai-billing/nextjs) | Next.js UI components for displaying billing usage and managing top-ups. | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fnextjs) |\n| [`@ai-billing/ui`](https://www.npmjs.com/package/@ai-billing/ui) | Internal headless UI components shared across `@ai-billing/*` packages. | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fui) |\n| [`@ai-billing/narev`](https://www.npmjs.com/package/@ai-billing/narev) | TypeScript SDK for the [Narev](https://narev.ai) billing API. | ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40ai-billing%2Fnarev) |\n\n---\n\n\n## Installation\n\n```bash\nnpm install @ai-billing/core @ai-billing/openrouter # Example for OpenRouter\n```\n\n## Basic Usage\n\nWrap your model provider with the billing middleware and define your destinations.\n\n```typescript\nimport { streamText, wrapLanguageModel } from 'ai';\nimport { createOpenRouter } from '@openrouter/ai-sdk-provider';\nimport { createOpenRouterV3Middleware } from '@ai-billing/openrouter';\n\nconst billingMiddleware = createOpenRouterV3Middleware({});\n\nconst model = wrapLanguageModel({\n  model: createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY })('google/gemini-2.0-flash-001'),\n  middleware: billingMiddleware,\n});\n```\n\n---\n\n## Send usage to Polar.sh\n\nWrap your model provider with the billing middleware and define your destinations.\n\n```typescript\nimport { streamText, wrapLanguageModel } from 'ai';\nimport { createOpenRouter } from '@openrouter/ai-sdk-provider';\nimport { createOpenRouterV3Middleware } from '@ai-billing/openrouter';\nimport { createPolarDestination } from '@ai-billing/polar';\n\nconst billingMiddleware = createOpenRouterV3Middleware({\n  destinations: [\n    createPolarDestination({\n      accessToken: process.env.POLAR_ACCESS_TOKEN,\n      eventName: 'llm_usage',\n    })\n  ],\n});\n\nconst model = wrapLanguageModel({\n  model: createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY })('google/gemini-2.0-flash-001'),\n  middleware: billingMiddleware,\n});\n\nconst { textStream } = await streamText({\n  model,\n  messages: [{ role: 'user', content: 'Quantify the value of metadata.' }],\n  providerOptions: { \n    'ai-billing-tags': { userId: 'usr_123', org: 'Acme' } \n  },\n});\n```\n\n## Status and Roadmap\n\n\u003e **Note:** We are prioritizing support for **TEXT models**.\n\n**Active Development**\n* [Requesty](https://ai-sdk.dev/providers/community-providers/requesty)\n* [Cloudflare AI Gateway](https://ai-sdk.dev/providers/community-providers/cloudflare-ai-gateway)\n\nFull list of providers can be found here: https://ai-sdk.dev/providers/\nThe following providers are planned for future implementation. **To prioritize a specific provider, please [open a GitHub issue](https://github.com/narevai/ai-billing/issues).**\n\n## Architecture\n\nThe package consists of two primary components:\n\n### 1. Provider Middleware\n- specialized for `@ai-sdk/*` that understand the specific `providerMetadata` shapes of different LLM usage\n- provider-specific cost calculation logic that that turn usage into cost\n- `PriceResolver` allowing to pass custom prices at time of request\n\n### 2. Destinations\n- functions that receive a normalized `BillingEvent` and handle the API calls to external services\n- allow charging in credits using standardized meters","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarevai%2Fai-billing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarevai%2Fai-billing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarevai%2Fai-billing/lists"}