Repository navigation
Description
Describe the bug
When a Claude Code agent is routed through OpenRouter (ANTHROPIC_BASE_URL=https://openrouter.ai/api, ANTHROPIC_DEFAULT_*_MODEL mapped to a non-Anthropic model), Trinity records the turn cost far too high.
Trinity stores total_cost_usd from Claude Code's result event as-is (stream_parser.py, jsonl_recovery.py). Claude Code computes that figure from its own Anthropic price table, so for a model it does not know (for example deepseek/deepseek-v4.1-flash) the number is a guess at Anthropic prices. Claude Code marks this itself: the modelUsage entry carries "costBasis": "unknown".
To Reproduce
- Point an agent at OpenRouter with a non-Anthropic model (via the agent
.env:ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek/deepseek-v4.1-flash, ...). - Run a scheduled task.
- Compare
schedule_executions.costwith what OpenRouter actually billed.
One real turn (10 turns, 26.7k input / 4.1k output / 132k cache-read tokens):
| Source | Cost |
|---|---|
Trinity (total_cost_usd) |
$0.311 |
OpenRouter /api/v1/generation, summed over the turn's 7 generation ids |
$0.0116 |
modelUsage tokens × OpenRouter /api/v1/models prices |
$0.0137 |
Over 5 days of schedules, two agents: Trinity showed $14.18, while OpenRouter billed $2.01 in total for both keys.
Expected behavior
When the runtime is behind a known Anthropic-compatible proxy, cost reflects the provider's prices, and falls back to the native figure when it cannot be determined.
Environment:
- Trinity version: v0.9.5 (hosted images)
- OS: Ubuntu 26.04
- Docker version: 29
Additional context
Related to #2982 (routing Claude Code agents through an Anthropic-compatible proxy): cost accounting is one of the places that assumes Anthropic. A fix will follow as a PR. It re-prices from modelUsage against the OpenRouter price list in the agent server, and keeps the native cost for every other setup.
Analysis and the fix were written with Claude Code.
Activity
fix(agent-server): keep provider price fetch off the result path, wir…
vybe commentedon Nov 5, 2026
Blocked on a product ruling, from the 2026-11-04 merge train on PR #3490: with ent#1001 closing the
.envroute and #2982 still incubating, should Trinity take OpenRouter repricing now for container-baseline proxies only, or hold it until #2982 provides a sanctioned proxy path?