Skip to content
NEWMeet Alaaddin, your AI genie with a voice. trig8n launches 1 January 2027. See what is new

Library / Code, Git & Developer Tools

Code, Git & Developer Tools

Route API traffic with Stripe RBAC and Redis rate limiting

When an API call/webhook arrives, it automates developer work using Redis, Stripe.

What it does

## n8n API Gateway - RBAC + Rate Limiting A single front-door webhook that every client request hits before reaching any backend logic (e.g. the AI SaaS content-generation workflow). It authenticates the API key against Stripe, resolves the customer's role from Stripe metadata, checks that role against a route/method permission map, enforces a sliding-window rate limit per API key in Redis, and only then forwards the request to the target internal workflow — returning a clean 401/403/429 otherwise. ### How to set up 1. Import this workflow into n8n 2. Add credentials: Stripe API, Redis 3. Edit Set - Gateway Config: routePermissions (route -> allowed roles), rateLimits (role -> requests per window), rateLimitWindowSeconds, and the internalWorkflowMap (route -> n8n workflow id/webhook to call) 4. Ensure each Stripe customer has metadata.apiKey and metadata.role (admin | user | readonly) 5. Point client apps at this webhook's URL instead of calling internal workflows directly 6. Activate the workflow ### Requirements - Stripe API access (customer lookup by API key + role metadata) - Redis access (INCR-based sliding/fixed window counters with TTL) - Execute Workflow node wired to (or HTTP call to) your internal backend workflows ### How to customize - Swap Stripe metadata for a dedicated auth service if you outgrow storing roles there - Move from fixed-window to true sliding-window/token-bucket in the Redis Lua/JS step if you need smoother limits - Add per-route (not just per-role) rate limits by keying Redis on role:route instead of just role - Add an audit-log step (write every request outcome to a DB) for compliance/debugging

The steps

  1. Webhook - Gateway Entry
  2. Set - Gateway Config
  3. HTTP Request - Stripe: Find Customer By API Key
  4. JS - Resolve Role
  5. IF - Authenticated
  6. JS - Check Route Permission
  7. IF - Authorized
  8. Redis - Increment Request Counter
  9. JS - Evaluate Rate Limit
  10. IF - Within Rate Limit
  11. JS - Resolve Target Workflow
  12. HTTP Request - Call Internal Workflow
  13. JS - Build Gateway Response
  14. Respond - Success

17 steps in total.

Similar automations