fix(usage): price Claude fast-mode requests at the fast rate (#13599)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-09-25 00:58:13 -07:00
1 parent 86054b6df2
commit e3e7cc3fc2
8 files changed
+129 -38

No files matched your search

+9 -3
View File
@@ -23,7 +23,8 @@ import type { CodexScanState, UsageRecord } from "./usageTranscripts.ts";
// entries would keep serving double-counted records forever.
// v3: entries carry the parse position and reducer state so a grown file
// re-parses only its appended bytes instead of starting over.
const USAGE_SCAN_CACHE_VERSION = 3 as const;
// v4: records carry Claude fast mode, which v3 rows never captured.
const USAGE_SCAN_CACHE_VERSION = 4 as const;
export interface CachedFile {
readonly size: number;
@@ -58,6 +59,7 @@ type SerializedRecord = readonly [
reasoningTokens: number,
dedupeKey: string | null,
reportedCostUsd: number | null,
fast: 0 | 1,
];
interface SerializedFile {
@@ -109,6 +111,7 @@ export function encodeScanCache(cache: ScanCache): SerializedCache {
record.totals.reasoningTokens,
record.dedupeKey,
record.reportedCostUsd,
record.fast ? 1 : 0,
];
const files: Record<string, SerializedFile> = {};
@@ -165,7 +168,7 @@ export function decodeScanCache(document: unknown): ScanCache {
): UsageRecord[] | null => {
const records: UsageRecord[] = [];
for (const row of rows) {
if (!isRecordArray(row) || row.length < 10) return null;
if (!isRecordArray(row) || row.length < 11) return null;
const [
timestampMs,
modelIndex,
@@ -177,6 +180,7 @@ export function decodeScanCache(document: unknown): ScanCache {
reasoning,
dedupeKey,
reportedCostUsd,
fast,
] = row as SerializedRecord;
const model = typeof modelIndex === "number" ? models[modelIndex] : undefined;
@@ -188,7 +192,8 @@ export function decodeScanCache(document: unknown): ScanCache {
!Number.isFinite(cached) ||
!Number.isFinite(cacheCreation) ||
!Number.isFinite(output) ||
!Number.isFinite(reasoning)
!Number.isFinite(reasoning) ||
(fast !== 0 && fast !== 1)
) {
return null;
}
@@ -206,6 +211,7 @@ export function decodeScanCache(document: unknown): ScanCache {
reasoningTokens: reasoning,
},
reportedCostUsd: typeof reportedCostUsd === "number" ? reportedCostUsd : null,
fast: fast === 1,
dedupeKey: typeof dedupeKey === "string" ? dedupeKey : null,
});
}