Skip to content

Record OpenRouter's reported cost in the usage ledger #18

Description

@DevMortimer

Problem

The usage ledger estimates spend from token counts at a fixed rate (DEFAULT_USD_PER_MTOK). OpenRouter reports the real cost on each Decisions response as usage.cost in USD (docs), for example "usage": { "input_tokens": 275, "output_tokens": 20, "cost": 0.00003 }. The TypeSafe backend returns no cost.

Wanted

  • When a response carries a valid usage.cost, record it in the ledger, so maxUsdPerDay and status lines follow what was actually billed.
  • Otherwise, keep the estimate.
  • A missing or malformed cost is ignored, never an error. Response validation keeps passing either way.
  • Existing public types keep estimatedUsd. New fields may be added.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions