Skip to content

feat(anthropic): add support for Opus 4.6 fast mode#12353

Merged
gr2m merged 1 commit intomainfrom
add-opus-4-6-fast-mode
Feb 8, 2026
Merged

feat(anthropic): add support for Opus 4.6 fast mode#12353
gr2m merged 1 commit intomainfrom
add-opus-4-6-fast-mode

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

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/anthropic package. Users can now enable fast mode by setting speed: 'fast' in provider options when using claude-opus-4-6.

Implementation:

  • Added speed option to anthropicProviderOptions schema (accepts 'fast' value)
  • Pass speed parameter in the Messages API request body when set
  • Automatically add fast-mode-2026-02-01 beta header when speed is enabled
  • Added unit test to verify request body and headers are correctly set

Usage:

import { anthropic } from '@ai-sdk/anthropic';
import { generateText } from 'ai';

const result = await generateText({
  model: anthropic('claude-opus-4-6'),
  prompt: 'Hello!',
  providerOptions: {
    anthropic: {
      speed: 'fast',
    },
  },
});

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 mode
  • examples/ai-functions/src/stream-text/anthropic-fast-mode.ts - streamText with fast mode

Both examples successfully generated output and respected the speed parameter, with responses including speed=fast as expected.

Aside: I found a bug where response.usage.raw when streaming Anthropic requests is not the actual raw usage data - unknown fields in the data (like speed=fast) gets stripped, which defeats the purpose of a "raw" response field. I manually verified speed=fast is 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

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Feb 8, 2026
@felixarntz felixarntz added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Feb 8, 2026
@gr2m gr2m merged commit 0a0d29c into main Feb 8, 2026
31 checks passed
@gr2m gr2m deleted the add-opus-4-6-fast-mode branch February 8, 2026 23:06
vercel-ai-sdk bot pushed a commit that referenced this pull request Feb 8, 2026
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Feb 8, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Feb 8, 2026

⚠️ Backport to release-v5.0 created but has conflicts: #12357

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>
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants