# Costs & Tokens

Shipyard reports real token usage where it can get it, an honest `n/a` where it
cannot, and an estimated cost next to both.

---

## What is captured

Usage is captured from:

- **API provider plugins** (OpenAI, Anthropic, Gemini, DeepSeek, Ollama, and
  the other shipped providers), which report real token counts.
- **The remote/bridge protocol**, where the worker reports usage back with the
  rollout.

Where usage is not captured, `metrics.json` carries `"usage": null` and the
human output prints `n/a`. CLI harnesses that do not expose token counts
(`claude-code`, `codex`, and friends) always show `n/a` rather than a guess.
There is no fabricated token count anywhere in Shipyard: a suite that mixes API
evals and CLI evals reports usage for the API evals and `n/a` for the rest.

`metrics.json` v1 writes usage per repeat:

```json
{
  "schema_version": "1",
  "run_id": "2026-10-15T08-00-00Z",
  "repeat_index": 2,
  "verdict": "passed",
  "usage": {
    "input_tokens": 18422,
    "output_tokens": 3110
  }
}
```

`error_kind` (`agent`, `infra`, or `rubric`) appears next to the verdict when
the repeat did not pass. `usage` is `null` when the harness cannot report. The
token counts in the example are illustrative; the contract is the field:
harness-reported numbers, or `null`.

## Estimated cost

For each eval that reported usage, Shipyard looks the model up in a shipped
pricing table of common models and computes an estimated cost from input and
output tokens. Every cost in the output is labeled an estimate; the label is
part of the contract, not a disclaimer.

Override or extend the table with `pricing.toml` at the target root, or point
`SHIPYARD_PRICING_FILE` at a file elsewhere:

```toml
# <target>/pricing.toml

[models."claude-sonnet-4-5"]
input_per_million = 3.00
output_per_million = 15.00

[models."gpt-4o"]
input_per_million = 2.50
output_per_million = 10.00

[models."my-finetune"]
input_per_million = 0.80
output_per_million = 0.80
```

Keys are model prefixes. Matching is exact first, then longest prefix: the
model `claude-sonnet-4-5-20250929` matches the `claude-sonnet-4-5` entry above,
and a more specific `claude-sonnet-4-5-20250929` entry would win over it.
Models with no match in the table show no cost at all rather than `0`, so
"unknown" never looks like "free".

## Suite totals and `partial`

A run aggregates usage and cost:

- `aggregate.json` carries the per-eval `usage` and the per-repeat records.
- `results.json` carries `totals.usage` for the suite.
- The human summary prints an estimated total when every eval could report.

If only some evals in the suite could report usage, the total is labeled
`partial` and the n/a evals are named. A partial total is never presented as
the whole bill, because a suite half-covered by token accounting is exactly
where cost surprises hide.

## Cost gates

`[gate] max_cost_increase_pct` turns estimated cost into a blocking signal. It
defaults to `0`, which is off; when enabled, a candidate whose estimated cost
rises past the configured percentage blocks the gate (see
[Gate policy](/docs/gate-policy)).

Economics, honestly:

- Costs are estimates from a pricing table, not billing records.
- CLI harnesses report no tokens, so cost gating is meaningful for API
  providers and the remote/bridge path, and mostly empty for CLI agents.
- `--repeat` multiplies both tokens and cost by `k`.

The point is not to predict an invoice to the cent. It is to stop a "10x
better" prompt from quietly becoming 10x the spend, and to keep the empty
answers visible instead of filling them in.
