@ai-sdk/anthropic 3.0.81 → 3.0.82

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.82
4
+
5
+ ### Patch Changes
6
+
7
+ - 2a91a17: feat(provider/anthropic): add support for `claude-fable-5` and the `fallbacks` API parameter
8
+
3
9
  ## 3.0.81
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -11,34 +11,21 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
11
11
  * - `compaction`: a context compaction step (billed at executor rates).
12
12
  * - `message`: an executor sampling iteration (billed at executor rates).
13
13
  * - `advisor_message`: an advisor sub-inference (billed at the advisor
14
- * model's rates; `model` carries the advisor model ID). Advisor token
15
- * usage is NOT rolled into the top-level usage totals because it bills
16
- * at a different rate; inspect this array directly for advisor billing.
14
+ * model's rates). Advisor token usage is NOT rolled into the top-level
15
+ * usage totals because it bills at a different rate; inspect this array
16
+ * directly for advisor billing.
17
+ * - `fallback_message`: a server-side fallback attempt that served the turn.
18
+ * Inspect this array for exact per-model attribution on a turn that fell
19
+ * back.
17
20
  */
18
21
  type AnthropicUsageIteration = {
19
- type: 'compaction' | 'message';
22
+ type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
20
23
  /**
21
- * Number of input tokens consumed in this iteration.
22
- */
23
- inputTokens: number;
24
- /**
25
- * Number of output tokens generated in this iteration.
26
- */
27
- outputTokens: number;
28
- /**
29
- * Number of cache-creation input tokens consumed in this iteration.
30
- */
31
- cacheCreationInputTokens?: number;
32
- /**
33
- * Number of cache-read input tokens consumed in this iteration.
34
- */
35
- cacheReadInputTokens?: number;
36
- } | {
37
- type: 'advisor_message';
38
- /**
39
- * The advisor model that produced this iteration.
24
+ * The model that produced this iteration. Populated for the per-model
25
+ * attribution cases (the fallback chain and advisor sub-inferences) and
26
+ * absent otherwise.
40
27
  */
41
- model: string;
28
+ model?: string;
42
29
  /**
43
30
  * Number of input tokens consumed in this iteration.
44
31
  */
@@ -48,15 +35,11 @@ type AnthropicUsageIteration = {
48
35
  */
49
36
  outputTokens: number;
50
37
  /**
51
- * Number of cache-creation input tokens consumed by this advisor
52
- * sub-inference. Nonzero when advisor-side caching is enabled and
53
- * the advisor writes a fresh cache entry.
38
+ * Number of cache-creation input tokens consumed in this iteration.
54
39
  */
55
40
  cacheCreationInputTokens?: number;
56
41
  /**
57
- * Number of cache-read input tokens consumed by this advisor
58
- * sub-inference. Nonzero on the second and later advisor calls
59
- * when advisor-side caching is enabled.
42
+ * Number of cache-read input tokens consumed in this iteration.
60
43
  */
61
44
  cacheReadInputTokens?: number;
62
45
  };
@@ -64,6 +47,38 @@ interface AnthropicMessageMetadata {
64
47
  usage: JSONObject;
65
48
  cacheCreationInputTokens: number | null;
66
49
  stopSequence: string | null;
50
+ /**
51
+ * Details about why the request stopped. Present only when the API returns
52
+ * a `refusal` stop reason together with a `stop_details` object (a
53
+ * classifier block or a model refusal).
54
+ *
55
+ * Branch on the finish reason (`content-filter`), not on this object: the
56
+ * API may return a refusal with no details at all, so this field can be
57
+ * absent even on a refusal and should not be relied upon being present.
58
+ */
59
+ stopDetails?: {
60
+ /**
61
+ * The kind of stop detail. `'refusal'` for classifier blocks and model
62
+ * refusals.
63
+ */
64
+ type: string;
65
+ /**
66
+ * The classifier category that triggered the block, e.g. `'cyber'` or
67
+ * `'bio'`. Absent for model refusals and other cases.
68
+ */
69
+ category?: string;
70
+ /**
71
+ * Human-readable explanation of why the request was blocked. May be
72
+ * absent even on a refusal.
73
+ */
74
+ explanation?: string;
75
+ /**
76
+ * The canonical id of a model to retry directly. Populated only when the
77
+ * request included fallbacks and the fallback attempt could not be made
78
+ * (e.g. the fallback model was rate limited or overloaded).
79
+ */
80
+ recommendedModel?: string;
81
+ };
67
82
  /**
68
83
  * Usage breakdown by iteration when compaction is triggered.
69
84
  *
@@ -169,7 +184,7 @@ interface AnthropicMessageMetadata {
169
184
  } | null;
170
185
  }
171
186
 
172
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | (string & {});
187
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | (string & {});
173
188
  declare const anthropicLanguageModelOptions: z.ZodObject<{
174
189
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
175
190
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -236,6 +251,16 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
236
251
  us: "us";
237
252
  global: "global";
238
253
  }>>;
254
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
255
+ model: z.ZodString;
256
+ max_tokens: z.ZodOptional<z.ZodNumber>;
257
+ thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
258
+ output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
259
+ speed: z.ZodOptional<z.ZodEnum<{
260
+ fast: "fast";
261
+ standard: "standard";
262
+ }>>;
263
+ }, z.core.$strip>>>;
239
264
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
240
265
  contextManagement: z.ZodOptional<z.ZodObject<{
241
266
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -11,34 +11,21 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
11
11
  * - `compaction`: a context compaction step (billed at executor rates).
12
12
  * - `message`: an executor sampling iteration (billed at executor rates).
13
13
  * - `advisor_message`: an advisor sub-inference (billed at the advisor
14
- * model's rates; `model` carries the advisor model ID). Advisor token
15
- * usage is NOT rolled into the top-level usage totals because it bills
16
- * at a different rate; inspect this array directly for advisor billing.
14
+ * model's rates). Advisor token usage is NOT rolled into the top-level
15
+ * usage totals because it bills at a different rate; inspect this array
16
+ * directly for advisor billing.
17
+ * - `fallback_message`: a server-side fallback attempt that served the turn.
18
+ * Inspect this array for exact per-model attribution on a turn that fell
19
+ * back.
17
20
  */
18
21
  type AnthropicUsageIteration = {
19
- type: 'compaction' | 'message';
22
+ type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
20
23
  /**
21
- * Number of input tokens consumed in this iteration.
22
- */
23
- inputTokens: number;
24
- /**
25
- * Number of output tokens generated in this iteration.
26
- */
27
- outputTokens: number;
28
- /**
29
- * Number of cache-creation input tokens consumed in this iteration.
30
- */
31
- cacheCreationInputTokens?: number;
32
- /**
33
- * Number of cache-read input tokens consumed in this iteration.
34
- */
35
- cacheReadInputTokens?: number;
36
- } | {
37
- type: 'advisor_message';
38
- /**
39
- * The advisor model that produced this iteration.
24
+ * The model that produced this iteration. Populated for the per-model
25
+ * attribution cases (the fallback chain and advisor sub-inferences) and
26
+ * absent otherwise.
40
27
  */
41
- model: string;
28
+ model?: string;
42
29
  /**
43
30
  * Number of input tokens consumed in this iteration.
44
31
  */
@@ -48,15 +35,11 @@ type AnthropicUsageIteration = {
48
35
  */
49
36
  outputTokens: number;
50
37
  /**
51
- * Number of cache-creation input tokens consumed by this advisor
52
- * sub-inference. Nonzero when advisor-side caching is enabled and
53
- * the advisor writes a fresh cache entry.
38
+ * Number of cache-creation input tokens consumed in this iteration.
54
39
  */
55
40
  cacheCreationInputTokens?: number;
56
41
  /**
57
- * Number of cache-read input tokens consumed by this advisor
58
- * sub-inference. Nonzero on the second and later advisor calls
59
- * when advisor-side caching is enabled.
42
+ * Number of cache-read input tokens consumed in this iteration.
60
43
  */
61
44
  cacheReadInputTokens?: number;
62
45
  };
@@ -64,6 +47,38 @@ interface AnthropicMessageMetadata {
64
47
  usage: JSONObject;
65
48
  cacheCreationInputTokens: number | null;
66
49
  stopSequence: string | null;
50
+ /**
51
+ * Details about why the request stopped. Present only when the API returns
52
+ * a `refusal` stop reason together with a `stop_details` object (a
53
+ * classifier block or a model refusal).
54
+ *
55
+ * Branch on the finish reason (`content-filter`), not on this object: the
56
+ * API may return a refusal with no details at all, so this field can be
57
+ * absent even on a refusal and should not be relied upon being present.
58
+ */
59
+ stopDetails?: {
60
+ /**
61
+ * The kind of stop detail. `'refusal'` for classifier blocks and model
62
+ * refusals.
63
+ */
64
+ type: string;
65
+ /**
66
+ * The classifier category that triggered the block, e.g. `'cyber'` or
67
+ * `'bio'`. Absent for model refusals and other cases.
68
+ */
69
+ category?: string;
70
+ /**
71
+ * Human-readable explanation of why the request was blocked. May be
72
+ * absent even on a refusal.
73
+ */
74
+ explanation?: string;
75
+ /**
76
+ * The canonical id of a model to retry directly. Populated only when the
77
+ * request included fallbacks and the fallback attempt could not be made
78
+ * (e.g. the fallback model was rate limited or overloaded).
79
+ */
80
+ recommendedModel?: string;
81
+ };
67
82
  /**
68
83
  * Usage breakdown by iteration when compaction is triggered.
69
84
  *
@@ -169,7 +184,7 @@ interface AnthropicMessageMetadata {
169
184
  } | null;
170
185
  }
171
186
 
172
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | (string & {});
187
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | (string & {});
173
188
  declare const anthropicLanguageModelOptions: z.ZodObject<{
174
189
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
175
190
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -236,6 +251,16 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
236
251
  us: "us";
237
252
  global: "global";
238
253
  }>>;
254
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
255
+ model: z.ZodString;
256
+ max_tokens: z.ZodOptional<z.ZodNumber>;
257
+ thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
258
+ output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
259
+ speed: z.ZodOptional<z.ZodEnum<{
260
+ fast: "fast";
261
+ standard: "standard";
262
+ }>>;
263
+ }, z.core.$strip>>>;
239
264
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
240
265
  contextManagement: z.ZodOptional<z.ZodObject<{
241
266
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.81" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.82" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -60,6 +60,12 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
60
60
  // src/anthropic-messages-api.ts
61
61
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
62
62
  var import_v42 = require("zod/v4");
63
+ var anthropicStopDetailsSchema = import_v42.z.object({
64
+ type: import_v42.z.string(),
65
+ category: import_v42.z.string().nullish(),
66
+ explanation: import_v42.z.string().nullish(),
67
+ recommended_model: import_v42.z.string().nullish()
68
+ });
63
69
  var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
64
70
  () => (0, import_provider_utils2.zodSchema)(
65
71
  import_v42.z.object({
@@ -345,34 +351,37 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
345
351
  error_code: import_v42.z.string()
346
352
  })
347
353
  ])
354
+ }),
355
+ // Server-side fallback marker. Parsed so the response validates, but
356
+ // dropped from the content output (the AI SDK has no model-hop
357
+ // primitive). The hop remains observable via usage.iterations.
358
+ import_v42.z.object({
359
+ type: import_v42.z.literal("fallback")
348
360
  })
349
361
  ])
350
362
  ),
351
363
  stop_reason: import_v42.z.string().nullish(),
352
364
  stop_sequence: import_v42.z.string().nullish(),
365
+ stop_details: anthropicStopDetailsSchema.nullish(),
353
366
  usage: import_v42.z.looseObject({
354
367
  input_tokens: import_v42.z.number(),
355
368
  output_tokens: import_v42.z.number(),
356
369
  cache_creation_input_tokens: import_v42.z.number().nullish(),
357
370
  cache_read_input_tokens: import_v42.z.number().nullish(),
358
371
  iterations: import_v42.z.array(
359
- import_v42.z.union([
360
- import_v42.z.object({
361
- type: import_v42.z.union([import_v42.z.literal("compaction"), import_v42.z.literal("message")]),
362
- input_tokens: import_v42.z.number(),
363
- output_tokens: import_v42.z.number(),
364
- cache_creation_input_tokens: import_v42.z.number().nullish(),
365
- cache_read_input_tokens: import_v42.z.number().nullish()
366
- }),
367
- import_v42.z.object({
368
- type: import_v42.z.literal("advisor_message"),
369
- model: import_v42.z.string(),
370
- input_tokens: import_v42.z.number(),
371
- output_tokens: import_v42.z.number(),
372
- cache_creation_input_tokens: import_v42.z.number().nullish(),
373
- cache_read_input_tokens: import_v42.z.number().nullish()
374
- })
375
- ])
372
+ import_v42.z.object({
373
+ type: import_v42.z.union([
374
+ import_v42.z.literal("compaction"),
375
+ import_v42.z.literal("message"),
376
+ import_v42.z.literal("advisor_message"),
377
+ import_v42.z.literal("fallback_message")
378
+ ]),
379
+ model: import_v42.z.string().nullish(),
380
+ input_tokens: import_v42.z.number(),
381
+ output_tokens: import_v42.z.number(),
382
+ cache_creation_input_tokens: import_v42.z.number().nullish(),
383
+ cache_read_input_tokens: import_v42.z.number().nullish()
384
+ })
376
385
  ).nullish()
377
386
  }),
378
387
  container: import_v42.z.object({
@@ -707,6 +716,11 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
707
716
  error_code: import_v42.z.string()
708
717
  })
709
718
  ])
719
+ }),
720
+ // Server-side fallback marker; dropped from content output (see the
721
+ // response schema). The hop remains observable via usage.iterations.
722
+ import_v42.z.object({
723
+ type: import_v42.z.literal("fallback")
710
724
  })
711
725
  ])
712
726
  }),
@@ -780,6 +794,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
780
794
  delta: import_v42.z.object({
781
795
  stop_reason: import_v42.z.string().nullish(),
782
796
  stop_sequence: import_v42.z.string().nullish(),
797
+ stop_details: anthropicStopDetailsSchema.nullish(),
783
798
  container: import_v42.z.object({
784
799
  expires_at: import_v42.z.string(),
785
800
  id: import_v42.z.string(),
@@ -801,26 +816,19 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
801
816
  cache_creation_input_tokens: import_v42.z.number().nullish(),
802
817
  cache_read_input_tokens: import_v42.z.number().nullish(),
803
818
  iterations: import_v42.z.array(
804
- import_v42.z.union([
805
- import_v42.z.object({
806
- type: import_v42.z.union([
807
- import_v42.z.literal("compaction"),
808
- import_v42.z.literal("message")
809
- ]),
810
- input_tokens: import_v42.z.number(),
811
- output_tokens: import_v42.z.number(),
812
- cache_creation_input_tokens: import_v42.z.number().nullish(),
813
- cache_read_input_tokens: import_v42.z.number().nullish()
814
- }),
815
- import_v42.z.object({
816
- type: import_v42.z.literal("advisor_message"),
817
- model: import_v42.z.string(),
818
- input_tokens: import_v42.z.number(),
819
- output_tokens: import_v42.z.number(),
820
- cache_creation_input_tokens: import_v42.z.number().nullish(),
821
- cache_read_input_tokens: import_v42.z.number().nullish()
822
- })
823
- ])
819
+ import_v42.z.object({
820
+ type: import_v42.z.union([
821
+ import_v42.z.literal("compaction"),
822
+ import_v42.z.literal("message"),
823
+ import_v42.z.literal("advisor_message"),
824
+ import_v42.z.literal("fallback_message")
825
+ ]),
826
+ model: import_v42.z.string().nullish(),
827
+ input_tokens: import_v42.z.number(),
828
+ output_tokens: import_v42.z.number(),
829
+ cache_creation_input_tokens: import_v42.z.number().nullish(),
830
+ cache_read_input_tokens: import_v42.z.number().nullish()
831
+ })
824
832
  ).nullish()
825
833
  }),
826
834
  context_management: import_v42.z.object({
@@ -1024,6 +1032,31 @@ var anthropicLanguageModelOptions = import_v43.z.object({
1024
1032
  * See https://platform.claude.com/docs/en/build-with-claude/data-residency
1025
1033
  */
1026
1034
  inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
1035
+ /**
1036
+ * Server-side fallback chain.
1037
+ *
1038
+ * When the primary model's safety classifiers block a turn, the API
1039
+ * automatically retries it on the next model in the chain, server-side. A
1040
+ * `content-filter` finish reason means the entire chain refused.
1041
+ *
1042
+ * Each entry is merged into the request as a direct request to that entry's
1043
+ * model, so it must be formatted accordingly: `model` is required, and an
1044
+ * entry may additionally override `max_tokens`, `thinking`, `output_config`,
1045
+ * and `speed` for that attempt only (`speed` additionally requires the speed
1046
+ * beta). The value is passed through to the API as-is.
1047
+ *
1048
+ * The required `server-side-fallback-2026-06-01` beta is added automatically
1049
+ * when this option is set.
1050
+ */
1051
+ fallbacks: import_v43.z.array(
1052
+ import_v43.z.object({
1053
+ model: import_v43.z.string(),
1054
+ max_tokens: import_v43.z.number().int().optional(),
1055
+ thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
1056
+ output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
1057
+ speed: import_v43.z.enum(["fast", "standard"]).optional()
1058
+ })
1059
+ ).optional(),
1027
1060
  /**
1028
1061
  * A set of beta features to enable.
1029
1062
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -1778,12 +1811,15 @@ function convertAnthropicMessagesUsage({
1778
1811
  usage,
1779
1812
  rawUsage
1780
1813
  }) {
1781
- var _a, _b;
1814
+ var _a, _b, _c;
1782
1815
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1783
1816
  const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1784
1817
  let inputTokens;
1785
1818
  let outputTokens;
1786
- if (usage.iterations && usage.iterations.length > 0) {
1819
+ const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some(
1820
+ (iter) => iter.type === "fallback_message"
1821
+ );
1822
+ if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
1787
1823
  const executorIterations = usage.iterations.filter(
1788
1824
  (iter) => iter.type === "compaction" || iter.type === "message"
1789
1825
  );
@@ -3453,6 +3489,9 @@ var AnthropicMessagesLanguageModel = class {
3453
3489
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3454
3490
  inference_geo: anthropicOptions.inferenceGeo
3455
3491
  },
3492
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
3493
+ fallbacks: anthropicOptions.fallbacks
3494
+ },
3456
3495
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3457
3496
  cache_control: anthropicOptions.cacheControl
3458
3497
  },
@@ -3629,6 +3668,9 @@ var AnthropicMessagesLanguageModel = class {
3629
3668
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3630
3669
  betas.add("fast-mode-2026-02-01");
3631
3670
  }
3671
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3672
+ betas.add("server-side-fallback-2026-06-01");
3673
+ }
3632
3674
  const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3633
3675
  const {
3634
3676
  tools: anthropicTools2,
@@ -4151,6 +4193,12 @@ var AnthropicMessagesLanguageModel = class {
4151
4193
  }
4152
4194
  break;
4153
4195
  }
4196
+ // Server-side fallback marker: the AI SDK has no content primitive for
4197
+ // a model hop, so drop it. The hop is still observable via
4198
+ // usage.iterations.
4199
+ case "fallback": {
4200
+ break;
4201
+ }
4154
4202
  }
4155
4203
  }
4156
4204
  return {
@@ -4173,14 +4221,16 @@ var AnthropicMessagesLanguageModel = class {
4173
4221
  warnings,
4174
4222
  providerMetadata: (() => {
4175
4223
  var _a2, _b2, _c2, _d2, _e2;
4224
+ const stopDetails = mapAnthropicStopDetails(response.stop_details);
4176
4225
  const anthropicMetadata = {
4177
4226
  usage: response.usage,
4178
4227
  cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
4179
4228
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
4229
+ ...stopDetails != null ? { stopDetails } : {},
4180
4230
  iterations: response.usage.iterations ? response.usage.iterations.map(
4181
- (iter) => iter.type === "advisor_message" ? {
4231
+ (iter) => ({
4182
4232
  type: iter.type,
4183
- model: iter.model,
4233
+ ...iter.model != null ? { model: iter.model } : {},
4184
4234
  inputTokens: iter.input_tokens,
4185
4235
  outputTokens: iter.output_tokens,
4186
4236
  ...iter.cache_creation_input_tokens ? {
@@ -4189,17 +4239,7 @@ var AnthropicMessagesLanguageModel = class {
4189
4239
  ...iter.cache_read_input_tokens ? {
4190
4240
  cacheReadInputTokens: iter.cache_read_input_tokens
4191
4241
  } : {}
4192
- } : {
4193
- type: iter.type,
4194
- inputTokens: iter.input_tokens,
4195
- outputTokens: iter.output_tokens,
4196
- ...iter.cache_creation_input_tokens ? {
4197
- cacheCreationInputTokens: iter.cache_creation_input_tokens
4198
- } : {},
4199
- ...iter.cache_read_input_tokens ? {
4200
- cacheReadInputTokens: iter.cache_read_input_tokens
4201
- } : {}
4202
- }
4242
+ })
4203
4243
  ) : null,
4204
4244
  container: response.container ? {
4205
4245
  expiresAt: response.container.expires_at,
@@ -4275,6 +4315,7 @@ var AnthropicMessagesLanguageModel = class {
4275
4315
  let rawUsage = void 0;
4276
4316
  let cacheCreationInputTokens = null;
4277
4317
  let stopSequence = null;
4318
+ let stopDetails = void 0;
4278
4319
  let container = null;
4279
4320
  let isJsonResponseFromTool = false;
4280
4321
  let blockType = void 0;
@@ -4301,6 +4342,9 @@ var AnthropicMessagesLanguageModel = class {
4301
4342
  case "content_block_start": {
4302
4343
  const part = value.content_block;
4303
4344
  const contentBlockType = part.type;
4345
+ if (contentBlockType === "fallback") {
4346
+ return;
4347
+ }
4304
4348
  blockType = contentBlockType;
4305
4349
  switch (contentBlockType) {
4306
4350
  case "text": {
@@ -4974,6 +5018,7 @@ var AnthropicMessagesLanguageModel = class {
4974
5018
  raw: (_k = value.delta.stop_reason) != null ? _k : void 0
4975
5019
  };
4976
5020
  stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
5021
+ stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
4977
5022
  container = value.delta.container != null ? {
4978
5023
  expiresAt: value.delta.container.expires_at,
4979
5024
  id: value.delta.container.id,
@@ -4999,10 +5044,11 @@ var AnthropicMessagesLanguageModel = class {
4999
5044
  usage: rawUsage != null ? rawUsage : null,
5000
5045
  cacheCreationInputTokens,
5001
5046
  stopSequence,
5047
+ ...stopDetails != null ? { stopDetails } : {},
5002
5048
  iterations: usage.iterations ? usage.iterations.map(
5003
- (iter) => iter.type === "advisor_message" ? {
5049
+ (iter) => ({
5004
5050
  type: iter.type,
5005
- model: iter.model,
5051
+ ...iter.model != null ? { model: iter.model } : {},
5006
5052
  inputTokens: iter.input_tokens,
5007
5053
  outputTokens: iter.output_tokens,
5008
5054
  ...iter.cache_creation_input_tokens ? {
@@ -5011,17 +5057,7 @@ var AnthropicMessagesLanguageModel = class {
5011
5057
  ...iter.cache_read_input_tokens ? {
5012
5058
  cacheReadInputTokens: iter.cache_read_input_tokens
5013
5059
  } : {}
5014
- } : {
5015
- type: iter.type,
5016
- inputTokens: iter.input_tokens,
5017
- outputTokens: iter.output_tokens,
5018
- ...iter.cache_creation_input_tokens ? {
5019
- cacheCreationInputTokens: iter.cache_creation_input_tokens
5020
- } : {},
5021
- ...iter.cache_read_input_tokens ? {
5022
- cacheReadInputTokens: iter.cache_read_input_tokens
5023
- } : {}
5024
- }
5060
+ })
5025
5061
  ) : null,
5026
5062
  container,
5027
5063
  contextManagement
@@ -5085,7 +5121,7 @@ var AnthropicMessagesLanguageModel = class {
5085
5121
  }
5086
5122
  };
5087
5123
  function getModelCapabilities(modelId) {
5088
- if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
5124
+ if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) {
5089
5125
  return {
5090
5126
  maxOutputTokens: 128e3,
5091
5127
  supportsStructuredOutput: true,
@@ -5186,6 +5222,17 @@ function mapAnthropicResponseContextManagement(contextManagement) {
5186
5222
  }).filter((edit) => edit !== void 0)
5187
5223
  } : null;
5188
5224
  }
5225
+ function mapAnthropicStopDetails(stopDetails) {
5226
+ if (stopDetails == null) {
5227
+ return void 0;
5228
+ }
5229
+ return {
5230
+ type: stopDetails.type,
5231
+ ...stopDetails.category != null ? { category: stopDetails.category } : {},
5232
+ ...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
5233
+ ...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
5234
+ };
5235
+ }
5189
5236
 
5190
5237
  // src/tool/bash_20241022.ts
5191
5238
  var import_provider_utils16 = require("@ai-sdk/provider-utils");