OpenCode

OpenCode cost tracking

Track OpenCode cost from local token counts and models. UsageAtlas estimates spend when OpenCode does not print a line item, and labels it as an estimate.

Quick answer

OpenCode records a cost value on assistant messages when the provider reports one, and computes it from model pricing otherwise. Summing that field per session gives spend. If the field is zero or missing, the provider did not supply pricing, so you need to apply rates yourself.

Where the cost number comes from

SourceReliabilityWhen to use
Provider-reported costHighBilling reconciliation
Computed from model pricingMediumTrend and comparison
Zero or missingNoneApply your own rates
Subscription providerNot marginalTreat as shadow cost

A subscription-backed provider can show a token cost while your marginal cost is zero. That is not a bug; it is the difference between list price and what you pay.

Audit a surprising number

  1. Open the session and find the message with the highest cost.
  2. Check the input token count for that message.
  3. Compare the model ID with the rate you expect.
  4. Check whether cache read and write are priced separately.
  5. Confirm the provider did not change pricing mid-period.

Keep a running total

Query the database for a date range, or let UsageAtlas total it. The app groups cost by session, model, and day, and shows tokens alongside so you can see whether a cost jump came from volume or from a rate change.

How OpenCode cost is calculated

OpenCode stores token counts and, where the provider returns it, a cost field per message. When the field exists it reflects what the provider reported. When it does not, a tracker multiplies tokens by published model rates, so the figure is an estimate rather than an invoice.

  1. Check whether the message records include a cost value.
  2. If they do, use it; it is the closest thing to a bill.
  3. If they do not, apply current rates per model.
  4. Keep cached input separate from fresh input.
  5. Label the result as estimated in any report you share.

The cost field guide goes deeper, and cost per session shows the arithmetic.

Questions, answered

Why does OpenCode show zero cost?

The provider did not report a price for that model, or the model is free. Free models still record tokens.

Is OpenCode cost the same as my provider bill?

Not necessarily. The local cost is a per-message estimate. Bills include rounding, plans, credits, and taxes.

Does cost include cache writes?

Only if the provider prices and reports them. Check the message record for separate cache fields.

Browse by topic