research31 min studyLesson 89 in Engineering

Abuse detection and rate controls

Combine cost-aware admission, bounded bursts, and calibrated detection while respecting false positives and distributed enforcement limits.

On this page

What you’ll understand

  • Separate resource admission from semantic abuse classification.
  • Calculate token-bucket burst limits and rate-based recovery.
  • Interpret detection thresholds through base rates and user impact.

A language-model endpoint can receive harmless expensive requests and harmful cheap ones. One control must protect scarce compute; another may assess policy violations. Treating requests per second as a complete abuse strategy confuses these purposes and ignores prompt length, generated tokens, tool calls, and account behavior. A useful design states what is being limited, who shares a budget, and what happens when evidence is uncertain.

Budget the resource actually consumed

Define charging units that track the constrained resource: input and output tokens, accelerator time, tool invocations, or a documented combination. A request-count limit can be a first boundary, but equal requests need not have equal cost. Apply limits at appropriate layers such as credential, tenant, endpoint, and overall service. Shared IP addresses can represent many legitimate users, while one actor may control many identities, so no single key solves attribution.

A token bucket accumulates credit at rate r up to capacity b; an admitted request consumes credit. Its burst allowance lets short demand spikes pass without permitting an unlimited long-run rate. Distributed replicas need a clear consistency and overshoot policy for shared limits. Independent local buckets multiply aggregate allowance unless deliberately partitioned. Admission should occur before expensive work where possible, with cancellation and maximum output budgets constraining work already in flight.

A(t2)−A(t1)≤b+r(t2−t1)A(t_2)-A(t_1)\le b+r(t_2-t_1)
This ideal single token-bucket envelope bounds admitted charged units over any interval when the bucket capacity is b, refill rate r, and no implementation overshoot occurs. Units must match the charged work.↔ Scroll wide equations horizontally.

Make detector uncertainty operational

A classifier score is not an authenticated identity or a universal abuse probability. Validate it on relevant populations, inspect calibration, and measure false positives alongside recall. Base rates matter: even a low false-positive rate can create substantial review work when legitimate traffic dominates. Use proportionate actions such as additional review or a constrained path where appropriate, instead of treating every uncertain score as proof of misconduct.

Keep a way to investigate and correct erroneous decisions, and monitor effects across user groups and changing traffic. Minimize retained sensitive content and define access and deletion policies for review evidence. Adaptive behavior can shift the distribution after deployment, so a fixed benchmark result has a limited shelf life. Rate controls can slow repeated probing, but they do not establish confidentiality, prevent all misuse, or replace authorization.

Respond without creating a retry storm

HTTP 429 communicates rate limiting and can include Retry-After. Clients should respect server guidance and use bounded retries with jitter where retries are appropriate. A rejected generation request must not automatically launch multiple parallel replacements. Distinguish temporary capacity rejection from a persistent policy denial so client libraries do not repeatedly retry an action that will remain forbidden.

Track admitted work, rejected work, enforcement latency, budget overshoot, and completed useful responses. Under severe overload, even generating detailed rejection responses costs resources, so infrastructure may need earlier connection-level protection. Test limiter-store failure policy deliberately: failing open protects availability but may exhaust compute; failing closed preserves a budget while denying legitimate service. State the chosen tradeoff and provide a constrained recovery path rather than letting it emerge accidentally.

trefill=c−qr(c>q, r>0),ρ=λμt_{\mathrm{refill}}=\frac{c-q}{r}\quad(c>q,\ r>0),\qquad \rho=\frac{\lambda}{\mu}
If a request costs c units and the bucket holds q<c, refill time is (c−q)/r without other consumption, provided c≤b. Utilization ρ compares compatible arrival and service rates; it does not model semantic abuse.↔ Scroll wide equations horizontally.

Reason about an inference token bucket

A bucket holds at most 600 charged units and refills at 120 units/s. Each illustrative request costs 60 units. It starts full and receives twenty requests immediately, with no concurrent refill during the instant.

  1. The full bucket can admit 600/60 = ten requests immediately.

  2. The remaining ten requests require 600 more units, which need 600/120 = five seconds to refill if no other traffic consumes credit.

  3. The long-run rate supported by this budget is 120/60 = two requests/s for this fixed request cost.

  4. If four replicas each accidentally enforce the full bucket independently, the system can allow a 2,400-unit aggregate burst and 480 units/s, quadrupling the intended shared budget.

The result

Bucket parameters describe charged work and burst behavior. They require deliberate coordination when enforcement is replicated.

Explore the model

Interactive lab

Interactive lab · queue

Connect admission to backlog

Change arrival rate λ and service rate μ in the fluid backlog max(0, 4 + (λ − μ)t). The separate M/M/1 readout assumes Poisson arrivals and exponential service. This is not a token-bucket implementation or abuse classifier; it shows why unchecked admitted demand can accumulate.

Connect admission to backlogFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAdmission and budgets keep accepted work compatible with capacity, while abuse classification answers a separate question.

Check your understanding

Four replicas independently apply the same full per-tenant token bucket. What risk follows without coordination or partitioning?

Try it yourself

A bucket capacity is 200 units, current credit 20, refill 30 units/s, and a request costs 80. Find earliest admission with no competing traffic. Could a 250-unit request ever fit under these rules?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Calculate missing credit, then compare request cost with the capacity before assuming waiting always helps.

Compare with the solution

The request needs 60 additional units, requiring 60/30 = two seconds. A 250-unit request never fits a bucket capped at 200 under the stated rules, regardless of waiting. It needs rejection, smaller work, or a separately authorized budget; endless retries cannot solve the capacity mismatch.

Take it with you

  • Charge and limit the scarce resource instead of assuming every request costs the same.
  • Detection scores require calibration, false-positive analysis, and proportionate responses.
  • Distributed rate enforcement and retry behavior must have explicit overshoot and failure policies.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.