feat(anthropic): add support for Opus 4.6 fast mode#12353
Merged
Conversation
gr2m
approved these changes
Feb 8, 2026
Contributor
|
|
gr2m
added a commit
that referenced
this pull request
Feb 9, 2026
This is an automated backport of #12353 to the release-v5.0 branch. --------- Co-authored-by: Felix Arntz <felix.arntz@vercel.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
4 tasks
felixarntz
added a commit
that referenced
this pull request
Feb 9, 2026
…es (#12375) ## Background When streaming with the `anthropic` provider, `response.usage.raw` only contained the 4 explicitly typed fields (`input_tokens`, `output_tokens`, `cache_creation_input_tokens`, `cache_read_input_tokens`) instead of the full raw API response. The raw response from Anthropic's API includes additional fields like `service_tier`, `inference_geo`, `cache_creation`, and `server_tool_use` that were being lost. This worked correctly for `generateText` but not `streamText`. Discovered this while working on #12353: when streaming with `speed=fast`, with this PR enabled you'll see it in the response - without it you weren't even though it was already being used. ## Summary Fixed the `doStream` method to pass the full `rawUsage` JSONObject (which accumulates all fields from stream chunks) to `convertAnthropicMessagesUsage` instead of the typed `usage` object (which only has the 4 declared properties). This also fixes a secondary bug in multi-turn streaming (programmatic tool calling): the typed `usage` object was mutated in place across turns, but `raw` held a reference to this same mutable object, causing all turns to show the last turn's token values. The fix resolves this because `rawUsage` is replaced (not mutated) at each `message_start`. **Changes:** - Updated `convertAnthropicMessagesUsage` to accept `{ usage, rawUsage? }` object instead of just `usage`, using `rawUsage` for the `raw` field when provided - Updated both call sites (`doGenerate` and `doStream`) to use the new signature - Added comprehensive unit tests for the usage conversion function - Updated test snapshots to reflect the now-correct raw usage data ## Manual Verification Run this without the PR, and then again with the PR: ```bash cd examples/ai-functions pnpm tsx src/generate-text/anthropic.ts pnpm tsx src/stream-text/anthropic.ts cd ../.. ``` The `generateText` result will always include actual raw data, e.g. `service_tier`, while the `streamText` result will not. With the PR, the `streamText` result will correctly include those additional values. ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues N/A
4 tasks
felixarntz
added a commit
that referenced
this pull request
Feb 14, 2026
…ard (#12582) ## Background Follow-up to #12353 which added `speed: 'fast'` support for Claude. A few things were missed: `'standard'` is also a valid value per the Anthropic spec, the `speed` field was missing from the API type definitions, and there was no documentation for the feature. These are low-severity issues, but potentially could lead to problems for those that rely on `providerOptions` schema and may incorrectly reject the `'standard'` value. ## Summary - Accept `'standard'` in addition to `'fast'` for the `speed` provider option (it's a no-op but required by the spec) - Add `AnthropicSpeed` type to the API definitions - Add a "Fast Mode" section to the Anthropic provider docs - Add test for `speed: 'standard'` verifying no beta header is sent ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues N/A
gr2m
pushed a commit
that referenced
this pull request
Feb 16, 2026
…ard (#12582) ## Background Follow-up to #12353 which added `speed: 'fast'` support for Claude. A few things were missed: `'standard'` is also a valid value per the Anthropic spec, the `speed` field was missing from the API type definitions, and there was no documentation for the feature. These are low-severity issues, but potentially could lead to problems for those that rely on `providerOptions` schema and may incorrectly reject the `'standard'` value. ## Summary - Accept `'standard'` in addition to `'fast'` for the `speed` provider option (it's a no-op but required by the spec) - Add `AnthropicSpeed` type to the API definitions - Add a "Fast Mode" section to the Anthropic provider docs - Add test for `speed: 'standard'` verifying no beta header is sent ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues N/A
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.
Background
Anthropic released fast mode for Opus 4.6: https://code.claude.com/docs/en/fast-mode
Summary
Added support for Anthropic's fast mode in the
@ai-sdk/anthropicpackage. Users can now enable fast mode by settingspeed: 'fast'in provider options when usingclaude-opus-4-6.Implementation:
speedoption toanthropicProviderOptionsschema (accepts'fast'value)speedparameter in the Messages API request body when setfast-mode-2026-02-01beta header when speed is enabledUsage:
Note: Fast mode is only supported directly with the Anthropic API (see https://code.claude.com/docs/en/fast-mode#requirements), not third-party providers like Amazon Bedrock or Google Vertex — so those provider packages don't require an update at this point.
Manual Verification
Created and ran two example scripts demonstrating fast mode:
examples/ai-functions/src/generate-text/anthropic-fast-mode.ts- generateText with fast modeexamples/ai-functions/src/stream-text/anthropic-fast-mode.ts- streamText with fast modeBoth examples successfully generated output and respected the
speedparameter, with responses includingspeed=fastas expected.Aside: I found a bug where
response.usage.rawwhen streaming Anthropic requests is not the actual raw usage data - unknown fields in the data (likespeed=fast) gets stripped, which defeats the purpose of a "raw" response field. I manually verifiedspeed=fastis included in the response, but the AI SDK strips it. Will fix in a follow up PR because it's not just scoped to this.Checklist
pnpm changesetin the project root)