fabro/docs
Scott Werner 480ff56aba feat(llm): add Response.cost_usd and CostSource across all adapters
Adds two new fields to the unified completion Response:

- cost_usd: Option<f64> — USD cost for the completion
- cost_source: Option<CostSource> — Authoritative | Estimated

A new fabro_llm::cost::estimate_cost_usd helper centralizes the catalog
math (tokens × catalog price → USD micros → f64). Every adapter response
path (Anthropic, OpenAI, Gemini, openai_chat) calls the helper when a
catalog is available, producing Estimated costs. Adapters with
authoritative provider-side pricing (e.g. OpenRouter, in a later commit)
will bypass the helper and set Authoritative.

The openai_chat streaming path now plumbs catalog + speed through
StreamState so finish_events can call the helper before assembling the
final Response.

Public API surface: CompletionResponse in fabro-api.yaml is extended
with cost_usd and cost_source. Progenitor + the TS client are
regenerated; apps/fabro-web typechecks clean since both fields are
optional.

42 Response constructor sites updated:
- 5 live adapter sites call estimate_cost_usd
- ~32 synthesized/fallback/test sites set (None, None) explicitly
- 5 test fixtures in types.rs set (None, None)

397 lib tests pass (was 392, +5 new helper unit tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 17:05:08 -04:00
..
brainstorms Replace queued with pending/runnable and add approval flow (web + API s… (#371) 2026-05-23 15:34:33 -04:00
ideation docs 2026-04-09 17:24:30 -04:00
internal refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
plans refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
public feat(llm): add Response.cost_usd and CostSource across all adapters 2026-05-28 17:05:08 -04:00
superpowers refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00