link the usage with the session to display together

This commit is contained in:
Owen
2026-08-11 16:14:46 -04:00
parent c42df737b0
commit f7aca85417
9 changed files with 129 additions and 8 deletions
+6
View File
@@ -428,6 +428,11 @@ export type UsageRecordInput = {
usage: AiUsage;
costUsd: number | null;
createdAt?: number;
// Same id as the aiSessionLog row logged for this request, so the two
// can be joined to show token/cost usage alongside the session
// transcript. Undefined when the session wasn't logged (e.g. session
// log retention disabled for the org).
sessionId?: string;
};
type AiUsageRecordInsert = InferInsertModel<typeof aiUsageRecords>;
@@ -539,6 +544,7 @@ export async function recordUsage(input: UsageRecordInput): Promise<void> {
resourceId: input.resourceId,
siteResourceId: input.siteResourceId,
userId: input.userId,
sessionId: input.sessionId,
requestedModel: input.requestedModel,
promptTokens: usage.promptTokens,
cacheReadTokens: usage.cacheReadTokens,