Skip to content

// 1. Always set max_tokens — NEVER omit #1111

@thomaslovaslokoy-ui

Description

@thomaslovaslokoy-ui

// 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions