mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 21:05:40 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2248
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wan0791 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4897
中文
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Terminal(预编译引擎 0.1.55,通过 new-api 网关走 OpenAI 端点)
What happened(发生了什么)
#2290(xrip,2026-10-13 合入)修复了 Anthropic 端点:
serve/server.py现在在/v1/messages的message_delta.usage里上报cache_creation_input_tokens,于是"本次读入并保留给下一次请求的 token"不再被静默计入input_tokens。但 #2290 没有动 OpenAI 端点(
/v1/chat/completions)。它的usage仍然只报:也就是说:缓存读取量(
cached_tokens)有上报,但缓存写入量——本次读入并保留给下一次的 prompt token 数——没有上报。而这个写入量正是 #2290 在 Anthropic 侧算的read_now - 1。我预期:OpenAI 端点的
usage也应带上cache_creation_input_tokens(对称于 #2290),这样下游网关能区分"读缓存"与"写缓存"。Smallest steps or command that reproduce it(最小复现)
/v1/chat/completions。usage:cached_tokens有值(读缓存生效),但没有cache_creation_input_tokens(写入不可见)。/v1/messages,第二次响应有cache_creation_input_tokens(#2290 之后)。Reproduction status
Reproduced locally(已在生产复现:19 万 token 多轮 agent 会话,第 2 轮起
cached_tokens基本 99%+ 命中,但 OpenAI 端点始终无cache_creation_input_tokens)Strata version
Strata 0.2.9 · engine 0.1.55(
strata --version= strata 0.1.55,预编译0.1.55-linux-x86_64-hip-rx7900)Graphics card, memory and system
Model, size and settings
Qwen3.8-Flash-Next · IQ3_S GGUF(SC117 abliterated)· 上下文按请求(实测最大 409,194 tokens)· 图片关闭 · 通过 new-api(calciumion rc.47)网关走 OpenAI 端点
影响(Why it matters)
new-api 的"模型调用分析"面板(new-api PR #7773 加入)读上游 usage 建两个计数器:
usage.prompt_tokens_details.cached_tokens→ 正常usage.cache_creation_input_tokens(或归一化后的cache_write_tokens)→ 恒 0,因为 OpenAI 端点从不发这个字段于是对任何走 OpenAI 协议的客户端,"缓存写入"格子永远是 0——不是没写缓存(每个新前缀确实被保留),而是 OpenAI 端点不上报写入量。
建议改法(Suggested fix)
把 #2290 在 Anthropic 侧做的事镜像到 OpenAI
chat/completions的 usage:read_now = len(ids) - reused(#2290 在serve/server.py用的同一表达式)。usage(顶层或prompt_tokens_details下)加cache_creation_input_tokens,值 = 本次读入并保留给下一次的 prompt token 数(即read_now - 1,与 #2290 的input_tokens: 1约定一致,保证prompt_tokens == cache_read + cache_creation + 1对账)。OpenAI 官方 schema 没定义
cache_creation_input_tokens,但usage里的额外字段被常见客户端容忍,而且这正是网关已经会读的字段。如果你们希望 OpenAI 负载严格贴合官方 schema,也可以改为在文档里说明等价算法(cache-write =prompt_tokens - cached_tokens - 1)让网关自己算;直接发字段对下游工具更省事。English
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Terminal (prebuilt engine 0.1.55, served over the OpenAI endpoint through new-api)
What happened
#2290 (xrip, merged 2026-10-13) fixed the Anthropic endpoint:
serve/server.pynow reportscache_creation_input_tokensin the/v1/messagesmessage_delta.usage, so "prompt tokens read this request and retained for the next" are no longer silently folded intoinput_tokens.The OpenAI endpoint (
/v1/chat/completions) was not touched by #2290. Itsusagestill only reports:i.e. the cache-read amount (
cached_tokens) is reported, but the cache-write amount — the prompt tokens read this request and retained for the next — is not. That write amount is exactly what #2290 computes asread_now - 1on the Anthropic side.Expected: the OpenAI
usageshould also carrycache_creation_input_tokens(symmetric to #2290) so downstream gateways can distinguish "cache read" from "cache write".Smallest steps or command that reproduce it
/v1/chat/completionswith any client (or new-api).usage:cached_tokensis populated (read works) but there is nocache_creation_input_tokens(write is invisible)./v1/messagesdoes reportcache_creation_input_tokenson the second call (since #2290).Reproduction status
Reproduced locally (production: ~190k-token multi-turn agent session, ~99%+
cached_tokenshit from turn 2 on, but the OpenAI endpoint never emitscache_creation_input_tokens)Strata version
Strata 0.2.9 · engine 0.1.55 (
strata --version= strata 0.1.55, prebuilt0.1.55-linux-x86_64-hip-rx7900)Graphics card, memory and system
Model, size and settings
Qwen3.8-Flash-Next · IQ3_S GGUF (SC117 abliterated) · context per request (max seen 409,194 tokens) · images off · served over the OpenAI endpoint through new-api (calciumion rc.47)
Why it matters
new-api's model-analysis dashboard (added in new-api PR #7773) reads the upstream usage to build two counters:
usage.prompt_tokens_details.cached_tokens→ worksusage.cache_creation_input_tokens(or the normalizedcache_write_tokens) → always 0, because the OpenAI endpoint never emits that fieldSo for any OpenAI-protocol client, the "cache write" tile is permanently 0 — not because nothing is written to the cache (every fresh prefix is retained), but because the OpenAI endpoint doesn't report the write count.
Suggested fix
Mirror what #2290 did on the Anthropic path for the OpenAI
chat/completionsusage:read_now = len(ids) - reused(the same expression #2290 uses inserve/server.py).cache_creation_input_tokensto the OpenAIusage(top level, or underprompt_tokens_details), valued at the prompt tokens read this request and retained for the next — i.e.read_now - 1, consistent with #2290'sinput_tokens: 1convention so the totals still reconcile (prompt_tokens == cache_read + cache_creation + 1).OpenAI's own schema doesn't define
cache_creation_input_tokens, but extra keys inusageare tolerated by common clients, and it is the exact field the gateways already know how to read. If you prefer to keep the OpenAI payload strictly spec-shaped, an alternative is to document the equivalent so gateways can derive it (cache-write =prompt_tokens - cached_tokens - 1); emitting the field directly is lower-friction for downstream tooling.@github-actions[bot] commented on GitHub (Nov 1, 2026):
Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:
strata --version).Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment
/reopen.Details: CONTRIBUTING.md
@github-actions[bot] commented on GitHub (Nov 1, 2026):
Thanks, this follows the format now.
@wan0791 commented on GitHub (Nov 1, 2026):
中文
感谢格式确认。
补充一点上下文:我方场景是通过 new-api(OpenAI 协议)网关使用 Strata,多轮 agent 会话 ~19 万 token,第 2 轮起
cached_tokens基本 99%+ 命中(读缓存正常),但 OpenAI 端点始终不上报cache_creation_input_tokens,导致 new-api 面板"缓存写入"恒 0。等上游对"OpenAI 端点是否也补这个字段"的判断。如果你们认为 OpenAI 负载应严格贴合官方 schema(不额外加字段),那在文档里说明等价算法(cache-write =
prompt_tokens - cached_tokens - 1)也够用,我们可以在 new-api 侧适配。English
Thanks for the format check.
A bit of context on our side: we use Strata through new-api (OpenAI protocol). Multi-turn agent sessions at ~190k tokens,
cached_tokensis ~99%+ hit from turn 2 on (cache read works), but the OpenAI endpoint never reportscache_creation_input_tokens, so new-api's "cache write" tile stays at 0.We'll wait for your call on whether the OpenAI endpoint should also emit this field. If you prefer to keep the OpenAI payload strictly spec-shaped (no extra field), then documenting the equivalent (cache-write =
prompt_tokens - cached_tokens - 1) is sufficient and we can adapt on the new-api side.