Repository navigation
[upstream #110] Bill cache_creation_input_tokens in prompt_tokens_details (9823ebc7e) - #111
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 关联任务 / Related Issue
🚀 变更类型 / Type of change
📝 变更描述 / 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