Stop runaway AI spend
before it stops you.
A drop-in proxy that enforces per-customer token budgets on every LLM request. Block abuse with 429. Never take down production when Redis hiccups.
-H "x-bucket: customer-123"
Built for peace of mind
Every feature designed to keep your LLM API costs predictable and your production stable.
Real-time Budget Enforcement
Returns HTTP 429 when budget is exhausted — blocks the request BEFORE it reaches the LLM provider. No surprise bills.
Per-Bucket Token Budgets
Set limits per customer, feature, or environment. Track usage from real provider metadata for both streaming and non-streaming responses.
Fail-Open Architecture
If Redis is down, LLM traffic still flows. Availability over enforcement — never take down production because of rate limiting.
Self-Hosted & Private
Deploy via Docker Compose in your own infra. No vendor lock-in, no data leaving your network. Your API keys pass through unchanged.
Admin API for Balance Management
Get, set, or top up bucket balances via REST API. No need for redis-cli or manual database manipulation.
Zero Latency Overhead
Tiny footprint, minimal latency. Drop-in replacement for OpenAI/Anthropic endpoints — works with existing SDKs.
Single Provider, Single Instance
One upstream per deploy. Point Token Guard at OpenAI or Anthropic — your app calls one consistent endpoint.
Abuse Prevention
Stop bad actors from draining your credits. Per-customer quotas mean one compromised key can't burn your whole budget.
Drop-in protection in 4 steps
Point your app at Token Guard. Add bucket headers. That's it.
Add Token Guard to your stack
Deploy via Docker Compose. Point your app at Token Guard instead of the LLM provider. Pass your existing provider keys through unchanged.
# docker-compose.yml
services:
token-guard:
image: tokenguard/token-guard:latest
ports:
- "8000:8000"
environment:
- UPSTREAM_URL=https://api.openai.com
- REDIS_URL=redis://redis:6379Set bucket budgets
Create a budget bucket for each customer, feature, or environment. Use the Admin API to set token limits and top up balances.
# Create a bucket with 100K tokens
curl -X PUT http://localhost:8000/admin/buckets/customer-123 \
-H "Content-Type: application/json" \
-d '{"balance": 100000}Make requests with bucket headers
Include the bucket ID in your request headers. Token Guard checks the budget before forwarding. If exhausted, returns 429 immediately.
# Your app sends requests with bucket header
curl https://tokenguard.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_OPENAI_KEY" \
-H "x-bucket: customer-123" \
-d '{"model": "gpt-4", "messages": [...}'Tokens deducted automatically
Token Guard reads the usage metadata from the provider response (streaming or non-streaming) and deducts tokens from the bucket balance.
# Response includes usage info
{
"id": "chatcmpl-abc123",
"usage": {
"prompt_tokens": 25,
"completion_tokens": 100,
"total_tokens": 125
}
}
# → 125 tokens deducted from bucketSimple pricing. Open source first.
Free forever. Self-host everything. Pro features coming soon for teams that want managed infrastructure.
What Token Guard is NOT (yet)
We believe in being upfront about limitations. Here's what's not included in v1:
Up and running in 5 minutes
Clone. Configure. Deploy. Start protecting your LLM API budget.
Clone the repository
git clone https://github.com/sakshamrai101/token_guard_ai.git
cd token_guard_aiOr use the Docker image directly
Configure environment
# .env
UPSTREAM_URL=https://api.openai.com
REDIS_URL=redis://localhost:6379
PORT=8000Point to OpenAI or Anthropic
Deploy with Docker
docker-compose up -dToken Guard is now running on port 8000
Set a bucket budget
curl -X PUT http://localhost:8000/admin/buckets/my-first-bucket \
-d '{"balance": 100000}'100K tokens allocated
Make your first request
curl http://localhost:8000/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "x-bucket: my-first-bucket" \
-d '{"model":"gpt-4","messages":[...]}'Tokens deducted automatically
Frequently asked questions
Everything you need to know about Token Guard.
Still have questions?
Open an issue on GitHub or reach out to the team.