fabro/lib/packages/fabro-api-client
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
..
scripts chore(api-client): make client generation idempotent 2026-05-21 14:29:11 -04:00
src feat(llm): add Response.cost_usd and CostSource across all adapters 2026-05-28 17:05:08 -04:00
tests feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
openapitools.json Rename Arc to Fabro in TypeScript/JavaScript 2026-03-12 11:13:18 -04:00
package.json Fold context-window data into agent.message, remove snapshot event (#390) 2026-05-24 15:48:21 -04:00
tsconfig.json Fix run principal attribution gaps 2026-05-02 09:14:02 -04:00