Repository navigation
Description
What happened?
This appears to be a follow-up to #1422.
At the time of #1422, Codex CLI did not persist cache-write token usage in rollout token_count events. With @openai/[email protected], I can now confirm that cache_write_input_tokens is present in the session log.
However, [email protected] still reports cacheCreationTokens: 0, so the GPT-5.6 Terra cache-write cost is not included in costUSD.
Example Codex SDK log:
{"timestamp":"2026-08-20T05:49:12.034Z","ordinal":177,"type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":935040,"cached_input_tokens":875306,"cache_write_input_tokens":57610,"output_tokens":11150,"reasoning_output_tokens":1141,"total_tokens":946190},"last_token_usage":{"input_tokens":58697,"cached_input_tokens":57817,"cache_write_input_tokens":0,"output_tokens":227,"reasoning_output_tokens":9,"total_tokens":58924},"model_context_window":258400},"rate_limits":null}}For the same session, ccusage codex daily --json reports:
{
"cacheCreationTokens": 0,
"cacheReadTokens": 875306,
"costUSD": 0.42832919999999997,
"inputTokens": 59734,
"models": {
"gpt-5.6-terra": {
"cacheCreationTokens": 0,
"cacheReadTokens": 875306,
"inputTokens": 59734,
"outputTokens": 11150,
"reasoningOutputTokens": 1141,
"totalTokens": 946190
}
}
}The session contains cache_write_input_tokens: 57610, but ccusage reports cacheCreationTokens: 0.
Since GPT-5.6 Terra charges separately for cache writes, this also causes the reported cost to be underestimated.
Steps to reproduce
- Use
@openai/[email protected]with thegpt-5.6-terramodel. - Run a session that produces cache writes.
- Confirm that the generated Codex session log contains a non-zero
cache_write_input_tokensvalue. - Run:
ccusage codex daily --json- Check the corresponding session in the output.
- Observe that
cacheCreationTokensis0even thoughcache_write_input_tokensis non-zero in the Codex log.
Expected behavior
ccusage codex daily should read cache_write_input_tokens from Codex session logs and include it in cacheCreationTokens.
The cache write tokens should also be included in the cost calculation using the appropriate cache write pricing for the model.
For the example above, cacheCreationTokens should reflect the 57610 cache write input tokens instead of 0.
Version
20.0.20
Activity
github-actions commentedon Aug 20, 2026
This issue was auto-closed. Issues from new contributors are auto-closed by default.
Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.
Keep the issue short, concrete, and written in your own voice.
If a maintainer replies
lgtmi, your future issues will stay open. If a maintainer replieslgtm, your future issues and PRs will stay open.See CONTRIBUTING.md.
pullfrog commentedon Aug 20, 2026
Assessment
This issue is actionable and worth reopening for implementation. The report includes a concrete
token_countpayload withcache_write_input_tokens: 57610, a reproducible command, and an expected result. The issue is currently closed by the repository's automatic new-contributor workflow, not because the defect was disproven.The current branch still has the reported gap:
rust/adapters/codex/src/types.rsparses cached reads but has no cache-write field.rust/adapters/codex/src/parser.rsomits cache writes from both direct usage events and cumulative-total subtraction.rust/adapters/codex/src/report.rshard-codescacheCreationTokensto0and does not include cache-write pricing.rust/crates/ccusage-adapter-all/src/loader.rsalso hard-codes Codex cache creation to0for unified reports.gpt-5.6-terrapricing already contains cache-write rates:2.5per million normally and5per million above the model's272000context threshold. The missing work is usage plumbing and Codex billing, not pricing data acquisition.Issue #1422 documented the same root cause and proposed the broad shape of this fix. Issue #1617 adds confirmation from a newer Codex SDK that the field is now actually present in session logs.
Implementation Plan
cache_write_input_tokens, with the existing cache-creation spelling as a compatibility alias if appropriate. Add the field toCodexRawUsage, propagate it through direct token events and headless/exec usage, and include it in cumulative-total delta subtraction. Normalize it so cache reads and cache writes form non-overlapping portions of the reported input.CodexTokenUsageEvent,CodexUsageBucket,CodexModelUsage, andCodexGroup. Update long-context tracking, service-tier buckets, group merges, replay handling, and all event deduplication keys so cache-write differences cannot be dropped or double-counted.cacheCreationTokensis populated at group, model, and totals levels, and so plaininputTokensexcludes both cache reads and cache writes. Extend Codex cost calculation with the existing shared cache-write rates, including the model-specific long-context rate and the existing standard/fast service-tier behavior. Use a narrow shared pricing accessor or helper if needed rather than exposing unrelated pricing internals.codex_group_rowto expose the same cache-creation and non-cached-input breakdown as focused Codex reports, preserving focused/unified cost parity.gpt-5.6-terrashort and long-context pricing, focused daily JSON, and unified rows. Update affected snapshots and retain coverage proving logs without the new field remain unchanged.ccusagetests, formatting, and the workspace validation prescribed by the repository.No implementation changes were made during this evaluation.
Task list (3/4 completed)
@v0or keep the SHA fresh with Dependabot | Implement plan ➔ | View workflow run | via Pullfrog | UsingGPT Luna(free via Pullfrog for OSS) | 𝕏ryoppippi commentedon Aug 27, 2026
@pullfrog Triage this issue using the repository standing issue-triage instructions. Inspect the full issue body, comments, current main branch, and related issues or pull requests. Choose exactly one priority label. If the issue is clearly unresolved and is priority:critical or priority:high with safe and well-scoped requirements, implement it and open a focused pull request. Otherwise, only triage it. Keep the explanation short and use simple English.
pullfrog commentedon Aug 27, 2026
Priority: high.
This is a confirmed billing bug on current
main: Codex logs can contain cache-write tokens, but ccusage drops them, socacheCreationTokensandcostUSDare too low. The requirements are clear and the fix is safe and focused. I prepared the fix and tests, but I could not open the PR because pushing the branch failed with:remote: Permission to ccusage/ccusage.git denied to github-actions[bot]. fatal: unable to access 'https://github.com/ccusage/ccusage.git/': The requested URL returned error: 403. PR creation then failed with:Validation Failed: {"resource":"PullRequest","field":"head","code":"invalid"}.@v0or keep the SHA fresh with Dependabot | View workflow run | via Pullfrog | UsingGPT Luna(free via Pullfrog for OSS) | 𝕏github-actions commentedon Aug 28, 2026
Pullfrog triage: priority:high
A maintainer explicitly requested an implementation attempt. Confirmed, repository-scoped billing bug: current Codex parsing and reports ignore cache-write tokens, causing GPT-5.6 Terra costs and cacheCreationTokens to be understated. The reproduction, expected behavior, and affected code paths are concrete and safely scoped for a focused fix.
Decision: kept open; Pullfrog will attempt a focused implementation PR.
ryoppippi commentedon Aug 31, 2026
Historical audit: this discussion was auto-closed by the legacy contributor gate. That closure did not assess technical importance.
Audit result: resolved. A later merged change or the current
mainimplementation covers this request. This item is kept for history and does not need to be reopened.