Support cached-input pricing for custom providers
- Lingua principale
- Rust
- Stelle
- 54.2k
- Fork
- 6.2k
- Merge medio
- 3g 4h
- PR unite (30g)
- 240
Descrizione
## Problem
Custom provider model metadata currently supports `input_token_cost` and `output_token_cost`, but it cannot specify a separate price for cached input tokens.
Some OpenAI-compatible providers return cached-token usage and bill those tokens at a substantially discounted rate. For example, Cloudflare Workers AI enables prefix caching for supported models, reports cached token counts in the response `usage` object, and applies a different cached-input price.
Because custom providers cannot configure that price separately, Goose's estimated and accumulated session cost can materially overestimate actual provider billing during long agent sessions with high cache-hit rates.
## Who this affects
Users of custom OpenAI-compatible providers that:
- report cached input tokens;
- charge a distinct cached-input rate;
- use long, repeated prompt prefixes, particularly coding-agent sessions.
Cloudflare Workers AI is one example, but the capability would be useful for any compatible provider with discounted cached input.
## Current behavior
A custom model can define:
- `input_token_cost`
- `output_token_cost`
There is no model metadata field for cached-input cost. Goose already has usage fields for cache-read and cache-write tokens, but custom-provider pricing cannot use a separate cached-input rate.
## Expected behavior
Custom providers should be able to optionally specify a cached-input token price.
When both cached-token usage and cached pricing are available, Goose should use them when calculating session cost. Providers that do not configure cached pricing should retain the current behavior.
The capability should work consistently in session totals and any CLI or Desktop cost display.
## Verification
A suitable verification plan would cover:
- no cached tokens;
- partially cached input;
- fully cached input;
- cached-token usage without cached pricing;
- cached pricing without cached-token usage;
- backward compatibility with existing custom-provider JSON files;
- accumulated cost across multiple requests.
## Example provider documentation
Cloudflare Workers AI prompt caching:
https://developers.cloudflare.com/workers-ai/features/prompt-caching/
Cloudflare Workers AI pricing:
https://developers.cloudflare.com/workers-ai/platform/pricing/
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Esamina la struttura dei metadati del modello del provider personalizzato, probabilmente in un file come `src/provider/custom.rs` o `src/model/metadata.rs`. Individua dove sono definiti `input_token_cost` e `output_token_cost`. Aggiungi un nuovo campo per il costo dei token di input memorizzati nella cache. Aggiorna la logica di calcolo dei costi in modo che utilizzi questo campo quando viene riportato l'utilizzo di token memorizzati nella cache. Controlla l'accumulo dei costi della sessione e qualsiasi codice di visualizzazione CLI/Desktop. Esegui i test esistenti per garantire la compatibilità con le versioni precedenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- backend-api-design
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 65/100