An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
import { capture } from './dispatch'
export interface ChatLimitEventData {
/** Outcome of the overall chat rate-limit check */
outcome: 'allowed' | 'blocked'
/** Authenticated Supabase user ID */
userId: string
/** Current daily usage count after the check (incl. this attempt) */
used: number
/** Effective daily limit at the time of the check */
limit: number
}
/**
* Track the overall (all-modes) per-user daily chat limit events.
*
* Fires on every authenticated request:
* - `outcome: "allowed"` while under the cap (with running counter), so we
* can plot daily usage distribution and percentiles.
* - `outcome: "blocked"` when the request is denied, so we can monitor the
* 429 hit-rate over time and decide whether to relax / tighten the cap.
*/
export async function trackChatLimitEvent(
data: ChatLimitEventData
): Promise<void> {
const { userId, outcome, used, limit } = data
await capture({
event: 'chat_limit_check',
distinctId: userId,
properties: { outcome, userId, used, limit }
})
}