[GH-ISSUE #4898] [Engine] OpenAI endpoint: usage never reports cache_creation_input_tokens (OpenAI-side counterpart of #2290) #2249

Open
opened 2026-11-04 01:57:55 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @wan0791 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4898

中文

Bug 描述

OpenAI 兼容端点 /v1/chat/completions 的 usage 从不报告 cache 写入量,而 Anthropic 端点 /v1/messages 会报 cache_creation_input_tokens。

这是 #2289 / PR #2290(修复 Anthropic 侧)的 OpenAI 侧对应缺口 —— 该修复只补齐了 Anthropic 格式,OpenAI 格式仍无等价字段。

实测证据(Strata 0.2.11 / 引擎 0.1.57)

同一 prompt,连续发两次(第二次应命中缓存):

OpenAI 端点 /v1/chat/completions

// 第 1 次
{"prompt_tokens": 60, "completion_tokens": 49, "total_tokens": 109,
 "prompt_tokens_details": {"cached_tokens": 0}}
// 第 2 次
{"prompt_tokens": 60, "completion_tokens": 32, "total_tokens": 92,
 "prompt_tokens_details": {"cached_tokens": 55}}

→ usage 里只有 4 个键:prompt_tokens / completion_tokens / total_tokens / prompt_tokens_details,无任何 cache 写入计数。

Anthropic 端点 /v1/messages(同一 prompt、同一引擎)

{"input_tokens": 1, "output_tokens": 31,
 "cache_creation_input_tokens": 4, "cache_read_input_tokens": 55}

→ 读写分开报,信息完整。

为什么不能靠 prompt_tokens - cached_tokens 近似

上例中 60 - 55 = 5,而 Anthropic 侧拆成 input_tokens 1 + cache_creation_input_tokens 4。

差别在于:prompt_tokens - cached_tokens 把「本次新写入缓存的 token」和「根本没有进缓存能力的 token」混成一个数(例如低于最小可缓存 chunk 的尾部、或是本轮不参与缓存的前缀)。调用方因此无法区分「这些 token 下次会免费」和「这些 token 永远不免费」。

期望行为

建议在 OpenAI 格式的 usage.prompt_tokens_details 中增加写入量字段,与 Anthropic 侧对齐,例如:

"prompt_tokens_details": {
  "cached_tokens": 55,
  "cache_creation_tokens": 4
}

(字段名可议;重点是让 OpenAI 格式也能拿到"本轮写入了多少"这个数。)

环境

  • Strata 0.2.11,引擎 0.1.57(/v1/status 回报 engine: 0.1.57)
  • GPU:1× AMD Radeon RX 7900 XTX 24 GB(gfx1100)
  • RAM:125 GB
  • OS:Ubuntu 24.04,ROCm 6.4.2
  • 模型:Qwen3.8-Flash-Next-IQ3_S(GGUF,native pack)
  • 相关参数:--prompt-cache 64 --prompt-cache-every 4096 --prompt-cache-spread --prompt-cache-tail

备注

  • 0.1.55 上观察到同样的不对称行为,0.1.57 未变。
  • 这不是功能阻塞,纯属可观测性/兼容性缺口:跨格式代理或按 Anthropic 口径记账的客户端,转成 OpenAI 端点后拿不到写入量。
  • 已知 #2289 已由 PR #2290 修复 Anthropic 侧,此处仅为补齐 OpenAI 侧。

English

Bug description

The OpenAI-compatible endpoint /v1/chat/completions never reports how many prompt tokens were written into the cache, while the Anthropic endpoint /v1/messages does report cache_creation_input_tokens.

This is the OpenAI-side counterpart of #2289 / PR #2290, which added the field to the Anthropic format only.

Evidence (Strata 0.2.11 / engine 0.1.57)

Same prompt sent twice (the second should hit the cache):

OpenAI endpoint /v1/chat/completions

// 1st
{"prompt_tokens": 60, "completion_tokens": 49, "total_tokens": 109,
 "prompt_tokens_details": {"cached_tokens": 0}}
// 2nd
{"prompt_tokens": 60, "completion_tokens": 32, "total_tokens": 92,
 "prompt_tokens_details": {"cached_tokens": 55}}

→ the usage object has exactly four keys and no cache-write count at all.

Anthropic endpoint /v1/messages (same prompt, same engine)

{"input_tokens": 1, "output_tokens": 31,
 "cache_creation_input_tokens": 4, "cache_read_input_tokens": 55}

Why prompt_tokens - cached_tokens is not a substitute

Above, 60 - 55 = 5, which the Anthropic side splits into input_tokens 1 + cache_creation_input_tokens 4.

prompt_tokens - cached_tokens conflates tokens newly written to the cache with tokens that were never cacheable (a tail below the minimum cacheable chunk, a prefix that took no part in caching this turn). A caller therefore cannot tell "these tokens are free next time" from "these tokens are never free".

Expected behaviour

Add a write-count field to usage.prompt_tokens_details in the OpenAI format, matching the Anthropic side, e.g.:

"prompt_tokens_details": {
  "cached_tokens": 55,
  "cache_creation_tokens": 4
}

(The name is open to discussion; the point is that the OpenAI format should expose how much was written this turn.)

Environment

  • Strata 0.2.11, engine 0.1.57 (/v1/status reports engine: 0.1.57)
  • GPU: 1× AMD Radeon RX 7900 XTX 24 GB (gfx1100)
  • RAM: 125 GB
  • OS: Ubuntu 24.04, ROCm 6.4.2
  • Model: Qwen3.8-Flash-Next-IQ3_S (GGUF, native pack)
  • Flags: --prompt-cache 64 --prompt-cache-every 4096 --prompt-cache-spread --prompt-cache-tail

Notes

  • Same asymmetry observed on 0.1.55; unchanged in 0.1.57.
  • Not a functional blocker — an observability / compatibility gap: cross-format proxies and clients that account per the Anthropic shape cannot get the write count from the OpenAI endpoint.
  • #2289 was fixed for the Anthropic side by PR #2290; this item only asks for the OpenAI side.
Originally created by @wan0791 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4898 ## 中文 ### Bug 描述 **OpenAI 兼容端点 `/v1/chat/completions` 的 `usage` 从不报告 cache **写入**量**,而 Anthropic 端点 `/v1/messages` 会报 `cache_creation_input_tokens`。 这是 #2289 / PR #2290(修复 Anthropic 侧)的 **OpenAI 侧对应缺口** —— 该修复只补齐了 Anthropic 格式,OpenAI 格式仍无等价字段。 ### 实测证据(Strata 0.2.11 / 引擎 0.1.57) 同一 prompt,连续发两次(第二次应命中缓存): **OpenAI 端点 `/v1/chat/completions`** ```json // 第 1 次 {"prompt_tokens": 60, "completion_tokens": 49, "total_tokens": 109, "prompt_tokens_details": {"cached_tokens": 0}} // 第 2 次 {"prompt_tokens": 60, "completion_tokens": 32, "total_tokens": 92, "prompt_tokens_details": {"cached_tokens": 55}} ``` → usage 里**只有 4 个键**:`prompt_tokens` / `completion_tokens` / `total_tokens` / `prompt_tokens_details`,**无任何 cache 写入计数**。 **Anthropic 端点 `/v1/messages`(同一 prompt、同一引擎)** ```json {"input_tokens": 1, "output_tokens": 31, "cache_creation_input_tokens": 4, "cache_read_input_tokens": 55} ``` → 读写分开报,信息完整。 ### 为什么不能靠 `prompt_tokens - cached_tokens` 近似 上例中 `60 - 55 = 5`,而 Anthropic 侧拆成 `input_tokens 1` + `cache_creation_input_tokens 4`。 差别在于:**`prompt_tokens - cached_tokens` 把「本次新写入缓存的 token」和「根本没有进缓存能力的 token」混成一个数**(例如低于最小可缓存 chunk 的尾部、或是本轮不参与缓存的前缀)。调用方因此无法区分「这些 token 下次会免费」和「这些 token 永远不免费」。 ### 期望行为 建议在 OpenAI 格式的 `usage.prompt_tokens_details` 中增加写入量字段,与 Anthropic 侧对齐,例如: ```json "prompt_tokens_details": { "cached_tokens": 55, "cache_creation_tokens": 4 } ``` (字段名可议;重点是让 OpenAI 格式也能拿到"本轮写入了多少"这个数。) ### 环境 - **Strata 0.2.11**,引擎 `0.1.57`(`/v1/status` 回报 `engine: 0.1.57`) - GPU:1× AMD Radeon RX 7900 XTX 24 GB(gfx1100) - RAM:125 GB - OS:Ubuntu 24.04,ROCm 6.4.2 - 模型:Qwen3.8-Flash-Next-IQ3_S(GGUF,native pack) - 相关参数:`--prompt-cache 64 --prompt-cache-every 4096 --prompt-cache-spread --prompt-cache-tail` ### 备注 - 0.1.55 上观察到同样的不对称行为,0.1.57 未变。 - 这不是功能阻塞,纯属**可观测性/兼容性**缺口:跨格式代理或按 Anthropic 口径记账的客户端,转成 OpenAI 端点后拿不到写入量。 - 已知 #2289 已由 PR #2290 修复 Anthropic 侧,此处仅为补齐 OpenAI 侧。 --- ## English ### Bug description The OpenAI-compatible endpoint `/v1/chat/completions` **never reports how many prompt tokens were written into the cache**, while the Anthropic endpoint `/v1/messages` does report `cache_creation_input_tokens`. This is the **OpenAI-side counterpart of #2289 / PR #2290**, which added the field to the Anthropic format only. ### Evidence (Strata 0.2.11 / engine 0.1.57) Same prompt sent twice (the second should hit the cache): **OpenAI endpoint `/v1/chat/completions`** ```json // 1st {"prompt_tokens": 60, "completion_tokens": 49, "total_tokens": 109, "prompt_tokens_details": {"cached_tokens": 0}} // 2nd {"prompt_tokens": 60, "completion_tokens": 32, "total_tokens": 92, "prompt_tokens_details": {"cached_tokens": 55}} ``` → the `usage` object has exactly four keys and **no cache-write count at all**. **Anthropic endpoint `/v1/messages` (same prompt, same engine)** ```json {"input_tokens": 1, "output_tokens": 31, "cache_creation_input_tokens": 4, "cache_read_input_tokens": 55} ``` ### Why `prompt_tokens - cached_tokens` is not a substitute Above, `60 - 55 = 5`, which the Anthropic side splits into `input_tokens 1` + `cache_creation_input_tokens 4`. `prompt_tokens - cached_tokens` **conflates tokens newly written to the cache with tokens that were never cacheable** (a tail below the minimum cacheable chunk, a prefix that took no part in caching this turn). A caller therefore cannot tell "these tokens are free next time" from "these tokens are never free". ### Expected behaviour Add a write-count field to `usage.prompt_tokens_details` in the OpenAI format, matching the Anthropic side, e.g.: ```json "prompt_tokens_details": { "cached_tokens": 55, "cache_creation_tokens": 4 } ``` (The name is open to discussion; the point is that the OpenAI format should expose how much was written this turn.) ### Environment - **Strata 0.2.11**, engine `0.1.57` (`/v1/status` reports `engine: 0.1.57`) - GPU: 1× AMD Radeon RX 7900 XTX 24 GB (gfx1100) - RAM: 125 GB - OS: Ubuntu 24.04, ROCm 6.4.2 - Model: Qwen3.8-Flash-Next-IQ3_S (GGUF, native pack) - Flags: `--prompt-cache 64 --prompt-cache-every 4096 --prompt-cache-spread --prompt-cache-tail` ### Notes - Same asymmetry observed on 0.1.55; unchanged in 0.1.57. - Not a functional blocker — an **observability / compatibility** gap: cross-format proxies and clients that account per the Anthropic shape cannot get the write count from the OpenAI endpoint. - #2289 was fixed for the Anthropic side by PR #2290; this item only asks for the OpenAI side.
Author
Owner

@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:

  • Describe it in the issue body: what happened, what you expected, and the exact error if there is one. The issue forms (New issue > Bug report) list what to include.
  • Add the Strata version (Settings > About, or strata --version).
  • Add your graphics card with its VRAM, your RAM and your operating system.

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

<!-- gh-comment-id:6556458033 --> @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: - [ ] Describe it in the issue body: what happened, what you expected, and the exact error if there is one. The issue forms (New issue > Bug report) list what to include. - [ ] Add the Strata version (Settings > About, or `strata --version`). - [ ] Add your graphics card with its VRAM, your RAM and your operating system. 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](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Nov 7, 2026):

Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection.

To bring it back: fix the title (area prefix) and the missing parts, then comment /reopen. A check runs and reopens it, or tells you what is still missing. See CONTRIBUTING.md.

<!-- gh-comment-id:6702196363 --> @github-actions[bot] commented on GitHub (Nov 7, 2026): Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection. To bring it back: fix the title (area prefix) and the missing parts, then comment `/reopen`. A check runs and reopens it, or tells you what is still missing. See [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@wan0791 commented on GitHub (Nov 7, 2026):

/reopen

<!-- gh-comment-id:6703359683 --> @wan0791 commented on GitHub (Nov 7, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Nov 7, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6703360557 --> @github-actions[bot] commented on GitHub (Nov 7, 2026): Thanks, this follows the format now.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 7, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6703361171 --> @github-actions[bot] commented on GitHub (Nov 7, 2026): Reopened, thank you. A maintainer will pick it up from here.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2249
No description provided.