Перейти к основному содержимому

Дневной лимит

Daily token cap (per user) 100,000
Resets at UTC midnight (in 12h 16m)
Counts input + output tokens (recorded in onFinish)

Caps cost-amplification abuse. With premium models running roughly $1–2 per 100k tokens, the worst case is bounded to a known dollar figure per user per day — even if every credential leaks at once.

Использовано сегодня

Шаблон check-then-charge

  1. Check on entry. Before the chat handler streams a response, it reads the day-keyed Redis counter for the user and rejects with 429 if the cap is already reached.
  2. Charge in onFinish. Once the AI SDK signals the stream is done with usage data, the handler increments the counter by inputTokens + outputTokens.
  3. TTL on every write. Each charge sets a 25h TTL so today's bucket auto-expires after the next reset.

This is check-then-charge, not pre-charge-then-reconcile. A burst of N parallel requests can each pass the gate before any has charged, so the daily total can overshoot by up to N × AI_MAX_TOKENS before the cap engages. Worst-case overshoot is well under a dollar per user — acceptable for v1.