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
- Webhook - Gateway Entry
- Set - Gateway Config
- HTTP Request - Stripe: Find Customer By API Key
- JS - Resolve Role
- IF - Authenticated
- JS - Check Route Permission
- IF - Authorized
- Redis - Increment Request Counter
- JS - Evaluate Rate Limit
- IF - Within Rate Limit
- JS - Resolve Target Workflow
- HTTP Request - Call Internal Workflow
- JS - Build Gateway Response
- Respond - Success
17 steps in total.
Similar automations
Code, Git & Developer ToolsManage adaptive API rate limiting with a webhook proxy and Redis26 stepsData Sync & ETLIngest paginated API data into Postgres with retries and rate limiting11 stepsCode, Git & Developer ToolsBack Up n8n Workflows to GitLab Organized by User12 stepsContent Writing & GenerationPredict SEO traffic impact scenarios with Postgres and OpenAI GPT-4.119 steps