Skip to content

parity: does upstream's client compute cost from tokens and catalog prices? #970

Open

Description

@Blind-Striker

Some providers report a cost of 0 in session, message and usage data, while token counts and the model catalog's prices (ModelInfo.Cost, including cache prices and long-context tiers) are available. Callers that enforce budgets then compute cost themselves from tokens and catalog prices.

Question for parity (ADR-0031): does opencode's first-party client (packages/client, the CLI and TUI) compute or display cost from tokens and catalog prices when the reported cost is 0? If it does, the SDK should offer the same helper. If it doesn't, record that the SDK reports the server's cost as is, and close this.

Done when the upstream behaviour at the pin is cited (file and line), and the SDK either has the matching helper or a recorded "not offered upstream".

Activity

  1. added this to the 1.x milestone on Nov 20, 2026
  2. Blind-Striker commented on Nov 22, 2026

    @Blind-Striker
    CollaboratorAuthor

    Answer from the source at opencode v2.3.2 (c0ad18b4): upstream does not compute cost from tokens when a provider reports 0.

    • The server computes the catalog cost, with context tiers and cache prices (packages/core/src/session/usage.ts:21-36). It does so only when the provider reports no cost: cost: usage?.cost === undefined ? calculateCost(costs, normalized) : Money.USD.make(usage.cost). The comment on that line says "A reported zero is authoritative" (usage.ts:43-51, and packages/ai/src/schema/events.ts:74-79).
    • That value reaches the HTTP API on step events, messages, sessions and stats. The CLI, the TUI, ACP and the Solid data store display the server's number unchanged. None of them recomputes it.
    • The SDK has no hand-written cost helper either, so it matches upstream.

    A recomputing helper would be an SDK-only addition, which is a divergence under ADR-0031. One related first-party helper the SDK lacks is filed separately: the family cost sum.

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions