gateway: capture real provider-reported cost (openrouter usage accounting)

Cost displays were estimates from a pricing table; on OpenRouter the
status bar never reflected what was actually charged. Now cost is
provider-REPORTED only, end to end:

- OpenRouter requests carry usage:{include:true} (profile + legacy
  transport paths); the response usage.cost field (credits, 1:1 USD)
  is captured per call into agent.session_actual_cost_usd and
  persisted to the sessions DB actual_cost_usd column (NULL-safe:
  unreported calls never touch the stored value).
- Nous keeps its x-nous-credits-* header capture; the header delta
  now surfaces as the session's real cost via real_session_cost_usd.
- Providers that report nothing accumulate NOTHING: cost fields stay
  absent/None (the TUI hides its cost segment), never a fabricated
  $0.00 and never an estimate. _get_usage, gateway /usage and the
  CLI usage page all switched off estimate_usage_cost for display.
- Per-model session accumulator (session_model_usage) records real
  per-call counts and provider-reported cost per model.
This commit is contained in:
alt-glitch 2026-06-11 00:14:21 +05:30
parent ba3fe7027c
commit 85546bb9e2
13 changed files with 427 additions and 86 deletions

View file

@ -49,6 +49,13 @@ class OpenRouterProfile(ProviderProfile):
if prefs:
body["provider"] = prefs
# Usage accounting — makes OpenRouter return the REAL cost it charged
# in the response `usage.cost` field (credits are 1:1 USD), instead of
# Hermes having to estimate from a pricing table. Captured by
# agent.usage_pricing.extract_provider_cost_usd in the conversation
# loop. https://openrouter.ai/docs/use-cases/usage-accounting
body["usage"] = {"include": True}
# Pareto Code router — model-gated. The plugins block is only
# meaningful for openrouter/pareto-code; sending it on any other
# model has no documented effect and would be confusing in logs.