You send a request to your Large Language Model (LLM) endpoint. It costs money. It takes time. And if you aren't careful, it can bankrupt you in an afternoon. We used to think about API limits as simple requests-per-minute counters. That world is gone. With generative AI, one "request" might cost $0.001, while another costs $2.50 because someone pasted the entire Wikipedia database into the prompt. Rate limiting and abuse detection for Large Language Model endpoints isn't just about keeping the server up; it's about preventing a specific type of financial attack called Denial of Wallet.
The Cost of Uncontrolled Inference
Traditional web APIs are cheap. If someone spams your weather API with 10,000 requests, your CPU gets warm, but your bank account doesn't cry. LLMs are different. Every token generated burns GPU cycles that have a direct dollar value. The OpenAI and Anthropic models we use today charge by input and output tokens. This changes the threat model entirely. An attacker doesn't need to flood your server with traffic to break it. They just need to send a few complex prompts that force the model to generate thousands of words.
This is why standard rate limiters fail here. A limiter set to 60 requests per minute assumes every request is roughly equal. For LLMs, they aren't. You need controls that look at token velocity, not just request count. If a user sends ten short questions, they are fine. If they send one request asking for a 4,000-word essay, they might blow through their quota instantly. Your system needs to estimate the cost before the request even hits the model.
| Metric Type | Traditional API Focus | LLM Endpoint Focus | Why It Matters |
|---|---|---|---|
| Requests Per Minute (RPM) | Primary control mechanism | Secondary / Baseline only | Fails to account for variable compute cost per request |
| Tokens Per Minute (TPM) | Not applicable | Primary control mechanism | Directly correlates to GPU usage and provider billing |
| Concurrency | Thread pool size | Active generation streams | Prevents resource exhaustion from long-running outputs |
| Spend Cap | Rarely enforced per user | Critical hard stop | Protects against runaway costs from bugs or attacks |
Building a Token-Aware Gateway
You shouldn't let raw requests hit your LLM provider directly. Place a gateway between your users and the model. This gateway acts as a bouncer. It checks three things: identity, intent, and estimated cost. First, verify who is sending the request. Is this a logged-in user? A service account? Then, look at the payload. How many characters are in the prompt? What is the `max_tokens` setting?
Here is the trick: reserve the budget before you send the request. If a user asks for a summary of a 10-page document, estimate the input tokens (the document) plus the maximum output tokens they requested. If that sum exceeds their remaining budget for the hour, reject the request immediately with an HTTP 429 status. Don't wait for the model to finish generating and then tell them they went over budget. That’s too late. You’ve already paid for the inference.
Use algorithms like Token Bucket or Leaky Bucket adapted for weights. Instead of each request costing "1" bucket unit, each request costs its estimated token count. A small chat message costs 10 units. A large code-generation task costs 500 units. This smooths out traffic spikes caused by heavy workloads without punishing users who send frequent, lightweight messages.
Detecting Abuse Beyond Simple Limits
Rate limiting stops volume. Abuse detection stops weirdness. Attackers are smart. They will rotate IP addresses. They will create new accounts. They will mimic human behavior. To catch them, you need behavioral analytics. Look for patterns that scream "bot" or "malicious script."
- Prompt Repetition: Is the same user sending nearly identical prompts every second? Humans pause to read. Bots don't.
- Context Window Stuffing: Are users consistently filling the context window to the max? This often signals an attempt to extract training data or confuse the model.
- Tool Call Loops: In agentic workflows, does a single session trigger dozens of tool calls in rapid succession? This could be a logic error or an infinite loop designed to drain credits.
- Geographic Mismatches: Does the account suddenly switch from New York to Singapore mid-session? Combined with high token usage, this is suspicious.
OWASP identifies this risk as Model Denial of Service (DoS). Their guidance suggests that attackers can submit resource-heavy operations to disrupt availability. But remember, for LLMs, DoS is also a financial event. Your detection layer should assign a risk score to each request. Low-risk requests go through fast. High-risk requests get queued, throttled, or blocked pending manual review.
Provider Quirks You Must Handle
Every major provider handles limits differently. Ignoring these nuances leads to failed integrations. Here is what you need to know about the big players as of late 2026.
OpenAI applies limits at the organization and project level, not just per API key. They provide detailed headers like `x-ratelimit-remaining-tokens`. Crucially, they distinguish between temporary rate limits and monthly spend caps. If you hit the rate limit, you retry later. If you hit the spend cap, you’re done until the next billing cycle or until you add funds. Always honor the `Retry-After` header. If you ignore it and hammer the API, you’ll make the problem worse.
Anthropic uses usage tiers (Start, Build, Scale). As of November 2026, they aligned rate limits across Claude Sonnet, Haiku, and Opus within these tiers. They also offer a Rate Limits API, allowing you to programmatically check your current quotas. This is vital for automated scaling systems that need to adjust their own throughput based on available headroom.
Google Gemini measures Requests Per Minute (RPM), Tokens Per Minute (TPM), and Requests Per Day (RPD). These quotas are tied to the Google Cloud Project, not the individual API key. This means if you have multiple apps sharing one project, they share the same bucket. One noisy app can starve the others. Keep this in mind when architecting multi-tenant applications.
Amazon Bedrock assigns quotas based on model, region, and account history. AWS warns that these are upper bounds, not guarantees. Sudden bursts can trigger `ThrottlingException` even if your average traffic is low. They recommend using bounded concurrency and exponential backoff with jitter. Jitter is critical-it prevents all your clients from retrying at the exact same millisecond, which would cause a thundering herd.
Implementing Smart Retries and Fallbacks
When you get a 429 Too Many Requests error, do not panic-retry. A tight retry loop is the fastest way to turn a minor throttle into a full outage. Use capped exponential backoff. Start with a 1-second delay. If it fails again, wait 2 seconds. Then 4. Add random jitter (e.g., ±0.5 seconds) so different clients don't synchronize their retries.
Consider fallback strategies. If your primary model (like GPT-4o or Claude Opus) is rate-limited, can you temporarily route traffic to a cheaper, faster model (like GPT-4o-mini or Claude Haiku)? This keeps the user experience alive, albeit with slightly lower quality, rather than showing an error page. Tools like Cloudflare AI Gateway can automate this routing, providing caching and logging along the way. Just be aware that adding a proxy adds latency. Measure it.
Observability and Incident Response
You cannot protect what you cannot see. Your dashboard must show more than just uptime. Track admitted, delayed, rejected, and retried requests. Monitor p95 and p99 latency. Watch for sudden spikes in token consumption. Set alerts for deviations from the baseline. If token usage jumps 500% in five minutes, something is wrong. Maybe a bug in your frontend is sending infinite loops. Maybe a competitor is scraping your site.
Log everything relevant: tenant ID, user ID, model used, input/output token counts, and the final cost. But be careful with privacy. Do not store raw prompts indefinitely if they contain sensitive data. Encrypt logs and enforce retention policies. When an incident occurs, you need to answer: Who did this? How much did it cost? Was it malicious? Without granular logging, you’re guessing.
What is the difference between rate limiting and abuse detection?
Rate limiting is a quantitative control that restricts the volume of traffic (e.g., 100 requests per minute). Abuse detection is a qualitative analysis that identifies suspicious patterns, such as unusual token usage, bot-like behavior, or credential stuffing, regardless of whether the volume is within the allowed limits.
Why are traditional RPM limits insufficient for LLMs?
Because LLM costs vary drastically per request. A short question costs pennies, while a long-context analysis can cost dollars. RPM treats all requests as equal, failing to prevent expensive outliers from exhausting budgets or resources. Token-based limits (TPM) are necessary to align restrictions with actual computational cost.
How should I handle HTTP 429 errors from LLM providers?
First, check the `Retry-After` header provided by the API. If present, wait that duration. If absent, use exponential backoff with random jitter (e.g., 1s, 2s, 4s + random noise). Avoid immediate retries, as this increases load on the provider and worsens the congestion. Ensure your client has a maximum retry count to prevent infinite loops.
Can I use IP address blocking alone for abuse prevention?
No. IP-only blocking causes false positives because many legitimate users share IPs behind NATs, corporate networks, or mobile carriers. It also fails against distributed attacks where bots rotate IPs. Effective protection combines IP reputation with user identity, device fingerprinting, and behavioral analytics.
What is 'Denial of Wallet' in the context of LLMs?
Denial of Wallet is an attack where an adversary forces the victim to incur excessive costs by triggering expensive operations. For LLMs, this involves submitting complex prompts that require significant GPU processing and token generation, rapidly depleting the account's prepaid balance or credit card limit, effectively stopping service due to financial exhaustion rather than technical failure.

Artificial Intelligence
Tony Griego
December 5, 2026 AT 15:54the cost is the real enemy here not the server load
we spent months thinking our infra was fine until a single user pasted a whole book and we got hit with a $400 bill overnight its funny how one token can be worth more than an entire day of cpu cycles