Prompt caching not working: app does not send anthropic-beta header on /anthropic/v1/messages requests

Aperta Adatta ai principianti
#3,688 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Ambito
api, desktop

Direzione di ricerca

Inizia tracciando la costruzione della richiesta dell’app Copilot per l’endpoint /anthropic/v1/messages e il modo in cui viene letto supports_prompt_caching. Conferma che le richieste per i modelli di provider personalizzati idonei includano anthropic-beta: prompt-caching-2024-07-31, mentre le altre richieste rimangano invariate; verifica l’header in uscita con la configurazione esistente per il logging delle richieste o del proxy.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

The Copilot app correctly uses the /anthropic/v1/messages endpoint when a custom model provider is configured with an Anthropic-compatible base URL. However, it does not send the anthropic-beta: prompt-caching-2024-07-31 header, so prompt caching is never activated — even when cache_control: {type: ephemeral} markers are present in the request.

Evidence (from local hai-desktop proxy logs)

The local hai-desktop proxy forwards requests and adds ?beta=true to the upstream URL only when it sees the anthropic-beta header from the client. Comparing the two callers:

Client User-Agent Upstream target Caching
Claude Code claude-cli/2.1.222 ...llm-proxy/anthropic/v1/messages?beta=true ✅ works
Copilot app Anthropic/JS 0.94.0 ...llm-proxy/anthropic/v1/messages ❌ broken

Claude Code sends anthropic-beta: prompt-caching-2024-07-31; the Copilot app does not.

Confirmed by live test (same proxy, same model)

With anthropic-beta header (Claude Code / manual curl):

  • Request 1: cache_creation_input_tokens: 1202, cost 0.005942
  • Request 2: cache_read_input_tokens: 1202, cost 0.00058710× cheaper

Without anthropic-beta header (Copilot app):

  • Request 1: cache_creation_input_tokens: 0
  • Request 2: cache_read_input_tokens: 0 — no savings

Workaround

I added a local HTTP caching proxy on a separate port that sits in front of hai-desktop to avoid redundant calls. This is a symptom fix, not a solution.

Request

When the Copilot app is configured with a custom provider using an Anthropic-format endpoint, and a model reports supports_prompt_caching: true, the app should send:

anthropic-beta: prompt-caching-2024-07-31

on requests to /anthropic/v1/messages. This is the only missing piece — the endpoint, the model, and the cache_control markers in the request body are all already correct.

Lingua principale
Nessun dato sulla lingua
Stelle
2.1k
Fork
157
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/app

Tutte le issue di github/app

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.