[v5.0] fix: surface the implicit output token limit for unknown Anthropic models - #17691
Conversation
…dels (#17611) ## Background Unknown Anthropic models silently received a 4096-token output limit when maxOutputTokens was omitted, making unexpected response truncation difficult to diagnose. ## Root Cause getModelCapabilities returned a 4096 fallback with isKnownModel false, and getArgs used that fallback as max_tokens without adding a provider warning. The reproduction confirmed a 4096 request limit and an empty warnings array. ## Bugfix Guidance ``` address the issue the following way: raise a warning when the model is unknown and state in the warning that output tokens have been limited to 4096 ``` ## Summary Added a compatibility warning identifying the unknown model, stating that output tokens were limited to 4096, and recommending an explicit maxOutputTokens value. Existing request behavior remains unchanged. ## Testing Added regression tests verifying that unknown models receive the warning with the 4096 fallback and that explicitly setting maxOutputTokens suppresses it. Added a patch changeset for @ai-sdk/anthropic. ## End-to-end Validation - `pnpm -C packages/anthropic build && pnpm -C examples/ai-functions exec tsx -e '…'` built the published package and exercised generateText with a synthetic unknown model; the request contained `max_tokens: 4096` and the returned and logged warning stated that output tokens were limited to 4096. ## Related Issues Fixes #17588 Closes #17596 Co-authored-by: plutonium-94 <47095613+plutonium-94@users.noreply.github.com>
Bugfix reviewOutcome: approved Fixes issueStatus: fully-addresses Unknown models without maxOutputTokens now retain the backwards-compatible 4096 request value but return and log a warning identifying the implicit limit and its explicit override. Keeping max_tokens is consistent with Anthropic documenting it as the model-specific absolute generation maximum. Side effectsRisk: low Request construction and token limits are unchanged; the only observable change is an intentional provider warning for unknown models that rely on the fallback, including related providers using the same Anthropic implementation. PerformanceRisk: low Affected calls allocate one small warning object and message string; no additional network requests, iteration, caching, or retained state are introduced. Backwards compatibilityRisk: none There are no stored-data, schema, or serialization changes, and existing requests continue sending the same max_tokens values. ArchitectureRisk: low The condition is localized in the Anthropic language-model argument builder that owns the fallback, uses the existing LanguageModelV2 warning abstraction, and introduces no new dependencies, cross-package source imports, or misplaced shared helpers. Change scopeStatus: minimal All three changed files are necessary: the localized warning branch, focused regression tests, and the required patch changeset. No unrelated implementation or generated artifacts were added. SecurityRisk: none The change does not alter authentication, network destinations, request contents, credential handling, or data exposure; it only surfaces locally available model and limit information through the existing warning channel. TestingStatus: appropriate Regression tests verify the unknown-model 4096 fallback and warning, plus suppression and preservation of an explicit maxOutputTokens value. The shared argument path covers generation and streaming, and the complete package suites passed in both Node and Edge environments. VerificationInspected the complete three-file merge-base diff, warning type and logging paths, model-capability fallback, and declared internal package exports. Anthropic type-checking passed; the full Node and Edge suites each passed all 227 tests. A focused generateText integration confirmed max_tokens remained 4096 while the warning was both returned and delivered to the configured warning logger. Diff validation and repository status were clean. Relevant Documentation |
|
🚀 Published in:
|
Background
Unknown Anthropic models silently received a 4096-token output limit when maxOutputTokens was omitted, making unexpected response truncation difficult to diagnose.
Root Cause
getModelCapabilities returned a 4096 fallback with isKnownModel false, and getArgs used that fallback as max_tokens without adding a provider warning. The reproduction confirmed a 4096 request limit and an empty warnings array.
Bugfix Guidance
Summary
Added a compatibility warning identifying the unknown model, stating that output tokens were limited to 4096, and recommending an explicit maxOutputTokens value. Existing request behavior remains unchanged.
Testing
Added regression tests verifying that unknown models receive the warning with the 4096 fallback and that explicitly setting maxOutputTokens suppresses it. Added a patch changeset for @ai-sdk/anthropic.
End-to-end Validation
pnpm -C packages/anthropic build && pnpm -C examples/ai-functions exec tsx -e '…'built the published package and exercised generateText with a synthetic unknown model; the request containedmax_tokens: 4096and the returned and logged warning stated that output tokens were limited to 4096.Related Issues
Fixes #17588
Closes #17596
Backport of #17611
Co-authored-by: plutonium-94 47095613+plutonium-94@users.noreply.github.com