Your model provider tells you what the whole account spent. It does not tell you that one free-tier user generated a third of it. Until cost is attributed per user, every pricing decision — plan limits, free-tier caps, whether that enterprise deal is even profitable — is a guess. Here is the schema I use, and the two decisions in it that took real debugging to learn.
One row per model request
Every request writes exactly one row, at the moment usage is known — from the stream's finish hook, or right after a non-streaming call returns:
export async function recordUsage ( args : RecordUsageArgs ): Promise < void > { await db () . insert ( usageEvents ) . values ({ userId : args . userId , model : args . model , route : args . route , // which feature spent the tokens, e.g. "chat" inputTokens : args . usage . inputTokens , outputTokens : args . usage . outputTokens , cacheReadTokens : args . usage . cacheReadTokens , cacheCreationTokens : args . usage . cacheCreationTokens , costMicroUsd : Math .…