Skip to content

Commit 23ac4a3

Browse files
authored
fix(provider/anthropic): minor follow up to support no-op speed standard (#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
1 parent 72d36c9 commit 23ac4a3

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

.changeset/shaggy-steaks-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/anthropic': patch
3+
---
4+
5+
fix(provider/anthropic): minor follow up to support no-op speed standard

content/providers/01-ai-sdk-providers/05-anthropic.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ The following optional provider options are available for Anthropic models:
125125

126126
Optional. See [Effort section](#effort) for more details.
127127

128+
- `speed` _"fast" | "standard"_
129+
130+
Optional. See [Fast Mode section](#fast-mode) for more details.
131+
128132
- `thinking` _object_
129133

130134
Optional. See [Reasoning section](#reasoning) for more details.
@@ -192,6 +196,27 @@ console.log(text); // resulting text
192196
console.log(usage); // token usage
193197
```
194198

199+
### Fast Mode
200+
201+
Anthropic supports a [`speed` option](https://code.claude.com/docs/en/fast-mode) for `claude-opus-4-6` that enables faster inference with approximately 2.5x faster output token speeds.
202+
203+
```ts highlight="8-10"
204+
import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
205+
import { generateText } from 'ai';
206+
207+
const { text } = await generateText({
208+
model: anthropic('claude-opus-4-6'),
209+
prompt: 'Write a short poem about the sea.',
210+
providerOptions: {
211+
anthropic: {
212+
speed: 'fast',
213+
} satisfies AnthropicLanguageModelOptions,
214+
},
215+
});
216+
```
217+
218+
The `speed` option accepts `'fast'` or `'standard'` (default behavior).
219+
195220
### Reasoning
196221

197222
Anthropic has reasoning support for `claude-opus-4-20250514`, `claude-sonnet-4-20250514`, and `claude-3-7-sonnet-20250219` models.

packages/anthropic/src/anthropic-messages-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ export type AnthropicTool =
439439
name: string;
440440
};
441441

442+
export type AnthropicSpeed = 'fast' | 'standard';
443+
442444
export type AnthropicToolChoice =
443445
| { type: 'auto' | 'any'; disable_parallel_tool_use?: boolean }
444446
| { type: 'tool'; name: string; disable_parallel_tool_use?: boolean };

packages/anthropic/src/anthropic-messages-language-model.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,47 @@ describe('AnthropicMessagesLanguageModel', () => {
41274127
expect(result.warnings).toStrictEqual([]);
41284128
});
41294129

4130+
it('should set speed=standard without fast-mode beta header', async () => {
4131+
prepareJsonFixtureResponse('anthropic-text');
4132+
4133+
const result = await model.doGenerate({
4134+
prompt: TEST_PROMPT,
4135+
providerOptions: {
4136+
anthropic: {
4137+
speed: 'standard',
4138+
} satisfies AnthropicLanguageModelOptions,
4139+
},
4140+
});
4141+
4142+
expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(`
4143+
{
4144+
"max_tokens": 4096,
4145+
"messages": [
4146+
{
4147+
"content": [
4148+
{
4149+
"text": "Hello",
4150+
"type": "text",
4151+
},
4152+
],
4153+
"role": "user",
4154+
},
4155+
],
4156+
"model": "claude-3-haiku-20240307",
4157+
"speed": "standard",
4158+
}
4159+
`);
4160+
expect(await server.calls[0].requestHeaders).toMatchInlineSnapshot(`
4161+
{
4162+
"anthropic-version": "2023-06-01",
4163+
"content-type": "application/json",
4164+
"x-api-key": "test-api-key",
4165+
}
4166+
`);
4167+
4168+
expect(result.warnings).toStrictEqual([]);
4169+
});
4170+
41304171
describe('context management', () => {
41314172
it('should send context_management in request body', async () => {
41324173
prepareJsonFixtureResponse('anthropic-text');

packages/anthropic/src/anthropic-messages-language-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
576576
betas.add('effort-2025-11-24');
577577
}
578578

579-
if (anthropicOptions?.speed) {
579+
if (anthropicOptions?.speed === 'fast') {
580580
betas.add('fast-mode-2026-02-01');
581581
}
582582

packages/anthropic/src/anthropic-messages-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const anthropicLanguageModelOptions = z.object({
174174
* Enable fast mode for faster inference (2.5x faster output token speeds).
175175
* Only supported with claude-opus-4-6.
176176
*/
177-
speed: z.literal('fast').optional(),
177+
speed: z.enum(['fast', 'standard']).optional(),
178178

179179
contextManagement: z
180180
.object({

0 commit comments

Comments
 (0)