fix: guard Anthropic thinking budgetTokens for unknown output limits#22581
Open
comzip wants to merge 1 commit intoanomalyco:devfrom
Open
fix: guard Anthropic thinking budgetTokens for unknown output limits#22581comzip wants to merge 1 commit intoanomalyco:devfrom
comzip wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found one potentially related PR: Related PR:
The other results (#12544, #12342) are older PRs about Anthropic thinking features but not directly addressing this specific bug fix. |
2493bc4 to
7914771
Compare
3 tasks
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
7914771 to
d74d764
Compare
Custom providers without an explicit output limit get limit.output = 0 (sentinel value). The budgetTokens calculation Math.floor(output / 2 - 1) becomes negative, causing "maxOutputTokens must be >= 1" from the API. Extract highBudget() to centralize the formula and its validation (result >= 1024, Anthropic's minimum). Both variants() and the kimi-k2.5 path share this helper, so the guard lives in one place. Fixes anomalyco#22253
d74d764 to
d02ef01
Compare
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.
Issue for this PR
Fixes #22253
Type of change
What does this PR do?
Custom provider models without a limit field get limit.output = 0. The budgetTokens formula Math.floor(output / 2 - 1) returns -1 in this case, which causes an error when Anthropic's API validates the thinking config. Extracted highBudget() to centralize the formula and guard against invalid results (Anthropic requires budgetTokens >= 1024). Both variants() and the kimi-k2.5 path now share this helper, so the guard lives in one place instead of being duplicated.
How did you verify your code works?
Added two unit tests in transform.test.ts:
Screenshots / recordings
N/A
Checklist