Rate Limiting em 2026: Redis 8 e Algoritmos Modernos Com APIs de IA custando por token, rate limiting nunca foi tao critico Em 2026, com APIs de IA que cobram por token, proteger seus endpoints de abuso e ainda mais urgente. Um unico cliente malicioso pode gerar custos enormes em minutos. Redis 8 em 2026 Redis 8 e 100% open source — reverteu a licenca proprietaria do Redis 7.4 Modulo Bloom integrado nativamente — contadores probabilisticos ultraeficientes Performance 2x maior que Redis 7.x em operacoes de incremento ACL v3 — controle de acesso mais granular por cliente Rate Limiting com Token Bucket e Redis 8 Código: import Redis from "ioredis"; const redis = new Redis(process.env.REDIS_URL); async function tokenBucketRateLimit(clientId, maxTokens = 100, refillRate = 10) { const key = `rate_limit:${clientId}`; const now = Date.now() / 1000; const result = await redis.eval(` local key = KEYS[1] local now = tonumber(ARGV[1]) local max_tokens = tonumber(ARGV[2]) local refill_rate = tonumber(ARGV[3]) local bucket = redis.call("HMGET", key, "tokens", "last_refill") local tokens = tonumber(bucket[1]) or max_tokens local last_refill = tonumber(bucket[2]) or now local elapsed = now - last_refill tokens = math.min(max_tokens, tokens + elapsed * refill_rate) if tokens >= 1 then tokens = tokens - 1 redis.call("HMSET", key, "tokens", tokens, "last_refill", now) redis.call("EXPIRE", key, 3600) return {1, math.floor(tokens)} else local wait = (1 - tokens) / refill_rate return {0, 0, math.ceil(wait)} end `, 1, key, now, maxTokens, refillRate); return { allowed: result[0] === 1, remaining: result[1] }; } // Middleware Express app.use("/api/ai-chat", async (req, res, next) => { const clientId = req.headers["x-api-key"] || req.ip; const { allowed, remaining } = await tokenBucketRateLimit(clientId); res.setHeader("X-RateLimit-Remaining", remaining); if (!allowed) { return res.status(429).json({ error: "Rate limit excedido" }); } next(); }); Limites Recomendados por Tipo de Endpoint (2026) Chat com LLM: 10 a 20 req/min por usuario (custo por token) Login/Auth: 5 a 10 req/hora (prevencao de brute force) [*>API publica geral: 100 a 500 req/hora por chave [*>Upload de arquivo: 5 a 10 req/hora Como voce gerencia rate limiting nas suas APIs em 2026?