Skip to content

feat(chat): cache metrics in debug traces, drop user name from prompt#9

Merged
albanm merged 2 commits into
mainfrom
perf-prompt-caching
Jun 4, 2026
Merged

feat(chat): cache metrics in debug traces, drop user name from prompt#9
albanm merged 2 commits into
mainfrom
perf-prompt-caching

Conversation

@albanm

@albanm albanm commented Jun 4, 2026

Copy link
Copy Markdown
Member

Surface provider prompt-cache token counts in the chat debug dialog, and stop sending the user's name to model providers.

What changed:

  • The gateway now forwards cache token details (Anthropic cache read/write, OpenAI cached_tokens) in its OpenAI-compatible usage as prompt_tokens_details.{cached_tokens,cache_creation_tokens}. The AI SDK normalizes these into usage.inputTokenDetails, so it's provider-agnostic.
  • The client parses them and shows them in the debug dialog: per physical-request trace (preview 100 in (80 cached) · … and detail) and in the session usage header.
  • The chat system prompt no longer interpolates the user's name (org, department, language and the compact hint are kept).

Why: part of the prompt-caching work — surface cache hit/write metrics so we can measure caching before tuning it; remove the user name because it has no bearing on assistant behaviour, is a privacy concern to send to providers, and makes the prompt prefix more homogeneous across users.

Regression risks:

  • Billing is unchanged (full input tokens). Anthropic cache reads stay 0 until cache_control breakpoints are added; OpenAI-family auto-caching will show real cache reads immediately.

Verified: check-types clean, lint 0 errors, gateway-response + session-recorder unit specs pass (including a new cache-extraction test).

albanm and others added 2 commits June 4, 2026 09:50
…ame from system prompt

Forward provider cache token counts (Anthropic cache read/write, OpenAI
cached_tokens) through the gateway's OpenAI-compatible usage object, parse
them client-side, and display them in the debug dialog — per physical-request
trace (preview + detail) and in the session usage header. The AI SDK
normalizes these into usage.inputTokenDetails regardless of provider.

Also remove the user's name from the chat system prompt (keeping org,
department, language and the compact hint) — irrelevant to assistant
behaviour, a privacy concern to send to providers, and it makes the prompt
prefix more homogeneous across users for prompt caching.

Billing is unchanged (full input tokens). Anthropic reads stay 0 until
cache_control breakpoints are added; OpenAI-family auto-caching shows real
cache reads immediately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added feature and removed feature labels Jun 4, 2026
@albanm albanm merged commit 7075536 into main Jun 4, 2026
5 checks passed
@albanm albanm deleted the perf-prompt-caching branch June 4, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant