fix: 前端计费显示缺少 cache_creation_tokens
Read This First (Do Not Remove This Section)
- Docs: https://docs.newapi.ai/
- Usage questions first: https://deepwiki.com/QuantumNous/new-api
- Warning: issues with this template removed, section headings deleted, or content cleared may be closed directly. Repeated abusive submissions may result in a block.
Your current newapi version
[v0.13.1-patch.1](https://github.com/QuantumNous/new-api/releases/tag/v0.13.1-patch.1)
Submission Checks
- [x] I have confirmed there are no similar issues
- [x] I have thoroughly read the docs at https://docs.newapi.ai/ and the project README, especially the FAQ section
- [x] I have not removed any guidance or section headings from this template and will complete it as requested
- [x] I understand that maintainers have limited time and issues that do not follow this template may be ignored or closed directly
Issue Description
当请求经过 Claude Messages → OpenAI Compatible 格式转换时,appendFinalRequestFormat 不会设置 other["claude"] = true(因为最终上游格式是 OpenAI),导致前端路由到 renderModelPrice 而非 renderClaudeModelPrice,同时 real_cost_usd 计算存在双重计费。
Steps to Reproduce
请求经过 Claude Messages → OpenAI Compatible 格式转换时,前端展示的计费过程缺少缓存写的算式
Expected Result
正确对齐费用计算逻辑
Related Screenshots
根因分析
问题 :前端计费显示不含 cache_creation_tokens
数据流:
log_info_generate.go中appendFinalRequestFormat仅在最终请求格式为 Claude 时设置other["claude"] = true- 当 Claude → OpenAI 转换后,
other["claude"]未设置 - 前端
useUsageLogsData.jsx根据other?.claude路由渲染函数:other?.claude→renderClaudeModelPrice(正确处理 cache_creation_tokens)- 否则 →
renderModelPrice(不处理 cache_creation_tokens)
renderModelPrice将所有 prompt_tokens 视为普通输入,忽略 1742 个 cache_creation_tokens 应按 1.25x 倍率计费
实际影响(以 log id 146013 为例):
- 后端实际扣费 quota: 6934(正确)
- 前端显示计费: $0.011690(错误,缺少 cache_creation 部分)
- 正确计费应为: baseInput=531, cacheCreation=1742×1.25=2177.5, (531+2177.5)/1M×$5 + 13/1M×$25 ≈ $0.013868
修复方案
Fix:前端 renderModelPrice 支持 cache_creation_tokens
让 renderModelPrice 和 renderLogContent 能识别并正确渲染 cache_creation_tokens、cache_creation_ratio 等字段,无论 other["claude"] 是否设置。
影响范围
| 组件 | 文件 | 影响 |
|---|---|---|
| 前端计费显示 | web/src/helpers/render.jsx, web/src/hooks/usage-logs/useUsageLogsData.jsx |
用户看到的计费过程与实际扣费不符 |
[Bot Review]
感谢提交。当前内容包含较详细的“问题描述”,但还没有按 Bug Report 模板完整填写,缺少 版本/version、提交确认/Submission Checks,以及单独的 复现步骤/Steps to Reproduce。请按模板补充这些部分,尤其是最小复现步骤、实际结果与预期结果,方便其他人基于同一格式继续查看。
[Bot Review]
This issue has been automatically marked as stale due to inactivity. If this is still relevant, please reply within 7 days — otherwise it will be closed automatically.