Tools
Tools: How to Control AI Agent API Costs: Rate Limiting vs Economic Firewalls
2026-03-05
0 views
admin
The Problem: Agents Spend Money Autonomously ## What Rate Limiting Gets Wrong ## Economic Firewalls: A Different Primitive ## Three Modes of Economic Governance ## Implementation: 5 Minutes to Budget Enforcement ## The Bottom Line Your AI agents are making API calls that cost money — LLM inference, tool calls, third-party services. Most setups have no hard spending limits. An agent loop or prompt injection can burn through hundreds of dollars before anyone notices. Rate limiting doesn't help because it doesn't understand money. Traditional API security answers one question: "Who are you?" OAuth tokens, API keys, JWTs — they verify identity. But identity doesn't tell you if an agent should be allowed to make its 500th OpenAI call today. Rate limiting answers a different question: "How fast are you going?" That's useful for preventing abuse, but 100 requests per minute could cost $0.10 or $100 depending on the model and payload. Rate limits are blind to economics. The question enterprises actually need answered is: "What can you afford?" Real-world scenario: A customer support agent loops on a complex ticket, making 2,000 GPT-4 calls in 30 minutes. Rate limit? 70 req/min — well within bounds. Cost? $340. Budget? $50/day. The rate limiter saw nothing wrong. The CFO disagrees. An economic firewall sits at the same layer as a traditional API gateway, but it understands money. Instead of counting requests, it tracks spend. Instead of rate windows, it enforces budgets. You don't have to go from zero to full budget enforcement overnight: SatGate is an open-source API gateway that implements economic access control: Agents authenticate with capability tokens (macaroons) that carry their budget, scope, and delegation chain. The gateway verifies the token, checks the budget, and either forwards the request or returns an HTTP 402 — "Payment Required." Rate limiting is necessary but insufficient for the agent economy. When AI agents autonomously make API calls that cost money, you need a primitive that understands economics, not just throughput. 🔗 Try the live budget enforcement demo — no signup required
🔗 GitHub — open source, Apache 2.0
🔗 Sandbox — try without signup Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
routes: - path: /v1/chat/completions upstream: https://api.openai.com policy: kind: control pay: mode: fiat402 enforceBudget: true costCredits: 5 - path: /v1/embeddings upstream: https://api.openai.com policy: kind: observe # Just log for now Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
routes: - path: /v1/chat/completions upstream: https://api.openai.com policy: kind: control pay: mode: fiat402 enforceBudget: true costCredits: 5 - path: /v1/embeddings upstream: https://api.openai.com policy: kind: observe # Just log for now COMMAND_BLOCK:
routes: - path: /v1/chat/completions upstream: https://api.openai.com policy: kind: control pay: mode: fiat402 enforceBudget: true costCredits: 5 - path: /v1/embeddings upstream: https://api.openai.com policy: kind: observe # Just log for now - Blind to cost variance — A request to GPT-3.5 costs 100x less than GPT-4 with a large context window. Same rate limit, wildly different spend.
- No cumulative tracking — Rate limits reset every window. They don't know if an agent has spent $5 or $5,000 this month.
- No delegation awareness — When Agent A delegates to Agent B who delegates to Agent C, rate limits can't enforce a shared budget across the chain.
- Can't attribute spend — Which team's agents are driving costs? Rate limits don't track cost centers or departments. - ✅ Per-agent budgets — Each agent gets a spending cap. When it's spent, it's done. Enforced at the gateway layer before the request reaches your upstream.
- ✅ Per-tool cost attribution — Different tools cost different amounts. An MCP proxy can assign costs per tool call — search: 2 credits, code_execute: 10 credits.
- ✅ Delegation hierarchies — A manager agent can delegate a subset of its budget to sub-agents. The parent's budget is the ceiling.
- ✅ Real-time enforcement — Budget checks happen at the gateway, before the request hits your API. Sub-millisecond overhead. - Observe — Let all traffic through. Log everything. See which agents are spending what. Free tier.
- Control — Set budgets per agent. Enforce spending caps. Block requests when budget is exhausted. Works with Stripe, ERP.
- Charge — Monetize your API. L402 Lightning payments — agents pay per request with instant settlement.
how-totutorialguidedev.toaiopenaillmgptfirewallapachegitgithub