Repository navigation
fix(mlx): surface engine prompt-cache reads in usage accounting - #288
Merged
Merged
Conversation
The fusion-mlx engine reports prefix-cache hits (prompt_tokens_details. cached_tokens, verified live: identical request 2nd/3rd call returns cached_tokens=64), and its Anthropic-style /v1/messages endpoint emits cache_read_input_tokens. The OpenAI-endpoint translation layer dropped that data, so session jsonl recorded cache_read_input_tokens=0 across 2,365 real sessions (125M input tokens with zero cache accounting) and efficiency baselines could not measure cache benefit. - MLXUsage gains optional prompt_tokens_details block - streaming message_delta maps cached_tokens -> cache_read_input_tokens - non-stream transform does the same - fields omitted when cached_tokens is 0/absent: uncached runs stay byte-identical Found during token-efficiency baseline investigation (bench report #1). Co-Authored-By: Claude Code <[email protected]>
…ontract Co-Authored-By: Claude Code <[email protected]>
This was referenced Nov 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the
cache_read_input_tokens = 0anomaly from the token-efficiency baseline (#281).Root cause chain, verified live against fusion-mlx 0.10.67:
prompt_tokens_details.cached_tokens = 64(of 82 prompt tokens)/v1/messagesendpoint emitscache_read_input_tokensMLXUsagelackedprompt_tokens_details, and both the streamingmessage_deltaand the non-stream transform mapped onlyprompt_tokens/completion_tokensChanges
fusion-mlx-types.ts:MLXUsagegains optionalprompt_tokens_detailsblockfusion-mlx-stream.ts: streamingmessage_delta+ non-stream transform mapcached_tokens->cache_read_input_tokenscached_tokensis 0/absent - uncached runs stay byte-identicalTest plan
bun test tests/services/api/ src/__tests__/llm/: 260 pass, 0 failbun run typecheckclean;bun run checkfull gate green🤖 Generated with Claude Code