QuantumNous / QuantumNous/new-api
Codex CLI 经 new-api 中转后 token / quota 消耗显著高于直连,疑似 prompt cache 未正确透传
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 48.5k
- Forks
- 11.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 58
Description
Codex CLI 经 new-api 中转后 token / quota 消耗显著高于直连,疑似 prompt cache 未正确透传
提交前必读(请勿删除本节)
- 文档:https://docs.newapi.ai/
- 使用问题先看或先问:https://deepwiki.com/QuantumNous/new-api
- 警告:删除本模板、删除小节标题或随意清空内容的 issue,可能会被直接关闭;重复恶意提交者可能会被 block。
您当前的 newapi 版本
自编译部署,线上 /api/status 返回 version="";当前构建基于 main@ed6ff0f2(2026-03-19)
提交确认
- 我已确认目前没有类似 issue
- 我已完整查看过文档 https://docs.newapi.ai/ 和项目 README,尤其是常见问题部分
- 我未删除此模板中的任何引导内容或小节标题,并会按要求完整填写
- 我理解项目维护者精力有限,不遵循模板要求的 issue 可能会被无视或直接关闭
问题描述
在相近使用场景下,OpenAI Codex CLI 直连官方与通过 new-api 中转,消耗差异非常大。
测试环境信息:
OpenAI Codex v0.116.0- 模型:
gpt-5.4 reasoning xhighsummaries auto258K window- new-api 版本号 ed6ff0f26705335bb1a28e422970db3865fdd559
2026-03-22 观察到的一组对比数据如下:
| 场景 | total | input | cached input | output |
|---|---|---|---|---|
| 直连官方 | 801,069 | 656,780 | 18,488,320 | 144,289 |
通过 new-api 中转 |
7,770,990 | 7,707,694 | 1,693,824 | 63,296 |
从这组数据看:
- 中转后的未缓存输入约为直连的
11.74x - 中转后的缓存输入仅为直连的
9.16% - 但中转后的输出反而只有直连的
43.87%
这说明问题不像是“输出变多导致消耗变大”,更像是通过 new-api 中转后,Codex 的缓存命中没有被正确保留/透传,或者大量重复上下文被按未缓存输入计
算了。
补充说明:
- 这不是完全相同 session 的逐请求 A/B,但在相近任务强度下多次观察到同样趋势
- 这里不是单纯的前端额度窗口展示误标问题,因为 Codex CLI 自己显示的
Token usage也同步异常 - 我已看过现有相近 issue,
#3309更偏向缓存字段识别/展示,#3317是 Codex free 窗口展示问题,和这次“中转后真实消耗显著放大”不完全相同
复现步骤
- 部署自建
new-api实例,并配置可供 Codex CLI 使用的 OpenAI 兼容中转入口 - 使用
OpenAI Codex v0.116.0 - 模型选择
gpt-5.4,并保持reasoning xhigh、summaries auto - 分别测试两种方式:
- 直连官方
- 将 Base URL 改为
new-api中转地址
- 在相近的仓库/任务场景下持续进行多轮对话
- 对比 Codex CLI 中显示的
Token usage、input、cached input、output以及额度窗口变化
预期结果
通过 new-api 中转时,Codex 的 token / quota 消耗应与直连官方处于接近量级。
尤其在长会话场景下:
- 缓存命中不应明显失效
- 不应出现
cached input大幅下降、input大幅上升的异常现象 - 如果上游已返回缓存相关 usage 信息,
new-api应正确识别并透传,避免把本应走缓存的上下文按未缓存输入计算
相关截图
已附 3 张截图,时间均为 2026-03-22:
相同强度下,中转的消耗量巨大
- Codex CLI 直连官方时的用量截图
╭─────────────────────────────────────────────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.116.0) │
│ │
│ Visit https://chatgpt.com/codex/settings/usage for up-to-date │
│ information on rate limits and credits │
│ │
│ Model: gpt-5.4 (reasoning xhigh, summaries auto) │
│ Directory: ~/.codex │
│ Permissions: Full Access │
│ Agents.md: AGENTS.md │
│ Account: (Team) │
│ Collaboration mode: Default │
│ Session: │
│ │
│ 5h limit: [███████████████░░░░░] 77% left (resets 15:17) │
│ Weekly limit: [███████████████████░] 93% left (resets 10:17 on 29 Mar) │
╰─────────────────────────────────────────────────────────────────────────────────╯
62% used · 5h 77% · 258K window · 19.3M used · 19.1M in · 144K out
Token usage: total=801,069 input=656,780 (+ 18,488,320 cached) output=144,289 (reasoning 59,283)
2. Codex CLI 通过 new-api 中转后的用量截图
╭─────────────────────────────────────────────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.116.0) │
│ │
│ Visit https://chatgpt.com/codex/settings/usage for up-to-date │
│ information on rate limits and credits │
│ │
│ Model: gpt-5.4 (reasoning xhigh, summaries auto) │
│ Directory: ~/code/ │
│ Permissions: Full Access │
│ Agents.md: │
│ Account: (Team) │
│ Collaboration mode: Default │
│ Session: │
│ │
│ 5h limit: [░░░░░░░░░░░░░░░░░░░░] 0% left (resets 13:07) │
│ Weekly limit: [██░░░░░░░░░░░░░░░░░░] 10% left (resets 10:12 on 28 Mar) │
╰─────────────────────────────────────────────────────────────────────────────────╯
· 69% used · 258K window · 9.46M used · 9.4M in · 63.3K out
Token usage: total=7,770,990 input=7,707,694 (+ 1,693,824 cached) output=63,296 (reasoning 30,987)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is identified in the issue. First reproduce the comparison with Codex CLI v0.116.0, gpt-5.4, and the listed reasoning and summary settings, then trace how the OpenAI-compatible gateway handles upstream usage and cached-input fields. Done means reproducing the discrepancy, identifying the transmission or accounting cause, and confirming cached input and quota usage remain close to direct access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100