TokenFence — Cost Circuit Breaker for AI Agents

2 min read Original article ↗

Now in public beta

Wrap your OpenAI/Anthropic clients in 2 lines of code. Set budget caps, automate model downgrades, and stop runaway loops instantly.

Get StartedView on GitHub

MIT LicenseZero Dependencies

AI agents have unpredictable costs

A single agentic loop can burn through your entire monthly budget in minutes. One bad prompt, one recursive call, and you're looking at a four-figure surprise on your next invoice.

67%

of developers cite cost as #1 barrier to deploying AI agents

$4.2K

average unexpected bill from a single runaway agentic workflow

Estimated API Cost

$0.00

Looking normal...

Three layers of protection

TokenFence wraps your AI client locally. Zero latency overhead, full cost control.

Budget Caps

Set per-workflow spending limits. Never exceed your budget. Enforce hard limits at the SDK level before requests even fire.

Auto Downgrade

When 80% of budget is spent, automatically route to cheaper models. GPT-4o falls back to GPT-4o-mini seamlessly.

Kill Switch

Hard stop at budget limit. Graceful error handling, clean shutdown, no surprise bills. Your agents fail safely.

2 lines. That's it.

No config files, no dashboards to set up. Import, wrap, deploy.

How it works

Five steps from unprotected to fully guarded. All local, all fast.

01

Wrap your AI client

Import TokenFence and wrap your existing OpenAI or Anthropic client. Zero config required.

client = guard(openai.OpenAI())

02

Set your budget

Define spending limits per workflow, per user, or globally. Budgets reset on your schedule.

budget="$0.50"

03

Monitor in real-time

TokenFence tracks every token locally. No proxy, no external calls, no added latency.

# 0ms overhead

04

Auto-downgrade models

At 80% budget, requests automatically route to cheaper models. Quality degrades gracefully.

fallback="gpt-4o-mini"

05

Hard stop at limit

When budget is exhausted, TokenFence stops requests with a clean, catchable exception.

on_limit="stop"

Simple, transparent pricing

Start free. Upgrade when you need more protection.

Hobby

Free

For side projects and experimentation

  • 50K requests/month
  • Basic budget caps
  • Single project
  • Community support
  • Core SDK access

Get Started Free

Recommended

Pro

$49/mo

For production AI applications

  • 500K requests/month
  • Auto model downgrades
  • Per-workflow budget caps
  • Unlimited projects
  • Email support
  • Usage dashboard

Team

$149/mo

For growing teams and organizations

  • 2M requests/month
  • Everything in Pro
  • Team management
  • Priority support
  • Advanced analytics
  • Custom policies

Enterprise

Custom

For teams with advanced needs

  • Unlimited requests
  • SLA guarantee
  • On-premise deployment
  • Dedicated support
  • Custom integrations
  • SSO / SAML
  • Audit logs

Contact Sales

Frequently asked questions

Everything you need to know about TokenFence.

Stop burning money on runaway agents

Ship AI agents with confidence. Set budgets, enforce policies, stop runaway costs. Free to start, no credit card required.

Get Started Free