Cached input is priced at 10% of input for every model; dollar cap undercounts

Ouverte
#179 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
75/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go

Piste de recherche

Start with Pricer.Cost in internal/llm/pricing.go and trace how PricesFromConfig in internal/llm/wrap.go maps the [pricing] fields defined in internal/config/config.go. Check the cached token usage reported in internal/llm/openai.go and the pricing section in docs/config.md. Run the relevant tests, then make test-short; done means configured cache prices affect costs and the documented fallback and built-in override behavior match the acceptance criteria.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug severity: medium

Summary

When a price entry has no cache prices, cached input is charged at 10% of the input price. That ratio fits one vendor; a [pricing] entry cannot override it, so for other endpoints the recorded cost and the spend cap are understated.

Where

  • internal/llm/pricing.go:86-92 (Pricer.Cost derives read = Input * 0.10, write = Input * 1.25)
  • internal/llm/wrap.go:219-225 (PricesFromConfig copies only input and output prices)
  • internal/config/config.go:323-326 ([pricing] has two keys)
  • internal/llm/openai.go:253-255 (cached tokens reported by OpenAI-compatible endpoints)
  • docs/config.md:334-346

Details

A [pricing] entry can only carry input_per_mtok and output_per_mtok, so every model priced by the operator gets the derived cache prices with no way to change them. The OpenAI-compatible provider reports cached tokens, and the agent loop resends a growing prefix each turn, so most input tokens of a long conversation are cached ones. docs/config.md states the 125% write rule for the built-in table only and says nothing about cached reads for [pricing] entries.

Assumption behind the medium confidence: that some OpenAI-compatible vendors bill cached input at more than 10% of the input price.

Impact

For such an endpoint usage.CostUSD is lower than the real charge, the budget accumulates the low figure and the spend cap fires late. Example: 100,000 prompt tokens of which 90,000 cached, at 2.5 per million input, is recorded as $0.0475; at half price for cached input the real cost is $0.1375. An operator override of a built-in model also silently loses that model's own cache-read price.

Suggested fix

Add optional cache_read_per_mtok and cache_write_per_mtok to [pricing] and copy them in PricesFromConfig. When they are absent for a model that is not in the built-in table, price cached tokens at the full input price (an overestimate keeps the cap honest), and document the rule in docs/config.md.

Acceptance criteria

  • [pricing] accepts the two cache keys and Pricer.Cost uses them
  • A model priced only by input and output charges cached tokens at the input price
  • An override of a built-in model keeps the built-in cache prices unless it sets its own
  • docs/config.md states the rule

Getting started

  • Relevant files: docs/config.md, internal/config/config.go, internal/llm/openai.go, internal/llm/pricing.go, internal/llm/wrap.go
  • How to run tests: make test-short (Unix) or .\make.ps1 test-short (Windows PowerShell); make lint before you call it done
  • Related docs: docs/config.md (pricing section)

Filed by repo-audit/full-audit at 50e92ec. Severity: medium. Effort: S. audit-key: bug|internal/llm/pricing.go|Pricer.Cost

Langage dominant
Go
Étoiles
0
Forks
1
Merge moyen
8 h 14 min
PR mergées (30 j)
3

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TMHSDigital/Spackle

Toutes les issues de TMHSDigital/Spackle

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.