-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
// 1. Always set max_tokens — NEVER omit
const model = isPro ? 'claude-sonnet-4-20250514' : 'claude-haiku-4-5-20251001'
const maxTokens = isPro ? 1500 : 300
// 2. Slice context by tier
const contextWindow = isPro ? messages.slice(-20) : messages.slice(-3)
// 3. Rate limiter — 20 req/hr per IP, all tiers
const requests = rateLimiter.get(ip) ?? []
const recent = requests.filter(t => Date.now() - t < 3_600_000)
if (recent.length >= 20) return new Response('Rate limited', { status: 429 })
// 4. Daily message count from DB/session — hard stop by tier
const dailyLimit = tier === 'free' ? 5 : tier === 'pro' ? 100 : Infinity
if (userMsgCount >= dailyLimit) return new Response('Limit reached', { status: 429 })
Originally posted by @thomaslovaslokoy-ui in #1110 (review)