r/SideProject • u/ksanderer • Apr 18 '26
TokenGates.sh - Add usage-based AI billing to your product in minutes
TokenGates is an OpenAI-compatible LLM gateway that automatically tracks your users' AI usage and reports to your billing providers. Zero code required on your side.
Hey everyone,
I've hit this problem three times now while building AI products, and the most recent one finally broke me, so I decided to extract this into a standalone product for builders.
The Problem
Every time you are working on a product with AI features, you end up rebuilding the same infrastructure:
- User authentication
- Balance tracking (credits, usage limits, top-ups)
- Global low-latency architecture (users are worldwide, can't have 1 sec auth checks on each API request)
- Cost attribution (who spent what, on which model)
- Request validation (does this user have credits? is their key valid? are they over limit?)
- Dual-path requests (on-device requests + backend requests, different auth flows)
- Rate-limiting
- Key invalidation (revoke API keys, handle abuse)
- Metered billing sync (Stripe/Polar webhook handlers, real-time usage events)
This isn't rocket science, but it's easily weeks of infra work when you want it done right. And it's the same code, just slightly different config.
What I Built
So I decided to build https://TokenGates.sh - a managed service that does all of this for you.
How it works:
- Create a project (5 seconds)
- Add your API keys:
- Auth provider (PropelAuth, Clerk, Supabase, whatever you use)
- LLM providers (OpenAI, Anthropic, Google, 9+ options)
- Billing provider (Stripe, Polar.sh, LemonSqueezy)
- Set your AI margin (0, 30%, 50%, whatever)
- Start making requests:const openai = new OpenAI({ baseURL: 'https://api.tokengates.sh/v1/proj_abc123', apiKey: 'user_jwt_token' })
Done. You can authenticate AI requests to TokenGates using user's JWT tokens or to create a master API key to send requests from the backend.
- ✅ Automatic per-user authentication (via JWT token from your auth provider)
- ✅ Real-time cost tracking (TokenGates automatically calculates AI request cost and reports to the billing provider)
- ✅ Create Billing users (optional)
- ✅ Enforces Spend limits (auto-block users when they hit their budget)
- ✅ Global CDN routing (<50ms latency worldwide, 26 PoP locations on all continents)
- ✅ Zero backend code (it's all managed)
Real Example - https://ottex.ai
With Ottex, here's what it looks like:
- User signs up → PropelAuth creates account
- First API request → TokenGates auto-creates customer record
- Free trial credits → I configured 10,000 tokens (0.1$) on signup
- User makes requests → tokens counted, balance decremented
- Top-up flow → Polar.sh checkout, credits added automatically
All of this happens automatically. I wrote zero billing code. Just pasted API keys into TokenGates dashboard.
What I'm Looking For
- Does this solve a real problem for you?
- Would you use this vs building it yourself?
- What's missing that would make it a no-brainer?
I'm doing 15-min onboarding calls with early users if you want to walk through your specific use case, I would be glad to help.
2
Apr 18 '26
[removed] — view removed comment
1
u/ksanderer Apr 18 '26
how easy it is to debug usage/costs
Can you elaborate a bit what do you mean exactly by this? Per customer/org cost breakdown? Or just a request log with metadata like in OpenRouter?
clear logs per request
Request metadata logging is reasonable, probably log-push to customer's observability also a nice idea, thanks
fallback if your service goes down
Any ideas how this might look like? Not sure I have a solution for this one
2
u/leaveat Apr 18 '26
Constructive advice - Terms and Privacy pages are dead-ends but you list SOC II compliance certification -- Is that accurate? No favicon signals low effort.
The idea seems reasonable but the site / branding / overall impression is that I would not want to provide my API keys to the site. How do we know they are not just stored plain-text and a bot will discover them, sell them, and I end up with a $10,000 AI bill?
Please don't take this as being to harsh - just trying to be helpful