Skip to content

fix: guard Anthropic thinking budgetTokens for unknown output limits#22581

Open
comzip wants to merge 1 commit intoanomalyco:devfrom
comzip:fix/guard-anthropic-thinking-budget
Open

fix: guard Anthropic thinking budgetTokens for unknown output limits#22581
comzip wants to merge 1 commit intoanomalyco:devfrom
comzip:fix/guard-anthropic-thinking-budget

Conversation

@comzip
Copy link
Copy Markdown

@comzip comzip commented Apr 15, 2026

Issue for this PR

Fixes #22253

Type of change

  • Bug fix

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:

  • output: 0 → returns {}
  • output: 2049 → returns {} (budgetTokens would be below Anthropic's 1024 minimum)

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
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.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@comzip comzip force-pushed the fix/guard-anthropic-thinking-budget branch from 7914771 to d74d764 Compare April 15, 2026 08:25
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
@comzip comzip force-pushed the fix/guard-anthropic-thinking-budget branch from d74d764 to d02ef01 Compare April 15, 2026 08:30
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.

[Bug] Custom provider models fail with "maxOutputTokens must be >= 1" when limit is not defined

1 participant