Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `<config path> agents.<name>`, `harness`, `default`), suffixed `, remapped by <config path> 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.<name>` 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 |
Expand Down
147 changes: 145 additions & 2 deletions docs/guides/infrastructure/distributed-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ 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 list-price dollar estimate from persisted token counts, see [Computing dollar cost from token telemetry](#computing-dollar-cost-from-token-telemetry).

Comment thread
ascerra marked this conversation as resolved.
Resolved
### Runtime cost extraction

Expand All @@ -413,6 +414,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
Expand Down Expand Up @@ -461,7 +463,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 list-price rates to the persisted token fields.

### Distinction from backend-derived cost estimates

Expand All @@ -478,6 +482,145 @@ 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 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
Comment thread
ascerra marked this conversation as resolved.
Resolved
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 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):

```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 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 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
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
Expand Down
5 changes: 4 additions & 1 deletion docs/guides/user/tracing-with-mlflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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).

## Level 3 content

Expand Down
12 changes: 8 additions & 4 deletions docs/runtimes/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 list-price estimate from `run-telemetry.jsonl`, including Codex reasoning tokens.

## Running it locally

Expand Down Expand Up @@ -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
Comment thread
ascerra marked this conversation as resolved.
Resolved

Expand Down
Loading