Repository navigation
fix(mistral): map cached token counts from Mistral usage response - #14889
Merged
lgrammel merged 2 commits intoMay 4, 2026
Merged
Conversation
Mistral API returns cached token counts via num_cached_tokens, prompt_tokens_details.cached_tokens, and prompt_token_details.cached_tokens. These fields were stripped by the Zod schema and never mapped in convertMistralUsage, causing all prompt tokens to be reported as noCacheTokens. This adds the fields to the schema and computes cacheRead/noCache correctly. Closes vercel#14382
4 tasks done
lgrammel
approved these changes
May 4, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 4, 2026
…4889) ## Summary - Mistral's API returns cached token counts via `num_cached_tokens`, `prompt_tokens_details.cached_tokens`, and `prompt_token_details.cached_tokens` - These fields were not included in `mistralUsageSchema` (stripped by Zod) and not mapped in `convertMistralUsage` - All prompt tokens were incorrectly reported as `noCacheTokens` - Adds the fields to the schema and computes `cacheRead`/`noCache` correctly ## Test plan - [x] Unit test with cached token fields in usage response - [x] Verify noCache = promptTokens - cacheReadTokens - [x] Verify cacheRead is populated when cached tokens present - [x] Verify backward compatibility when cached fields are absent ## Related Issues Closes #14382 Supersedes #14419 Co-authored-by: Lars Grammel <[email protected]>
Contributor
|
✅ Backport PR created: #14947 |
3 of 5 tasks
gr2m
pushed a commit
that referenced
this pull request
May 4, 2026
…sponse (#14947) This is an automated backport of #14889 to the release-v6.0 branch. FYI @Christian-Sidak Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Lars Grammel <[email protected]>
gr2m
pushed a commit
that referenced
this pull request
Jun 5, 2026
…4889) ## Summary - Mistral's API returns cached token counts via `num_cached_tokens`, `prompt_tokens_details.cached_tokens`, and `prompt_token_details.cached_tokens` - These fields were not included in `mistralUsageSchema` (stripped by Zod) and not mapped in `convertMistralUsage` - All prompt tokens were incorrectly reported as `noCacheTokens` - Adds the fields to the schema and computes `cacheRead`/`noCache` correctly ## Test plan - [x] Unit test with cached token fields in usage response - [x] Verify noCache = promptTokens - cacheReadTokens - [x] Verify cacheRead is populated when cached tokens present - [x] Verify backward compatibility when cached fields are absent ## Related Issues Closes #14382 Supersedes #14419 Co-authored-by: Lars Grammel <[email protected]>
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
num_cached_tokens,prompt_tokens_details.cached_tokens, andprompt_token_details.cached_tokensmistralUsageSchema(stripped by Zod) and not mapped inconvertMistralUsagenoCacheTokenscacheRead/noCachecorrectlyTest plan
Related Issues
Closes #14382
Supersedes #14419