Skip to content

[v5.0] fix: surface the implicit output token limit for unknown Anthropic models - #17691

Merged
lgrammel merged 2 commits into
release-v5.0from
backport-v5.0/17588-6
Jul 22, 2026
Merged

[v5.0] fix: surface the implicit output token limit for unknown Anthropic models#17691
lgrammel merged 2 commits into
release-v5.0from
backport-v5.0/17588-6

Conversation

@lgrammel

Copy link
Copy Markdown
Collaborator

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

Backport of #17611

Co-authored-by: plutonium-94 47095613+plutonium-94@users.noreply.github.com

lgrammel added 2 commits July 22, 2026 08:46
…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>
@lgrammel

Copy link
Copy Markdown
Collaborator Author

Bugfix review

Outcome: approved

Fixes issue

Status: 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 effects

Risk: 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.

Performance

Risk: low

Affected calls allocate one small warning object and message string; no additional network requests, iteration, caching, or retained state are introduced.

Backwards compatibility

Risk: none

There are no stored-data, schema, or serialization changes, and existing requests continue sending the same max_tokens values.

Architecture

Risk: 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 scope

Status: 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.

Security

Risk: 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.

Testing

Status: 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.

Verification

Inspected 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

@lgrammel
lgrammel merged commit 5bb3ae4 into release-v5.0 Jul 22, 2026
53 of 54 checks passed
@lgrammel
lgrammel deleted the backport-v5.0/17588-6 branch July 22, 2026 09:09
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 5.0.219 github npm
@ai-sdk/amazon-bedrock 3.0.109 github npm
@ai-sdk/angular 1.0.219 github npm
@ai-sdk/anthropic 2.0.89 github npm
@ai-sdk/anthropic-aws 0.1.4 github npm
@ai-sdk/gateway 2.0.118 github npm
@ai-sdk/google-vertex 3.0.156 github npm
@ai-sdk/langchain 1.0.219 github npm
@ai-sdk/llamaindex 1.0.219 github npm
@ai-sdk/react 2.0.221 github npm
@ai-sdk/rsc 1.0.221 github npm
@ai-sdk/svelte 3.0.219 github npm
@ai-sdk/vue 2.0.219 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant