fix(usage): preserve nested cached_tokens in canonicalizeUsage
buildUsage() only emits cache reads under prompt_tokens_details, so the top-level-only read dropped the count for every Responses-format provider (codex, grok-cli, ...), persisting cached_tokens: 0 and billing cache hits at the full input rate. Mirror the cache_creation fallback already used just above.
This commit is contained in:
@@ -190,7 +190,10 @@ export function canonicalizeUsage(usage) {
|
||||
prompt = prompt + cached + cacheCreation;
|
||||
} else {
|
||||
// OpenAI/Gemini path (or already-canonical input): prompt already includes cached_tokens.
|
||||
cached = num(usage.cached_tokens);
|
||||
// Mirror the cacheCreation fallback above: buildUsage() only ever emits the
|
||||
// nested prompt_tokens_details.cached_tokens shape, so without this the
|
||||
// cache-read count is silently dropped on every buildUsage()-derived usage.
|
||||
cached = num(usage.cached_tokens ?? usage.prompt_tokens_details?.cached_tokens);
|
||||
}
|
||||
|
||||
const result = {
|
||||
|
||||
Reference in New Issue
Block a user