From 9578a450fc99635db576a0a77cf063d3c8f150f2 Mon Sep 17 00:00:00 2001 From: Adam Scerra Date: Fri, 23 Oct 2026 07:09:39 -0400 Subject: [PATCH 1/2] docs(#7230): explain cost estimates from token telemetry Signed-off-by: Adam Scerra --- docs/cli/run.md | 1 + .../infrastructure/distributed-tracing.md | 144 +++++++++++++++++- docs/guides/user/tracing-with-mlflow.md | 5 +- docs/runtimes/codex.md | 12 +- 4 files changed, 155 insertions(+), 7 deletions(-) diff --git a/docs/cli/run.md b/docs/cli/run.md index 7befa05ffe..cad12cce4c 100644 --- a/docs/cli/run.md +++ b/docs/cli/run.md @@ -132,6 +132,7 @@ depend on the process cwd. | `override_source` | Where `requested_model` came from (`--model flag`, `FULLSEND_MODEL`, `FULLSEND_PI_MODEL`, `FULLSEND_CODEX_MODEL`, ` agents.`, `harness`, `default`), suffixed `, remapped by models.aliases` when a per-repo alias override applied to it | | `runtime_source` | Where `requested_runtime` came from (`--runtime flag`, `FULLSEND_RUNTIME`, the config file path — suffixed ` agents.` when the agent's entry decided — or `default (config not found)`) | | `total_cost_usd` | Total inference cost in USD, as reported by the runtime (raw floating-point aggregate across all iterations; no fullsend-side pricing-table fallback). See [Cost data contract](../guides/infrastructure/distributed-tracing.md#cost-data-contract) | +| `token_usage` | Run-level token counts: `input`, `output`, `cache_creation`, `cache_read`, and `reasoning` (always serialized, `0` when none). Reasoning is separate from output for Codex and included in output for Claude and the pinned pi version. Counts can survive interruption even when reported cost is zero. Prefer per-iteration `run-telemetry.jsonl` for pricing; see [Computing dollar cost from token telemetry](../guides/infrastructure/distributed-tracing.md#computing-dollar-cost-from-token-telemetry). | | `num_turns` | Number of conversation turns | | `iterations` | Number of agent iterations run; an iteration killed at the budget is not retried (see [Budget and deadline](#budget-and-deadline)) | | `per_model_usage` | Per-model breakdown, present only when a runtime reports one (today: `pi` with the `Agent` tool enabled, `claude` when Claude Code's result carries `modelUsage`, and `codex` for an agent with registered sub-agent roles or a spawn in its stream). See below | diff --git a/docs/guides/infrastructure/distributed-tracing.md b/docs/guides/infrastructure/distributed-tracing.md index e4559a1573..0b0def5caf 100644 --- a/docs/guides/infrastructure/distributed-tracing.md +++ b/docs/guides/infrastructure/distributed-tracing.md @@ -403,7 +403,9 @@ Additional resource attributes from `OTEL_RESOURCE_ATTRIBUTES` are merged in. Fullsend does not calculate inference cost from token counts or maintain a model-price table. Each runtime reports a USD cost value and fullsend records it as-is. This section defines the source, aggregation, rounding, -and display behavior of that value across every output surface. +and display behavior of that value across every output surface. To compute +a dollar figure from persisted token counts using your own contracted +rates, see [Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry). ### Runtime cost extraction @@ -413,6 +415,7 @@ Each runtime extracts cost differently from its agent process: |---------|--------|------------| | `claude` | Claude Code stream JSON | Reads `result.total_cost_usd` from the final result event — a single value covering the entire iteration | | `pi` | Pi assistant message stream | Sums `usage.cost.total` across all assistant messages in the iteration | +| `codex` | Codex event stream | No cost field; records `0` | | `opencode` | OpenCode step stream | Sums `step_finish.part.cost` across all step-finish events in the iteration | The runtime-reported value includes whatever the provider prices — input @@ -461,7 +464,9 @@ differently than the sum of parts. If a runtime does not report cost (returns zero or the field is absent), fullsend records zero. There is no fallback cost calculation from token -counts. A missing runtime cost propagates as `$0.00` on all surfaces. +counts. A missing runtime cost propagates as `$0.00` on all surfaces. See +[Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry) +for how to apply your own contracted rates to the persisted token fields. ### Distinction from backend-derived cost estimates @@ -478,6 +483,141 @@ The authoritative cost for a fullsend run is always `fullsend.cost_usd` (on spans) or `total_cost_usd` (in `metrics.json`). Backend-derived estimates are informational and may diverge. +## Computing dollar cost from token telemetry + +Fullsend never converts token counts into dollars. A runtime-reported cost +is not necessarily your contracted charge. Codex reports no cost, so its +cost stays `0`. A Claude iteration interrupted before its terminal result +has no reported cost; pi and OpenCode can retain cost accumulated before +interruption. A cancelled run can still have a non-zero aggregate from +previous iterations. Zero reported cost does not mean zero usage. + +These are distinct gaps: Codex has no reported dollar cost even after a +successful run; Claude can lose the cost of an interrupted iteration. The +original [cancelled-run follow-up](https://github.com/fullsend-ai/fullsend/pull/7208#issuecomment-5633919519) +was closed in favor of pricing the persisted token counts at users' own +rates. This procedure covers both cases. + +Use `run-telemetry.jsonl` as the primary source for a contracted-rate +estimate. Its `agent` spans carry per-iteration token counts, runtime, and +model identity. `metrics.json` provides the run-level aggregate when span +telemetry is unavailable. Token counts survive interruption where the +runtime has reported them; tokens consumed after its last usage update +cannot be reconstructed from these artifacts. If telemetry is disabled or +the process dies before an `agent` span ends, the file may lack that span. + +### Persisted token fields + +| Kind | `agent` span attribute | `metrics.json` `token_usage` | +|------|------------------------|------------------------------| +| Uncached input | `gen_ai.usage.input_tokens` | `input` | +| Output | `gen_ai.usage.output_tokens` | `output` | +| Cache creation | `gen_ai.usage.cache_creation.input_tokens` | `cache_creation` | +| Cache read | `gen_ai.usage.cache_read.input_tokens` | `cache_read` | +| Reasoning | `gen_ai.usage.reasoning_tokens` | `reasoning` | + +The first four span attributes are emitted even when zero. The reasoning +attribute is omitted when zero; `metrics.json` always serializes +`token_usage.reasoning`, including `0`. Treat a missing reasoning attribute +on a Fullsend `agent` span as zero recorded reasoning, not proof that the +provider consumed none. + +For Claude, pi, and Codex, input is uncached input: cache creation and cache +read are separate counters. The reasoning rule depends on the runtime: + +- **Codex:** Fullsend subtracts reasoning from the wire output count. + Persisted output and reasoning are disjoint, so add a reasoning term + whenever recorded reasoning is non-zero, including interrupted runs. +- **Claude:** Reasoning is a breakdown of output. Do not add it again. + An interrupted iteration may lack the final reasoning count even when + streamed output counts were captured. +- **pi:** The pinned pi `1.3.0` + [usage schema](https://github.com/earendil-works/pi/blob/v1.3.0/packages/ai/src/types.ts#L451-L463) + defines reasoning as a subset of output. Fullsend passes those fields + through, so do not add reasoning again. Recheck the schema when pricing + artifacts from a different pi version; sibling JSON fields and synthetic + fixture totals alone do not establish whether counters overlap. +- **OpenCode:** Fullsend passes its wire counters through. Verify the + provider/version's output, reasoning, and cache semantics before using + either formula; this guide does not establish their overlap. + +Codex and pi synthesize final usage from counters observed before an +interruption. A completed turn or assistant message can report zero +reasoning; completion alone does not imply non-zero reasoning. + +### Worked example + +Extract the relevant attributes from each `agent` span in the local OTLP +JSONL file (see [Output file format](#output-file-format)): + +```bash +jq -c ' + .resourceSpans[]?.scopeSpans[]?.spans[]? + | select(.name == "agent") + | .attributes + | map({key: .key, value: (.value.intValue // .value.doubleValue // .value.stringValue)}) + | from_entries + | { + runtime: .["fullsend.runtime"], + model: .["gen_ai.request.model"], + input: (.["gen_ai.usage.input_tokens"] | tonumber), + output: (.["gen_ai.usage.output_tokens"] | tonumber), + cache_creation: (.["gen_ai.usage.cache_creation.input_tokens"] | tonumber), + cache_read: (.["gen_ai.usage.cache_read.input_tokens"] | tonumber), + reasoning: ((.["gen_ai.usage.reasoning_tokens"] // 0) | tonumber) + } +' run-telemetry.jsonl +``` + +One extracted iteration could look like this (a projection of a span, +not the raw OTLP envelope): + +```json +{ + "runtime": "codex", + "model": "example-model", + "input": 1000, + "output": 500, + "cache_creation": 150000, + "cache_read": 600000, + "reasoning": 200 +} +``` + +Using hypothetical contracted rates of $2.00 / $10.00 / $2.50 / $0.20 / +$10.00 per million tokens (uncached input / output / cache creation / cache +read / reasoning): + +```text +cost = 1000/1e6 * 2.00 + + 500/1e6 * 10.00 + + 150000/1e6 * 2.50 + + 600000/1e6 * 0.20 + + 200/1e6 * 10.00 + = 0.002 + 0.005 + 0.375 + 0.120 + 0.002 + = $0.504 +``` + +The fifth term applies because this is Codex with non-zero reasoning. +For Claude or the pinned pi version, output already includes reasoning: +use the first four terms when reasoning has the same rate as other output. +If your contract prices that subset differently, split output into +`output - reasoning` and `reasoning` and price each once. + +Pricing only uncached input and output would give $0.007 and miss the +cache tokens that dominate this example. Substitute the rates and cache +retention tiers from your contract; these numbers are illustrative. + +Price each iteration at its model's rates, then sum the estimates. Do not +also charge the root `run` span or add `metrics.json` totals: that counts +the same usage twice. An iteration can include multiple models or providers +through fallback and sub-agents, so a single span's model label may not be +enough. Use the [per-model usage breakdown](../../cli/run.md#per-model-usage) +where available. It has no per-model reasoning counter, so mixed-model +Codex reasoning cannot be priced exactly at different model rates from +that breakdown alone. Missing attribution or usage makes the result an +estimate, not a complete billing record. + ## Output file format `run-telemetry.jsonl` contains one JSON object per line. Each object is a diff --git a/docs/guides/user/tracing-with-mlflow.md b/docs/guides/user/tracing-with-mlflow.md index 9b2401071d..9e1df21653 100644 --- a/docs/guides/user/tracing-with-mlflow.md +++ b/docs/guides/user/tracing-with-mlflow.md @@ -78,7 +78,10 @@ token counts and prices them against MLflow's internal model table. This excludes cache-creation and cache-read tokens, which dominate agent-run cost. The authoritative cost figure is the runtime-reported `fullsend.cost_usd` -attribute on `agent` spans (also in `run-telemetry.jsonl`). +attribute on `agent` spans (also in `run-telemetry.jsonl`). When that value +is zero, or when you need a contracted-rate figure rather than the +runtime's reported estimate, compute it from the persisted token fields +— see [Computing dollar cost from token telemetry](../infrastructure/distributed-tracing.md#computing-dollar-cost-from-token-telemetry). ## Level 3 content diff --git a/docs/runtimes/codex.md b/docs/runtimes/codex.md index 6da19bdc26..a6664e1539 100644 --- a/docs/runtimes/codex.md +++ b/docs/runtimes/codex.md @@ -140,9 +140,12 @@ refuse some levels with an upstream 400. Check the levels your model accepts bef | Extra knobs | `FULLSEND_CODEX_MODEL` (the runner-side model default for codex runs; see [Models](#models)) | | Not supported | Sub-agents, `plugins:`, fallback chains, non-OpenAI providers (other than through a Responses-capable inference gateway), Chat Completions or Messages on a gateway | -Cost is **not** in `metrics.json` on codex: the `codex exec --json` stream carries no cost field, so -the value stays `0`. Token counts are recorded normally on the direct route; through a gateway they -can read 0 (see [Models through an inference gateway](#models-through-an-inference-gateway-experimental)). +Cost is recorded as **zero** in `metrics.json` on codex: the +`codex exec --json` stream carries no cost field, so the value stays `0`. +Token counts are recorded normally on the direct route; through a gateway +they can read 0 (see [Models through an inference gateway](#models-through-an-inference-gateway-experimental)). +See [Computing dollar cost from token telemetry](../guides/infrastructure/distributed-tracing.md#computing-dollar-cost-from-token-telemetry) +for a contracted-rate estimate from `run-telemetry.jsonl`, including Codex reasoning tokens. ## Running it locally @@ -286,7 +289,8 @@ What a local codex run needs, beyond the guide: project is untrusted; that is not documented upstream and may change, so keep repository skills in `.agents/skills`. Codex's bundled skills (`skill-installer`, `imagegen` and friends) are switched off, so an agent sees only yours. -- **No cost in metrics** — see [At a glance](#at-a-glance). +- **Reported dollar cost is zero.** Token usage is recorded separately; see + [At a glance](#at-a-glance). ## Not yet exercised From 2a769e098a0ac174942e4e2b3d34522c8195db73 Mon Sep 17 00:00:00 2001 From: fullsend-fix <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 12:02:48 +0000 Subject: [PATCH 2/2] docs: clarify token cost estimate is list price, not contracted rate Fullsend does not support configuring or calculating a contracted rate, so the token-telemetry cost procedure yields a list-price estimate. Reword the contracted-rate language in the tracing, MLflow, and Codex docs accordingly. Note: pre-commit hooks and lychee link check could not run (sandbox network/exec restrictions). No links or anchors were changed. Addresses #7232 Co-Authored-By: Claude Sonnet 5.5 --- .../infrastructure/distributed-tracing.md | 21 +++++++++++-------- docs/guides/user/tracing-with-mlflow.md | 2 +- docs/runtimes/codex.md | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/guides/infrastructure/distributed-tracing.md b/docs/guides/infrastructure/distributed-tracing.md index 0b0def5caf..b57ed12512 100644 --- a/docs/guides/infrastructure/distributed-tracing.md +++ b/docs/guides/infrastructure/distributed-tracing.md @@ -404,8 +404,7 @@ Fullsend does not calculate inference cost from token counts or maintain a model-price table. Each runtime reports a USD cost value and fullsend records it as-is. This section defines the source, aggregation, rounding, and display behavior of that value across every output surface. To compute -a dollar figure from persisted token counts using your own contracted -rates, see [Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry). +a list-price dollar estimate from persisted token counts, see [Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry). ### Runtime cost extraction @@ -466,7 +465,7 @@ If a runtime does not report cost (returns zero or the field is absent), fullsend records zero. There is no fallback cost calculation from token counts. A missing runtime cost propagates as `$0.00` on all surfaces. See [Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry) -for how to apply your own contracted rates to the persisted token fields. +for how to apply list-price rates to the persisted token fields. ### Distinction from backend-derived cost estimates @@ -498,9 +497,11 @@ original [cancelled-run follow-up](https://github.com/fullsend-ai/fullsend/pull/ was closed in favor of pricing the persisted token counts at users' own rates. This procedure covers both cases. -Use `run-telemetry.jsonl` as the primary source for a contracted-rate -estimate. Its `agent` spans carry per-iteration token counts, runtime, and -model identity. `metrics.json` provides the run-level aggregate when span +Use `run-telemetry.jsonl` as the primary source for a list-price estimate. +This is an estimate at the provider's published list price, not your +contracted rate: fullsend does not yet support configuring or calculating +a contracted rate. Its `agent` spans carry per-iteration token counts, +runtime, and model identity. `metrics.json` provides the run-level aggregate when span telemetry is unavailable. Token counts survive interruption where the runtime has reported them; tokens consumed after its last usage update cannot be reconstructed from these artifacts. If telemetry is disabled or @@ -584,7 +585,7 @@ not the raw OTLP envelope): } ``` -Using hypothetical contracted rates of $2.00 / $10.00 / $2.50 / $0.20 / +Using hypothetical list-price rates of $2.00 / $10.00 / $2.50 / $0.20 / $10.00 per million tokens (uncached input / output / cache creation / cache read / reasoning): @@ -601,12 +602,14 @@ cost = 1000/1e6 * 2.00 The fifth term applies because this is Codex with non-zero reasoning. For Claude or the pinned pi version, output already includes reasoning: use the first four terms when reasoning has the same rate as other output. -If your contract prices that subset differently, split output into +If the provider prices that subset differently, split output into `output - reasoning` and `reasoning` and price each once. Pricing only uncached input and output would give $0.007 and miss the cache tokens that dominate this example. Substitute the rates and cache -retention tiers from your contract; these numbers are illustrative. +retention tiers from your provider's published list prices; these numbers +are illustrative. The result is a list-price estimate and will differ from +your actual charge if you have a contracted rate. Price each iteration at its model's rates, then sum the estimates. Do not also charge the root `run` span or add `metrics.json` totals: that counts diff --git a/docs/guides/user/tracing-with-mlflow.md b/docs/guides/user/tracing-with-mlflow.md index 9e1df21653..65ae488894 100644 --- a/docs/guides/user/tracing-with-mlflow.md +++ b/docs/guides/user/tracing-with-mlflow.md @@ -79,7 +79,7 @@ excludes cache-creation and cache-read tokens, which dominate agent-run cost. The authoritative cost figure is the runtime-reported `fullsend.cost_usd` attribute on `agent` spans (also in `run-telemetry.jsonl`). When that value -is zero, or when you need a contracted-rate figure rather than the +is zero, or when you need a list-price figure rather than the runtime's reported estimate, compute it from the persisted token fields — see [Computing dollar cost from token telemetry](../infrastructure/distributed-tracing.md#computing-dollar-cost-from-token-telemetry). diff --git a/docs/runtimes/codex.md b/docs/runtimes/codex.md index a6664e1539..06509c3878 100644 --- a/docs/runtimes/codex.md +++ b/docs/runtimes/codex.md @@ -145,7 +145,7 @@ Cost is recorded as **zero** in `metrics.json` on codex: the Token counts are recorded normally on the direct route; through a gateway they can read 0 (see [Models through an inference gateway](#models-through-an-inference-gateway-experimental)). See [Computing dollar cost from token telemetry](../guides/infrastructure/distributed-tracing.md#computing-dollar-cost-from-token-telemetry) -for a contracted-rate estimate from `run-telemetry.jsonl`, including Codex reasoning tokens. +for a list-price estimate from `run-telemetry.jsonl`, including Codex reasoning tokens. ## Running it locally