AI Agent Rate Limiting — Your Agent Consumed 1.5M Tokens in 5 Minutes Last Night.
Your AI agent consumed 1.5M tokens in a single session last night — without rate limiting. The result: $12,000 in cloud costs, your CTO called the finance controller. Here's how to prevent it.
What is Rate Limiting? Simply explained.
Think of rate limiting like a gas station: you can only pump as much as your credit allows. When you hit the limit, you must wait or pay more. For AI agents, this is even more critical: without rate limiting, a single agent can exhaust all resources and block other users. Good rate limiting means: token-based limits, tool-call throttling, session quotas, and dynamic adjustment.
↓ Jump to technical depth4-Layer Rate Limit Defense Architecture
Token-Based Rate Limiting
Rate limit based on token consumption instead of request count. Prevents token flooding attacks.
token_rate_limit:
enabled: true
user_quota:
tokens_per_minute: 10000
tokens_per_hour: 100000
counting:
include_rag_tokens: trueTool Call Throttling
Separate rate limits for tool calls. Tools can be more expensive or dangerous than LLM generation.
tool_rate_limit:
enabled: true
tools:
database_query:
calls_per_minute: 20
file_write:
calls_per_minute: 5Agent Session Quotas
Session-based quotas limit total resources per session. Prevents long-running workflows from exhausting resources.
session_quotas:
enabled: true
session:
max_total_tokens: 100000
max_tool_calls: 500Dynamic Rate Adjustment
Dynamic adjustment based on system load, user tier, and threat level.
dynamic_rate_limit:
enabled: true
user_tiers:
free:
multiplier: 1.0
enterprise:
multiplier: 100.0Real-World Scars: Production Incidents
An agent consumed 1.5M tokens in 5 minutes without rate limiting. $12,000 in cloud costs. Fix: Token-based rate limiting, session quotas.
An attacker flooded the API with tool call requests. Database crashed, all services down. Fix: Tool call throttling, global limits.
Immediate Actions: What to do today?
Enable Token-Based Rate Limiting
Set token quotas per minute/hour/day.
Enable Tool Call Throttling
Set limits per tool (database_query, file_write).
Enable Session Quotas
Set max tokens and max tool calls per session.
Interactive Rate Limit Checklist
Rate Limit Security Score Calculator
Industry Average: 25/100