Use our Ingestion Strategies to track any usage with precision.
import { Ingestion } from "@polar-sh/ingestion"; import { LLMStrategy } from "@polar-sh/ingestion/strategies/LLM"; import { generateText } from "ai"; import { openai } from "@ai-sdk/openai"; const llmIngestion = Ingestion({ accessToken: 'xxx' }) .strategy(new LLMStrategy(openai("gpt-4o"))) .ingest("openai-usage"); export async function POST(req: Request) { const { prompt }: { prompt: string } = await req.json(); const model = llmIngestion.client({ externalCustomerId: "<USER_ID_FROM_YOUR_DATABASE>", }); const { text } = await generateText({ model, system: "You are a helpful assistant.", prompt, }); return Response.json({ text }); }
All the tools you need to integrate flexible usage billing into your application
Ingest events from your application to track usage.
Aggregate events into meters to track usage by customer.
Invoice your customers for their usage on a monthly basis.
Join companies that trust Polar for accurate, scalable usage-based billing.