bug: Anthropic provider: `system` sent as plain string — prompt caching never engages
还没有人认领这个 Issue。
评估
调研方向
从 cptr/utils/ai.py 中的 stream_anthropic 和 chat_completion 开始,这两个请求路径在 issue 中有提及。检查它们各自如何构建 Anthropic 的 system 字段,并查看这些路径现有的测试;issue 没有指定测试文件。完成标准是:两个路径都将系统提示作为缓存文本块发送,同时保留空 system 的保护逻辑,并且 Anthropic 使用情况报告显示首轮创建缓存、后续轮次读取缓存。
由索引模型根据 Issue 内容生成。
描述
Summary
The Anthropic provider sends system as a plain string in the /v1/messages body. Anthropic only creates a cache entry when a system text block carries a cache_control breakpoint — a plain string is never eligible. Result: prompt caching is silently dead for every Anthropic connection; each turn of a chat re-reads the entire system prompt at full input-token price (no cache_creation_input_tokens / cache_read_input_tokens in the Anthropic usage analytics).
Where (cptr/utils/ai.py, HEAD):
stream_anthropic(line ~437) — the main chat path:body = { "model": form_data.model, "system": form_data.instructions, ... }chat_completion(line ~144) — the non-streaming path (title/summary generation):if system: body["system"] = system
Proposed fix
Send the system as a cached block list in both call sites:
body["system"] = [
{
"type": "text",
"text": system,
"cache_control": {"type": "ephemeral"},
}
]
(Keep the if system: / empty→None guard as-is.)
Notes
- Anthropic's minimum cacheable prefix is 1024 tokens; cptr's system prompt (instructions + memory + skills + tools) comfortably exceeds it, so the breakpoint pays off from the second turn of every chat.
- The client side is already ready:
stream_anthropicparsescache_read_input_tokensandcache_creation_input_tokensfrom the response usage — only the request side never opts in. - #27 ("feat: ephemeral caching header for anthropic models") asked for a per-model configurable ephemeral cache header and was closed 2026-06-11 with "Request parameters support added". That makes caching possible via per-model
request_params, but the provider's default still sends a plain string, so nothing is cached unless the user wires it up manually. Making the breakpoint the default (still overridable viarequest_params) would fix it for everyone.
Verification
After the fix: first turn of a chat shows cache_creation_input_tokens > 0, subsequent turns show cache_read_input_tokens > 0 — visible in the Anthropic console usage analytics and in cptr's per-request usage logging.
- 主要语言
- Python
- 星标
- 768
- 派生
- 108
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
open-webui/computer 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
open-webui/computer#327 · 7 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 64/100
open-webui/computer#324 · 3 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
open-webui/computer#314 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
open-webui/computer#293 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
open-webui/computer#286 · 1 条评论 ·
查看 open-webui/computer 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
pdm-project/pdm#4042 ·
维护者通常 1 天内回复
-
change relation
难度 1/5 1 小时以内 新手友好度 76/100
globalwordnet/english-wordnet#1467 ·
维护者通常 1 天内回复
-
pr-babysit: the validator reports only the hex part of the harvest fingerprint, so a launch stops review-report-unusable可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭follow-up
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
521xueweihan/HelloGitHub#4618 ·