Skip to content

Protect AI endpoints with sliding-window rate limits

Prevent traffic bursts and abusive scrapers from draining token budgets with smooth per-IP, per-key, and per-user sliding limits.

Copy the prompt and paste it into the AI assistant you already use.

Checklist for smooth sliding-window limits

  1. 01

    Prefer sliding over fixed windows

    Avoid boundary-minute double bursts where callers fire 2x capacity at :59 and :01 seconds.

  2. 02

    Combine burst and sustained caps

    Allow short 5-request interactive bursts while capping total sustained calls per hour.

  3. 03

    Key behind trusted proxy headers

    Extract real client IPs cleanly when traffic arrives via Cloudflare or application proxies.

  4. 04

    Separate limit buckets by route

    Give cheap classification routes generous caps while guarding expensive generation tightly.

Common questions

Why are sliding windows better than fixed 60-second buckets?

Fixed buckets let bursts fire twice the limit across a minute boundary. Sliding windows enforce smooth continuous limits.

Can I limit by tokens consumed instead of just request count?

Yes. Token-bucket and TPM rate limits prevent callers from sneaking huge prompts under a small request-count limit.

Do I need an external Redis instance for distributed limits?

No. APIkit enforces distributed rate limits globally across edge nodes automatically.