Skip to content

[BUG] Turn cost overstated ~25x when Claude Code runs through OpenRouter #3489

Open

Description

@jjaeger94

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

  1. 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, ...).
  2. Run a scheduled task.
  3. Compare schedule_executions.cost with 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

  1. added
    status-in-progress
    priority-p2
    type-bug
    theme-monetization
    complexity-high
    on Oct 12, 2026
  2. vybe commented on Nov 5, 2026

    @vybe
    Contributor

    Blocked on a product ruling, from the 2026-11-04 merge train on PR #3490: with ent#1001 closing the .env route 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-highpriority-p2status-in-progresstheme-monetizationtype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions