Quick answer
`info.cost` is the cost value attached to an OpenCode assistant message. It is populated when the provider reports pricing or when OpenCode can compute it from a known model. It can be zero for free models, null for unknown models, and absent in older records. Treat it as a per-message estimate.
The three states
| Value | Meaning | What to do |
|---|---|---|
| Positive number | Reported or computed cost | Sum it |
| Zero | Free model or unpriced provider | Check the model before assuming free |
| Missing | Older record or unknown model | Apply rates manually |
Read it safely
Do not assume every message has the field. A query that sums info.cost across a mixed data set will silently ignore missing rows, which understates the total.
select count(*),
sum(case when cost is null then 1 else 0 end) as missing,
sum(cost) as total
from message;Compute the missing rows
- Group missing rows by model.
- Look up the current rate for each model.
- Apply input, cache read, cache write, and output separately.
- Add the computed value to the reported total.
If you would rather not maintain a rate table, UsageAtlas shows both reported and computed cost and marks which is which.
What the cost field really contains
When OpenCode records a cost value, it comes from what the provider reported for that message. That makes it the most accurate per-message number available locally, but it is not an invoice: discounts, credits, and plan allowances are applied later.
| Value | Source | Use it for |
|---|---|---|
| Reported cost | Provider response | Relative comparison |
| Calculated cost | Tokens times rates | Estimation and planning |
| Plan usage | Provider dashboard | Whether you can continue |
| Invoice | Billing | What you actually pay |
Read the field as a signal, not a receipt. The cost tracking guide explains how to combine it with token-based estimates.
Questions, answered
Is info.cost a string or a number?
It is a numeric value in the message metadata. Formats vary by version, so parse defensively.
Does info.cost include cache writes?
When the provider prices them. If the field is computed locally, it depends on the pricing table in use.
Why do two messages with the same tokens have different costs?
Different models, different cache shares, or a pricing change between the two.