@ai-sdk/anthropic 3.0.38 → 3.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.38",
3
+ "version": "3.0.40",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -350,6 +350,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
350
350
  ...(anthropicOptions?.effort && {
351
351
  output_config: { effort: anthropicOptions.effort },
352
352
  }),
353
+ ...(anthropicOptions?.speed && {
354
+ speed: anthropicOptions.speed,
355
+ }),
353
356
 
354
357
  // structured output:
355
358
  ...(useStructuredOutput &&
@@ -554,6 +557,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
554
557
  betas.add('effort-2025-11-24');
555
558
  }
556
559
 
560
+ if (anthropicOptions?.speed) {
561
+ betas.add('fast-mode-2026-02-01');
562
+ }
563
+
557
564
  // only when streaming: enable fine-grained tool streaming
558
565
  if (stream && (anthropicOptions?.toolStreaming ?? true)) {
559
566
  betas.add('fine-grained-tool-streaming-2025-05-14');
@@ -1091,7 +1098,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
1091
1098
  }),
1092
1099
  raw: response.stop_reason ?? undefined,
1093
1100
  },
1094
- usage: convertAnthropicMessagesUsage(response.usage),
1101
+ usage: convertAnthropicMessagesUsage({ usage: response.usage }),
1095
1102
  request: { body: args },
1096
1103
  response: {
1097
1104
  id: response.id ?? undefined,
@@ -2026,7 +2033,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2026
2033
  controller.enqueue({
2027
2034
  type: 'finish',
2028
2035
  finishReason,
2029
- usage: convertAnthropicMessagesUsage(usage),
2036
+ usage: convertAnthropicMessagesUsage({ usage, rawUsage }),
2030
2037
  providerMetadata,
2031
2038
  });
2032
2039
  return;
@@ -170,6 +170,12 @@ export const anthropicProviderOptions = z.object({
170
170
  */
171
171
  effort: z.enum(['low', 'medium', 'high', 'max']).optional(),
172
172
 
173
+ /**
174
+ * Enable fast mode for faster inference (2.5x faster output token speeds).
175
+ * Only supported with claude-opus-4-6.
176
+ */
177
+ speed: z.literal('fast').optional(),
178
+
173
179
  contextManagement: z
174
180
  .object({
175
181
  edits: z.array(
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3Usage } from '@ai-sdk/provider';
1
+ import { JSONObject, LanguageModelV3Usage } from '@ai-sdk/provider';
2
2
 
3
3
  export type AnthropicMessagesUsage = {
4
4
  input_tokens: number;
@@ -7,9 +7,13 @@ export type AnthropicMessagesUsage = {
7
7
  cache_read_input_tokens?: number | null;
8
8
  };
9
9
 
10
- export function convertAnthropicMessagesUsage(
11
- usage: AnthropicMessagesUsage,
12
- ): LanguageModelV3Usage {
10
+ export function convertAnthropicMessagesUsage({
11
+ usage,
12
+ rawUsage,
13
+ }: {
14
+ usage: AnthropicMessagesUsage;
15
+ rawUsage?: JSONObject;
16
+ }): LanguageModelV3Usage {
13
17
  const inputTokens = usage.input_tokens;
14
18
  const outputTokens = usage.output_tokens;
15
19
  const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
@@ -27,6 +31,6 @@ export function convertAnthropicMessagesUsage(
27
31
  text: undefined,
28
32
  reasoning: undefined,
29
33
  },
30
- raw: usage,
34
+ raw: rawUsage ?? usage,
31
35
  };
32
36
  }