Skip to content

[upstream #110] Bill cache_creation_input_tokens in prompt_tokens_details (9823ebc7e) - #111

Merged
woncc merged 1 commit into
mainfrom
codex/r3-0202-issue-110-9823-cache-creation
Nov 1, 2026
Merged

woncc merged 1 commit into
mainfrom
codex/r3-0202-issue-110-9823-cache-creation

Conversation

@woncc

@woncc woncc commented Nov 1, 2026

Copy link
Copy Markdown

🔗 关联任务 / Related Issue

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)

📝 变更描述 / Description

接入 prompt_tokens_details.cache_creation_input_tokens,按缓存创建价格计费;与已有缓存写入字段取最大值,避免重复计费。合并 usage 和 Chat → Responses 转换保留该字段。

仅干净应用指定上游提交,6 个文件,patch-id 一致。未实施 #81/#82 或其他上游提交。由 Codex 辅助移植和验证,保留原作者。

📸 运行证明 / Proof of Work

  • 原定 GOMAXPROCS=2 go test -count=1 -timeout=180s ./relaykit/dto ./relaykit/relayconvert/... ./service -run 'Usage|Cache|Quota|Billing|Text|Merge':失败。根模块不包含独立 relaykit 模块;service 中 OAuth/SQL 测试夹具缺少 separate trusted installer。
  • 在 relaykit/ 执行 GOMAXPROCS=2 GOWORK=off go test -count=1 -timeout=180s ./dto ./relayconvert/... -run 'Usage|Cache|Quota|Billing|Text|Merge':通过。
  • 在 relaykit/ 执行 GOMAXPROCS=2 GOWORK=off go build ./...:通过。
  • 根目录 GOMAXPROCS=2 go test -count=1 -timeout=180s ./service -run 'TestCalculateTextQuotaSummary':通过;新增用例验证缓存创建计费为 525、缺字段为 450、重复字段取最大值。
  • git diff --check、git diff --cached --check:通过。
  • 未进行真实提供商请求;宽筛选测试的环境缺口未消除。

✅ 提交前检查项 / Checklist

…ens_details (QuantumNous#7909)

OpenAI-compatible upstreams with explicit context cache (e.g. Alibaba Bailian)
report cache-write tokens as prompt_tokens_details.cache_creation_input_tokens.
The field was ignored, so cache-write tokens were billed at the plain input
price instead of the cache-creation price.

Parse it into InputTokenDetails.CacheCreationInputTokens and include it in
CacheCreationTokensTotal using max() with the existing cache-write fields, so
the same tokens are never counted twice.
@woncc
woncc merged commit 823d022 into main Nov 1, 2026
@woncc
woncc deleted the codex/r3-0202-issue-110-9823-cache-creation branch November 1, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[上游/现在能解] 9823ebc7e cache_creation_input_tokens 计入计费(e9d4后CLEAN)

2 participants