A cached prompt costs the cached rate

cached_per_1k in a price charges the prompt tokens the answer counts as
cached_tokens at their own rate; zero keeps charging them as prompt tokens.
The count reaches the cost and not a column: CostMicros holds what it
changed. Cached beyond the prompt is clamped, an engine's miscount rather
than a refund. BACKLOG L5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-25 17:15:48 +01:00
1 parent 73e1bb6733
commit ed0d1ec0ad
12 files changed
+85 -11

No files matched your search

+1
View File
@@ -825,6 +825,7 @@ func (r *Router) account(req *parsedRequest, res dispatchResult, status int, too
if usage := res.outcome.Usage; usage != nil {
u.PromptTokens = int64(usage.PromptTokens)
u.CompletionTokens = int64(usage.CompletionTokens)
u.CachedTokens = int64(usage.CachedTokens)
} else {
// No usage came back — a failure before the engine answered, or an
// engine that does not report it. Charging the estimate is closer to
+2 -1
View File
@@ -400,7 +400,7 @@ func New(cfg config.Server, log *slog.Logger) (*Router, error) {
prices := make(map[string]accounting.Price, len(cfg.Auth.Pricing))
for name, p := range cfg.Auth.Pricing {
prices[name] = accounting.Price{
PromptPer1k: p.PromptPer1k, CompletionPer1k: p.CompletionPer1k, PerImage: p.PerImage, PerMesh: p.PerMesh,
PromptPer1k: p.PromptPer1k, CompletionPer1k: p.CompletionPer1k, CachedPer1k: p.CachedPer1k, PerImage: p.PerImage, PerMesh: p.PerMesh,
}
}
r.recorder = accounting.NewRecorder(st, r.auth, accounting.RecorderConfig{
@@ -430,6 +430,7 @@ func New(cfg config.Server, log *slog.Logger) (*Router, error) {
accounting.NewPricing(prices, accounting.Price{
PromptPer1k: cfg.Auth.DefaultPrice.PromptPer1k,
CompletionPer1k: cfg.Auth.DefaultPrice.CompletionPer1k,
CachedPer1k: cfg.Auth.DefaultPrice.CachedPer1k,
PerImage: cfg.Auth.DefaultPrice.PerImage,
PerMesh: cfg.Auth.DefaultPrice.PerMesh,
}),