Skip to content

fix(sse): include prompt cache usage fields on message_stop fallback path - #10545

Merged
diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.50from
NahuSaruf:fix/openai-translator-cache-usage-fields
Aug 21, 2026
Merged

diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.50from
NahuSaruf:fix/openai-translator-cache-usage-fields

Conversation

@NahuSaruf

Copy link
Copy Markdown
Contributor

Summary

  • claude-to-openai.ts built the final OpenAI-format usage payload in two places: the message_delta finish path (already mapped cache_read/cache_creation into prompt_tokens_details) and a message_stop fallback used when the finish signal arrives without usage on the same event.
  • The fallback never copied the cache fields, so OpenAI-compatible clients saw "0% cache hit" even though the data was present in state.usage (matches the report: Claude-format responses had the counters, OpenAI-format ones didn't).
  • Mirrored the existing prompt_tokens_details mapping from the message_delta path into the message_stop fallback.

Fixes #10535

Test plan

⚠️ base-red inherited: #9985 (the two failing jobs on the latest schedule run — "Validate main branch" and "Bank ratchet shrinks" — are unrelated to this change; "Validate active release branch" passed on the current tip).

…path

claude-to-openai.ts built the final OpenAI-format usage payload in two
places: the message_delta finish path (which already mapped cache_read/
cache_creation into prompt_tokens_details) and a message_stop fallback
used when the finish signal arrives without usage attached to the same
event. The fallback never copied the cache fields, so OpenAI-compatible
clients saw 0% cache hit even though the data was present in state.usage.

Fixes cheaper-inference#10535
@diegosouzapw

Copy link
Copy Markdown
Collaborator

The focused translator suite passes 15/15 and lint is clean. Before marking this merge-ready,
please add or confirm coverage for cache-creation-only, read-plus-creation, missing
state.usage, and preservation of prompt_tokens_details on the message_stop fallback. These
are small table-driven cases but protect the usage/billing contract.

@diegosouzapw diegosouzapw added deferred-v3.8.50 Adiada para o ciclo v3.8.50 (validacao VPS, refactor, ou escopo grande) merge-train-deferred PR ejetada do merge-train — triagem separada and removed merge-train-deferred PR ejetada do merge-train — triagem separada deferred-v3.8.50 Adiada para o ciclo v3.8.50 (validacao VPS, refactor, ou escopo grande) labels Aug 17, 2026
@diegosouzapw
diegosouzapw merged commit 00aba8e into cheaper-inference:release/v3.8.50 Aug 21, 2026
3 checks passed
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…path (cheaper-inference#10545)

Mirrors the existing prompt_tokens_details cache-field mapping from the message_delta finish path into the message_stop fallback, so OpenAI-compatible clients see cache_read/cache_creation counters when the finish signal arrives without usage on the same event. Fixes cheaper-inference#10535.

Validated in an isolated worktree boarded onto origin/release/v3.8.50 (0 conflicts, 2 files):
- 16/16 focused tests pass (translator-resp-claude-to-openai.test.ts), including the new regression test for this exact fallback path.
- check-file-size, check-changelog-integrity: OK.
- typecheck:core: clean.
- check-complexity / check-cognitive-complexity: OK, both under baseline.

Co-authored-by: NahuSaruf <NahuSaruf@users.noreply.github.com>
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.

fix(api): OpenAI-format responses drop prompt-cache usage fields (no prompt_tokens_details.cached_tokens)

2 participants