Skip to content

feat(observability): show the cached input and the reasoning inside a run's tokens - #230

Merged
goldbarth merged 1 commit into
mainfrom
feat/usage-cached-reasoning
Sep 22, 2026
Merged

goldbarth merged 1 commit into
mainfrom
feat/usage-cached-reasoning

Conversation

@goldbarth

Copy link
Copy Markdown
Owner

Follows #229 (LlmCall record), point 3 of the measurement plan for the provider comparison runs

  • Two parts of the tokens made visible: cached input (served from the provider's prompt cache, usually billed lower) and reasoning output (spent thinking, billed as output, never in the changelog). Both come from Microsoft.Extensions.AI's UsageDetails, so no provider type is named.

  • Checked what each adapter fills, against the real SDKs:

    input cached reasoning
    Anthropic includes cache reads cache_read_input_tokens not reported (folded into output)
    OpenAI prompt_tokens cached_tokens reasoning_tokens

    Same meaning on both: cached is a part of input, reasoning a part of output, so in / out stay complete totals.

  • Not reported stays unknown: summed over the calls that reported it, null until one does; the summary says reasoning not reported rather than 0, which would claim the model did not think.

  • Cache writes (Anthropic's cache_creation_input_tokens) are left out: they arrive only under an adapter-specific key, and occur only when caching is requested, which Chartula does not do today.

  • Summary: a of which N in cached, M out reasoning line under each operation with calls. Run record: cachedInputTokens, reasoningTokens per operation, left out when not reported; additive under schemaVersion: 1.

  • Docs: run-metrics.md, run-record.md.

Verified end to end: the release binary against a local OpenAI-compatible fake reporting both details:

  Rephrasing:       1 call, 6,000 in / 320 out, 0.5 s
    of which 4,096 in cached, 300 out reasoning

Tests: UsageDetailTests (real Anthropic and OpenAI adapters), RunMetricsTests (summing with unreported calls), RunReportFormatterTests (detail line, not reported), RunRecordJsonSerializerTests (written and omitted); full suite 721 passing, build and dotnet format clean.

@goldbarth
goldbarth merged commit 31fb7e7 into main Sep 22, 2026
4 checks passed
@goldbarth
goldbarth deleted the feat/usage-cached-reasoning branch September 22, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant