bug: Anthropic provider: `system` sent as plain string — prompt caching never engages
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia in cptr/utils/ai.py, in stream_anthropic e chat_completion, i due percorsi di richiesta menzionati nell’issue. Controlla come ciascuno costruisce il campo system di Anthropic e rivedi i test esistenti per questi percorsi; l’issue non indica un file di test. Il lavoro è completo quando entrambi i percorsi inviano il prompt di sistema come blocco di testo memorizzato nella cache, mantenendo il controllo per il sistema vuoto, e i dati di utilizzo di Anthropic segnalano la creazione della cache al primo turno e le letture della cache nei turni successivi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 768
- Fork
- 108
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di open-webui/computer
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
open-webui/computer#327 · 7 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
open-webui/computer#324 · 3 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-webui/computer#314 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-webui/computer#293 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-webui/computer#286 · 1 commento ·
Tutte le issue di open-webui/computer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pdm-project/pdm#4042 ·
I maintainer di solito rispondono entro 1 giorno
-
change relation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
globalwordnet/english-wordnet#1467 ·
I maintainer di solito rispondono entro 1 giorno
-
pr-babysit: the validator reports only the hex part of the harvest fingerprint, so a launch stops review-report-unusableForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertafollow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
521xueweihan/HelloGitHub#4618 ·