Back to articles
💰I Built a Token Billing System for My AI Agent - Here's How It Works

💰I Built a Token Billing System for My AI Agent - Here's How It Works

via Dev.to WebdevTeja Kummarikuntla

I've been building an AI agent that routes requests across multiple LLM providers, OpenAI , Anthropic etc., based on the task. But pretty quickly, I hit a real problem: how do you charge for this fairly? Flat subscriptions didn't make sense. Token costs vary by model, input vs output, and actual usage. A user generating a two-line summary isn't the same as someone churning out 3,000-word articles, yet flat pricing treats them the same. I looked at a few options for usage-based billing. Stripe Billing has metered subscriptions but you have to build your own token tracking pipeline on top. Orb and Metronome are good, but they're separate vendors, you'd still need something to capture token data from your LLM calls and pipe it in. What I wanted was something at the gateway level, where the traffic already flows. I ended up using Kong AI Gateway with Konnect Metering & Billing (built on OpenMeter ). The gateway proxies every LLM request, so it already knows the token counts. The metering l

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles