---
name: "upstash-redis-ratelimit-edge"
description: "Rate-limit serverless and edge functions with sub-millisecond HTTP calls using Upstash Redis."
metadata:
  author: "Upstash"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "setup upstash ratelimit"
  - "sliding window rate limit edge"
  - "serverless rate limiting redis"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Upstash Redis Edge Rate Limiting & Sliding Windows

Implements @upstash/ratelimit and @upstash/redis: algorithms (slidingWindow, fixedWindow, tokenBucket), multi-region Redis replication, ephemeral analytics, and blocking abusive IP requests at edge middleware.

## When to Invoke
Invoke this skill whenever you need to:
- setup upstash ratelimit
- sliding window rate limit edge
- serverless rate limiting redis

## Execution SOP & Rules
1. Initialize: const ratelimit = new Ratelimit({ redis: Redis.fromEnv(), limiter: Ratelimit.slidingWindow(10, '10 s') }).
2. Check limit: const { success, limit, remaining, reset } = await ratelimit.limit(identifier);
3. In middleware: if (!success) return new Response('Rate limit exceeded', { status: 429 });
4. Pass remaining quota headers back to client for transparent rate limit visibility.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
