@ai-sdk/anthropic 2.0.80 → 2.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 +14 -0
- package/dist/index.d.mts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.js +120 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +119 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +119 -20
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.82
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9f67efe]
|
|
8
|
+
- Updated dependencies [eea9166]
|
|
9
|
+
- @ai-sdk/provider-utils@3.0.26
|
|
10
|
+
|
|
11
|
+
## 2.0.81
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 518f0c3: feat(provider/anthropic): add support for `claude-fable-5` and the `fallbacks` API parameter
|
|
16
|
+
|
|
3
17
|
## 2.0.80
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -5,11 +5,22 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a single iteration in the usage breakdown.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* - `compaction`: a context compaction step.
|
|
10
|
+
* - `message`: an executor sampling iteration.
|
|
11
|
+
* - `advisor_message`: an advisor sub-inference.
|
|
12
|
+
* - `fallback_message`: a server-side fallback attempt that served the turn.
|
|
13
|
+
* Inspect this array for exact per-model attribution on a turn that fell
|
|
14
|
+
* back.
|
|
10
15
|
*/
|
|
11
16
|
interface AnthropicUsageIteration {
|
|
12
|
-
type: 'compaction' | 'message';
|
|
17
|
+
type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
|
|
18
|
+
/**
|
|
19
|
+
* The model that produced this iteration. Populated for the per-model
|
|
20
|
+
* attribution cases (the fallback chain and advisor sub-inferences) and
|
|
21
|
+
* absent otherwise.
|
|
22
|
+
*/
|
|
23
|
+
model?: string;
|
|
13
24
|
/**
|
|
14
25
|
* Number of input tokens consumed in this iteration.
|
|
15
26
|
*/
|
|
@@ -23,6 +34,38 @@ interface AnthropicMessageMetadata {
|
|
|
23
34
|
usage: JSONObject;
|
|
24
35
|
cacheCreationInputTokens: number | null;
|
|
25
36
|
stopSequence: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Details about why the request stopped. Present only when the API returns
|
|
39
|
+
* a `refusal` stop reason together with a `stop_details` object (a
|
|
40
|
+
* classifier block or a model refusal).
|
|
41
|
+
*
|
|
42
|
+
* Branch on the finish reason (`content-filter`), not on this object: the
|
|
43
|
+
* API may return a refusal with no details at all, so this field can be
|
|
44
|
+
* absent even on a refusal and should not be relied upon being present.
|
|
45
|
+
*/
|
|
46
|
+
stopDetails?: {
|
|
47
|
+
/**
|
|
48
|
+
* The kind of stop detail. `'refusal'` for classifier blocks and model
|
|
49
|
+
* refusals.
|
|
50
|
+
*/
|
|
51
|
+
type: string;
|
|
52
|
+
/**
|
|
53
|
+
* The classifier category that triggered the block, e.g. `'cyber'` or
|
|
54
|
+
* `'bio'`. Absent for model refusals and other cases.
|
|
55
|
+
*/
|
|
56
|
+
category?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Human-readable explanation of why the request was blocked. May be
|
|
59
|
+
* absent even on a refusal.
|
|
60
|
+
*/
|
|
61
|
+
explanation?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The canonical id of a model to retry directly. Populated only when the
|
|
64
|
+
* request included fallbacks and the fallback attempt could not be made
|
|
65
|
+
* (e.g. the fallback model was rate limited or overloaded).
|
|
66
|
+
*/
|
|
67
|
+
recommendedModel?: string;
|
|
68
|
+
};
|
|
26
69
|
/**
|
|
27
70
|
* Usage breakdown by iteration when compaction is triggered.
|
|
28
71
|
*
|
|
@@ -126,7 +169,7 @@ interface AnthropicMessageMetadata {
|
|
|
126
169
|
} | null;
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
172
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
130
173
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
131
174
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
132
175
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
@@ -182,6 +225,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
182
225
|
us: "us";
|
|
183
226
|
global: "global";
|
|
184
227
|
}>>;
|
|
228
|
+
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
229
|
+
model: z.ZodString;
|
|
230
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
232
|
+
output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
233
|
+
speed: z.ZodOptional<z.ZodEnum<{
|
|
234
|
+
fast: "fast";
|
|
235
|
+
standard: "standard";
|
|
236
|
+
}>>;
|
|
237
|
+
}, z.core.$strip>>>;
|
|
185
238
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
186
239
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
187
240
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,22 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a single iteration in the usage breakdown.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* - `compaction`: a context compaction step.
|
|
10
|
+
* - `message`: an executor sampling iteration.
|
|
11
|
+
* - `advisor_message`: an advisor sub-inference.
|
|
12
|
+
* - `fallback_message`: a server-side fallback attempt that served the turn.
|
|
13
|
+
* Inspect this array for exact per-model attribution on a turn that fell
|
|
14
|
+
* back.
|
|
10
15
|
*/
|
|
11
16
|
interface AnthropicUsageIteration {
|
|
12
|
-
type: 'compaction' | 'message';
|
|
17
|
+
type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
|
|
18
|
+
/**
|
|
19
|
+
* The model that produced this iteration. Populated for the per-model
|
|
20
|
+
* attribution cases (the fallback chain and advisor sub-inferences) and
|
|
21
|
+
* absent otherwise.
|
|
22
|
+
*/
|
|
23
|
+
model?: string;
|
|
13
24
|
/**
|
|
14
25
|
* Number of input tokens consumed in this iteration.
|
|
15
26
|
*/
|
|
@@ -23,6 +34,38 @@ interface AnthropicMessageMetadata {
|
|
|
23
34
|
usage: JSONObject;
|
|
24
35
|
cacheCreationInputTokens: number | null;
|
|
25
36
|
stopSequence: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Details about why the request stopped. Present only when the API returns
|
|
39
|
+
* a `refusal` stop reason together with a `stop_details` object (a
|
|
40
|
+
* classifier block or a model refusal).
|
|
41
|
+
*
|
|
42
|
+
* Branch on the finish reason (`content-filter`), not on this object: the
|
|
43
|
+
* API may return a refusal with no details at all, so this field can be
|
|
44
|
+
* absent even on a refusal and should not be relied upon being present.
|
|
45
|
+
*/
|
|
46
|
+
stopDetails?: {
|
|
47
|
+
/**
|
|
48
|
+
* The kind of stop detail. `'refusal'` for classifier blocks and model
|
|
49
|
+
* refusals.
|
|
50
|
+
*/
|
|
51
|
+
type: string;
|
|
52
|
+
/**
|
|
53
|
+
* The classifier category that triggered the block, e.g. `'cyber'` or
|
|
54
|
+
* `'bio'`. Absent for model refusals and other cases.
|
|
55
|
+
*/
|
|
56
|
+
category?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Human-readable explanation of why the request was blocked. May be
|
|
59
|
+
* absent even on a refusal.
|
|
60
|
+
*/
|
|
61
|
+
explanation?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The canonical id of a model to retry directly. Populated only when the
|
|
64
|
+
* request included fallbacks and the fallback attempt could not be made
|
|
65
|
+
* (e.g. the fallback model was rate limited or overloaded).
|
|
66
|
+
*/
|
|
67
|
+
recommendedModel?: string;
|
|
68
|
+
};
|
|
26
69
|
/**
|
|
27
70
|
* Usage breakdown by iteration when compaction is triggered.
|
|
28
71
|
*
|
|
@@ -126,7 +169,7 @@ interface AnthropicMessageMetadata {
|
|
|
126
169
|
} | null;
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
172
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
|
|
130
173
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
131
174
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
132
175
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
@@ -182,6 +225,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
182
225
|
us: "us";
|
|
183
226
|
global: "global";
|
|
184
227
|
}>>;
|
|
228
|
+
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
229
|
+
model: z.ZodString;
|
|
230
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
232
|
+
output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
233
|
+
speed: z.ZodOptional<z.ZodEnum<{
|
|
234
|
+
fast: "fast";
|
|
235
|
+
standard: "standard";
|
|
236
|
+
}>>;
|
|
237
|
+
}, z.core.$strip>>>;
|
|
185
238
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
186
239
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
187
240
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.82" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -59,6 +59,12 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
59
59
|
// src/anthropic-messages-api.ts
|
|
60
60
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
61
61
|
var import_v42 = require("zod/v4");
|
|
62
|
+
var anthropicStopDetailsSchema = import_v42.z.object({
|
|
63
|
+
type: import_v42.z.string(),
|
|
64
|
+
category: import_v42.z.string().nullish(),
|
|
65
|
+
explanation: import_v42.z.string().nullish(),
|
|
66
|
+
recommended_model: import_v42.z.string().nullish()
|
|
67
|
+
});
|
|
62
68
|
var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
63
69
|
() => (0, import_provider_utils2.zodSchema)(
|
|
64
70
|
import_v42.z.object({
|
|
@@ -246,11 +252,18 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
246
252
|
old_start: import_v42.z.number().nullable()
|
|
247
253
|
})
|
|
248
254
|
])
|
|
255
|
+
}),
|
|
256
|
+
// Server-side fallback marker. Parsed so the response validates, but
|
|
257
|
+
// dropped from the content output (the AI SDK has no model-hop
|
|
258
|
+
// primitive). The hop remains observable via usage.iterations.
|
|
259
|
+
import_v42.z.object({
|
|
260
|
+
type: import_v42.z.literal("fallback")
|
|
249
261
|
})
|
|
250
262
|
])
|
|
251
263
|
),
|
|
252
264
|
stop_reason: import_v42.z.string().nullish(),
|
|
253
265
|
stop_sequence: import_v42.z.string().nullish(),
|
|
266
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
254
267
|
usage: import_v42.z.looseObject({
|
|
255
268
|
input_tokens: import_v42.z.number(),
|
|
256
269
|
output_tokens: import_v42.z.number(),
|
|
@@ -258,9 +271,17 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
258
271
|
cache_read_input_tokens: import_v42.z.number().nullish(),
|
|
259
272
|
iterations: import_v42.z.array(
|
|
260
273
|
import_v42.z.object({
|
|
261
|
-
type: import_v42.z.union([
|
|
274
|
+
type: import_v42.z.union([
|
|
275
|
+
import_v42.z.literal("compaction"),
|
|
276
|
+
import_v42.z.literal("message"),
|
|
277
|
+
import_v42.z.literal("advisor_message"),
|
|
278
|
+
import_v42.z.literal("fallback_message")
|
|
279
|
+
]),
|
|
280
|
+
model: import_v42.z.string().nullish(),
|
|
262
281
|
input_tokens: import_v42.z.number(),
|
|
263
|
-
output_tokens: import_v42.z.number()
|
|
282
|
+
output_tokens: import_v42.z.number(),
|
|
283
|
+
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
284
|
+
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
264
285
|
})
|
|
265
286
|
).nullish()
|
|
266
287
|
}),
|
|
@@ -466,6 +487,11 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
466
487
|
old_start: import_v42.z.number().nullable()
|
|
467
488
|
})
|
|
468
489
|
])
|
|
490
|
+
}),
|
|
491
|
+
// Server-side fallback marker; dropped from content output (see the
|
|
492
|
+
// response schema). The hop remains observable via usage.iterations.
|
|
493
|
+
import_v42.z.object({
|
|
494
|
+
type: import_v42.z.literal("fallback")
|
|
469
495
|
})
|
|
470
496
|
])
|
|
471
497
|
}),
|
|
@@ -539,6 +565,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
539
565
|
delta: import_v42.z.object({
|
|
540
566
|
stop_reason: import_v42.z.string().nullish(),
|
|
541
567
|
stop_sequence: import_v42.z.string().nullish(),
|
|
568
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
542
569
|
container: import_v42.z.object({
|
|
543
570
|
expires_at: import_v42.z.string(),
|
|
544
571
|
id: import_v42.z.string(),
|
|
@@ -561,9 +588,17 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
561
588
|
cache_read_input_tokens: import_v42.z.number().nullish(),
|
|
562
589
|
iterations: import_v42.z.array(
|
|
563
590
|
import_v42.z.object({
|
|
564
|
-
type: import_v42.z.union([
|
|
591
|
+
type: import_v42.z.union([
|
|
592
|
+
import_v42.z.literal("compaction"),
|
|
593
|
+
import_v42.z.literal("message"),
|
|
594
|
+
import_v42.z.literal("advisor_message"),
|
|
595
|
+
import_v42.z.literal("fallback_message")
|
|
596
|
+
]),
|
|
597
|
+
model: import_v42.z.string().nullish(),
|
|
565
598
|
input_tokens: import_v42.z.number(),
|
|
566
|
-
output_tokens: import_v42.z.number()
|
|
599
|
+
output_tokens: import_v42.z.number(),
|
|
600
|
+
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
601
|
+
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
567
602
|
})
|
|
568
603
|
).nullish()
|
|
569
604
|
}),
|
|
@@ -738,6 +773,31 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
738
773
|
* See https://platform.claude.com/docs/en/build-with-claude/data-residency
|
|
739
774
|
*/
|
|
740
775
|
inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
|
|
776
|
+
/**
|
|
777
|
+
* Server-side fallback chain.
|
|
778
|
+
*
|
|
779
|
+
* When the primary model's safety classifiers block a turn, the API
|
|
780
|
+
* automatically retries it on the next model in the chain, server-side. A
|
|
781
|
+
* `content-filter` finish reason means the entire chain refused.
|
|
782
|
+
*
|
|
783
|
+
* Each entry is merged into the request as a direct request to that entry's
|
|
784
|
+
* model, so it must be formatted accordingly: `model` is required, and an
|
|
785
|
+
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
|
|
786
|
+
* and `speed` for that attempt only (`speed` additionally requires the speed
|
|
787
|
+
* beta). The value is passed through to the API as-is.
|
|
788
|
+
*
|
|
789
|
+
* The required `server-side-fallback-2026-06-01` beta is added automatically
|
|
790
|
+
* when this option is set.
|
|
791
|
+
*/
|
|
792
|
+
fallbacks: import_v43.z.array(
|
|
793
|
+
import_v43.z.object({
|
|
794
|
+
model: import_v43.z.string(),
|
|
795
|
+
max_tokens: import_v43.z.number().int().optional(),
|
|
796
|
+
thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
797
|
+
output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
798
|
+
speed: import_v43.z.enum(["fast", "standard"]).optional()
|
|
799
|
+
})
|
|
800
|
+
).optional(),
|
|
741
801
|
/**
|
|
742
802
|
* Context management configuration for automatic context window management.
|
|
743
803
|
* Enables features like automatic compaction and clearing of tool uses/thinking blocks.
|
|
@@ -2298,6 +2358,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2298
2358
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
2299
2359
|
inference_geo: anthropicOptions.inferenceGeo
|
|
2300
2360
|
},
|
|
2361
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
2362
|
+
fallbacks: anthropicOptions.fallbacks
|
|
2363
|
+
},
|
|
2301
2364
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
2302
2365
|
cache_control: anthropicOptions.cacheControl
|
|
2303
2366
|
},
|
|
@@ -2440,6 +2503,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2440
2503
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
2441
2504
|
betas.add("fast-mode-2026-02-01");
|
|
2442
2505
|
}
|
|
2506
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
2507
|
+
betas.add("server-side-fallback-2026-06-01");
|
|
2508
|
+
}
|
|
2443
2509
|
if (useStructuredOutput) {
|
|
2444
2510
|
betas.add("structured-outputs-2025-11-13");
|
|
2445
2511
|
}
|
|
@@ -2539,7 +2605,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2539
2605
|
});
|
|
2540
2606
|
}
|
|
2541
2607
|
async doGenerate(options) {
|
|
2542
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2608
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2543
2609
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2544
2610
|
...options,
|
|
2545
2611
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2779,11 +2845,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2779
2845
|
});
|
|
2780
2846
|
break;
|
|
2781
2847
|
}
|
|
2848
|
+
// Server-side fallback marker: the AI SDK has no content primitive for
|
|
2849
|
+
// a model hop, so drop it. The hop is still observable via
|
|
2850
|
+
// usage.iterations.
|
|
2851
|
+
case "fallback": {
|
|
2852
|
+
break;
|
|
2853
|
+
}
|
|
2782
2854
|
}
|
|
2783
2855
|
}
|
|
2784
2856
|
let inputTokens;
|
|
2785
2857
|
let outputTokens;
|
|
2786
|
-
|
|
2858
|
+
const servedByFallback = (_b = response.usage.iterations) == null ? void 0 : _b.some(
|
|
2859
|
+
(iter) => iter.type === "fallback_message"
|
|
2860
|
+
);
|
|
2861
|
+
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
2787
2862
|
const totals = response.usage.iterations.reduce(
|
|
2788
2863
|
(acc, iter) => ({
|
|
2789
2864
|
input: acc.input + iter.input_tokens,
|
|
@@ -2797,6 +2872,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2797
2872
|
inputTokens = response.usage.input_tokens;
|
|
2798
2873
|
outputTokens = response.usage.output_tokens;
|
|
2799
2874
|
}
|
|
2875
|
+
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
2800
2876
|
return {
|
|
2801
2877
|
content,
|
|
2802
2878
|
finishReason: mapAnthropicStopReason({
|
|
@@ -2807,12 +2883,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2807
2883
|
inputTokens,
|
|
2808
2884
|
outputTokens,
|
|
2809
2885
|
totalTokens: inputTokens + outputTokens,
|
|
2810
|
-
cachedInputTokens: (
|
|
2886
|
+
cachedInputTokens: (_c = response.usage.cache_read_input_tokens) != null ? _c : void 0
|
|
2811
2887
|
},
|
|
2812
2888
|
request: { body: args },
|
|
2813
2889
|
response: {
|
|
2814
|
-
id: (
|
|
2815
|
-
modelId: (
|
|
2890
|
+
id: (_d = response.id) != null ? _d : void 0,
|
|
2891
|
+
modelId: (_e = response.model) != null ? _e : void 0,
|
|
2816
2892
|
headers: responseHeaders,
|
|
2817
2893
|
body: rawResponse
|
|
2818
2894
|
},
|
|
@@ -2820,21 +2896,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2820
2896
|
providerMetadata: {
|
|
2821
2897
|
anthropic: {
|
|
2822
2898
|
usage: response.usage,
|
|
2823
|
-
cacheCreationInputTokens: (
|
|
2824
|
-
stopSequence: (
|
|
2899
|
+
cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
|
|
2900
|
+
stopSequence: (_g = response.stop_sequence) != null ? _g : null,
|
|
2901
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
2825
2902
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2826
2903
|
type: iter.type,
|
|
2904
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
2827
2905
|
inputTokens: iter.input_tokens,
|
|
2828
2906
|
outputTokens: iter.output_tokens
|
|
2829
2907
|
})) : null,
|
|
2830
2908
|
container: response.container ? {
|
|
2831
2909
|
expiresAt: response.container.expires_at,
|
|
2832
2910
|
id: response.container.id,
|
|
2833
|
-
skills: (
|
|
2911
|
+
skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
|
|
2834
2912
|
type: skill.type,
|
|
2835
2913
|
skillId: skill.skill_id,
|
|
2836
2914
|
version: skill.version
|
|
2837
|
-
}))) != null ?
|
|
2915
|
+
}))) != null ? _i : null
|
|
2838
2916
|
} : null,
|
|
2839
2917
|
contextManagement: response.context_management ? {
|
|
2840
2918
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -2895,6 +2973,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2895
2973
|
let rawUsage = void 0;
|
|
2896
2974
|
let cacheCreationInputTokens = null;
|
|
2897
2975
|
let stopSequence = null;
|
|
2976
|
+
let stopDetails = void 0;
|
|
2898
2977
|
let container = null;
|
|
2899
2978
|
let iterations = null;
|
|
2900
2979
|
let contextManagement = null;
|
|
@@ -2906,7 +2985,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2906
2985
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2907
2986
|
},
|
|
2908
2987
|
transform(chunk, controller) {
|
|
2909
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2988
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2910
2989
|
if (options.includeRawChunks) {
|
|
2911
2990
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2912
2991
|
}
|
|
@@ -2921,6 +3000,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2921
3000
|
}
|
|
2922
3001
|
case "content_block_start": {
|
|
2923
3002
|
const contentBlockType = value.content_block.type;
|
|
3003
|
+
if (contentBlockType === "fallback") {
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
2924
3006
|
blockType = contentBlockType;
|
|
2925
3007
|
switch (contentBlockType) {
|
|
2926
3008
|
case "text": {
|
|
@@ -3313,7 +3395,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3313
3395
|
if (value.usage.iterations != null) {
|
|
3314
3396
|
iterations = value.usage.iterations;
|
|
3315
3397
|
}
|
|
3316
|
-
|
|
3398
|
+
const servedByFallback = (_f = value.usage.iterations) == null ? void 0 : _f.some(
|
|
3399
|
+
(iter) => iter.type === "fallback_message"
|
|
3400
|
+
);
|
|
3401
|
+
if (value.usage.iterations && value.usage.iterations.length > 0 && !servedByFallback) {
|
|
3317
3402
|
const totals = value.usage.iterations.reduce(
|
|
3318
3403
|
(acc, iter) => ({
|
|
3319
3404
|
input: acc.input + iter.input_tokens,
|
|
@@ -3329,20 +3414,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3329
3414
|
}
|
|
3330
3415
|
usage.outputTokens = value.usage.output_tokens;
|
|
3331
3416
|
}
|
|
3332
|
-
usage.totalTokens = ((
|
|
3417
|
+
usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
|
|
3333
3418
|
finishReason = mapAnthropicStopReason({
|
|
3334
3419
|
finishReason: value.delta.stop_reason,
|
|
3335
3420
|
isJsonResponseFromTool: usesJsonResponseTool
|
|
3336
3421
|
});
|
|
3337
|
-
|
|
3422
|
+
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
3423
|
+
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
3338
3424
|
container = value.delta.container != null ? {
|
|
3339
3425
|
expiresAt: value.delta.container.expires_at,
|
|
3340
3426
|
id: value.delta.container.id,
|
|
3341
|
-
skills: (
|
|
3427
|
+
skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3342
3428
|
type: skill.type,
|
|
3343
3429
|
skillId: skill.skill_id,
|
|
3344
3430
|
version: skill.version
|
|
3345
|
-
}))) != null ?
|
|
3431
|
+
}))) != null ? _k : null
|
|
3346
3432
|
} : null;
|
|
3347
3433
|
if (value.context_management != null) {
|
|
3348
3434
|
contextManagement = {
|
|
@@ -3387,8 +3473,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3387
3473
|
usage: rawUsage != null ? rawUsage : null,
|
|
3388
3474
|
cacheCreationInputTokens,
|
|
3389
3475
|
stopSequence,
|
|
3476
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
3390
3477
|
iterations: iterations ? iterations.map((iter) => ({
|
|
3391
3478
|
type: iter.type,
|
|
3479
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
3392
3480
|
inputTokens: iter.input_tokens,
|
|
3393
3481
|
outputTokens: iter.output_tokens
|
|
3394
3482
|
})) : null,
|
|
@@ -3444,7 +3532,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3444
3532
|
}
|
|
3445
3533
|
};
|
|
3446
3534
|
function getModelCapabilities(modelId) {
|
|
3447
|
-
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
|
|
3535
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) {
|
|
3448
3536
|
return {
|
|
3449
3537
|
maxOutputTokens: 128e3,
|
|
3450
3538
|
supportsStructuredOutput: true,
|
|
@@ -3509,6 +3597,17 @@ function getModelCapabilities(modelId) {
|
|
|
3509
3597
|
};
|
|
3510
3598
|
}
|
|
3511
3599
|
}
|
|
3600
|
+
function mapAnthropicStopDetails(stopDetails) {
|
|
3601
|
+
if (stopDetails == null) {
|
|
3602
|
+
return void 0;
|
|
3603
|
+
}
|
|
3604
|
+
return {
|
|
3605
|
+
type: stopDetails.type,
|
|
3606
|
+
...stopDetails.category != null ? { category: stopDetails.category } : {},
|
|
3607
|
+
...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
|
|
3608
|
+
...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
|
|
3609
|
+
};
|
|
3610
|
+
}
|
|
3512
3611
|
|
|
3513
3612
|
// src/tool/bash_20241022.ts
|
|
3514
3613
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|