@ai-sdk/anthropic 3.0.80 → 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 +12 -0
- package/dist/index.d.mts +57 -32
- package/dist/index.d.ts +57 -32
- package/dist/index.js +123 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +123 -75
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +122 -74
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +122 -74
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +63 -4
- package/package.json +1 -1
- package/src/anthropic-message-metadata.ts +67 -54
- package/src/anthropic-messages-api.ts +57 -38
- package/src/anthropic-messages-language-model.ts +93 -73
- package/src/anthropic-messages-options.ts +30 -0
- package/src/anthropic-tools.ts +1 -1
- package/src/convert-anthropic-messages-usage.ts +28 -20
- package/src/convert-to-anthropic-messages-prompt.ts +9 -9
- package/src/tool/advisor_20260301.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
9
|
+
## 3.0.81
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4084fcd: feat(provider/anthropic): add support for `claude-opus-4-8`
|
|
14
|
+
|
|
3
15
|
## 3.0.80
|
|
4
16
|
|
|
5
17
|
### 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
|
|
15
|
-
* usage
|
|
16
|
-
*
|
|
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
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
|
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
|
|
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' | (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<{
|
|
@@ -305,7 +330,7 @@ declare const anthropicTools: {
|
|
|
305
330
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
306
331
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
307
332
|
*
|
|
308
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
333
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
309
334
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
310
335
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
311
336
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
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
|
|
15
|
-
* usage
|
|
16
|
-
*
|
|
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
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
|
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
|
|
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' | (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<{
|
|
@@ -305,7 +330,7 @@ declare const anthropicTools: {
|
|
|
305
330
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
306
331
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
307
332
|
*
|
|
308
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
333
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
309
334
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
310
335
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
311
336
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
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.
|
|
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.
|
|
360
|
-
import_v42.z.
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
import_v42.z.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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.
|
|
805
|
-
import_v42.z.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
import_v42.z.
|
|
816
|
-
|
|
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
|
-
|
|
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
|
);
|
|
@@ -2210,19 +2246,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2210
2246
|
const type = block.type;
|
|
2211
2247
|
switch (type) {
|
|
2212
2248
|
case "system": {
|
|
2213
|
-
|
|
2214
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
2215
|
-
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
2249
|
+
const content = block.messages.map(({ content: content2, providerOptions }) => ({
|
|
2219
2250
|
type: "text",
|
|
2220
|
-
text:
|
|
2251
|
+
text: content2,
|
|
2221
2252
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
2222
2253
|
type: "system message",
|
|
2223
2254
|
canCache: true
|
|
2224
2255
|
})
|
|
2225
2256
|
}));
|
|
2257
|
+
if (system == null) {
|
|
2258
|
+
system = content;
|
|
2259
|
+
} else {
|
|
2260
|
+
messages.push({ role: "system", content });
|
|
2261
|
+
betas.add("mid-conversation-system-2026-04-07");
|
|
2262
|
+
}
|
|
2226
2263
|
break;
|
|
2227
2264
|
}
|
|
2228
2265
|
case "user": {
|
|
@@ -3452,6 +3489,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3452
3489
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3453
3490
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3454
3491
|
},
|
|
3492
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3493
|
+
fallbacks: anthropicOptions.fallbacks
|
|
3494
|
+
},
|
|
3455
3495
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3456
3496
|
cache_control: anthropicOptions.cacheControl
|
|
3457
3497
|
},
|
|
@@ -3628,6 +3668,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3628
3668
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3629
3669
|
betas.add("fast-mode-2026-02-01");
|
|
3630
3670
|
}
|
|
3671
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3672
|
+
betas.add("server-side-fallback-2026-06-01");
|
|
3673
|
+
}
|
|
3631
3674
|
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
3632
3675
|
const {
|
|
3633
3676
|
tools: anthropicTools2,
|
|
@@ -4150,6 +4193,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4150
4193
|
}
|
|
4151
4194
|
break;
|
|
4152
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
|
+
}
|
|
4153
4202
|
}
|
|
4154
4203
|
}
|
|
4155
4204
|
return {
|
|
@@ -4172,14 +4221,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4172
4221
|
warnings,
|
|
4173
4222
|
providerMetadata: (() => {
|
|
4174
4223
|
var _a2, _b2, _c2, _d2, _e2;
|
|
4224
|
+
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
4175
4225
|
const anthropicMetadata = {
|
|
4176
4226
|
usage: response.usage,
|
|
4177
4227
|
cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
|
|
4178
4228
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4229
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
4179
4230
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4180
|
-
(iter) =>
|
|
4231
|
+
(iter) => ({
|
|
4181
4232
|
type: iter.type,
|
|
4182
|
-
model: iter.model,
|
|
4233
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
4183
4234
|
inputTokens: iter.input_tokens,
|
|
4184
4235
|
outputTokens: iter.output_tokens,
|
|
4185
4236
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -4188,17 +4239,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4188
4239
|
...iter.cache_read_input_tokens ? {
|
|
4189
4240
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4190
4241
|
} : {}
|
|
4191
|
-
}
|
|
4192
|
-
type: iter.type,
|
|
4193
|
-
inputTokens: iter.input_tokens,
|
|
4194
|
-
outputTokens: iter.output_tokens,
|
|
4195
|
-
...iter.cache_creation_input_tokens ? {
|
|
4196
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
4197
|
-
} : {},
|
|
4198
|
-
...iter.cache_read_input_tokens ? {
|
|
4199
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4200
|
-
} : {}
|
|
4201
|
-
}
|
|
4242
|
+
})
|
|
4202
4243
|
) : null,
|
|
4203
4244
|
container: response.container ? {
|
|
4204
4245
|
expiresAt: response.container.expires_at,
|
|
@@ -4274,6 +4315,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4274
4315
|
let rawUsage = void 0;
|
|
4275
4316
|
let cacheCreationInputTokens = null;
|
|
4276
4317
|
let stopSequence = null;
|
|
4318
|
+
let stopDetails = void 0;
|
|
4277
4319
|
let container = null;
|
|
4278
4320
|
let isJsonResponseFromTool = false;
|
|
4279
4321
|
let blockType = void 0;
|
|
@@ -4300,6 +4342,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4300
4342
|
case "content_block_start": {
|
|
4301
4343
|
const part = value.content_block;
|
|
4302
4344
|
const contentBlockType = part.type;
|
|
4345
|
+
if (contentBlockType === "fallback") {
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
4303
4348
|
blockType = contentBlockType;
|
|
4304
4349
|
switch (contentBlockType) {
|
|
4305
4350
|
case "text": {
|
|
@@ -4973,6 +5018,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4973
5018
|
raw: (_k = value.delta.stop_reason) != null ? _k : void 0
|
|
4974
5019
|
};
|
|
4975
5020
|
stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
|
|
5021
|
+
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
4976
5022
|
container = value.delta.container != null ? {
|
|
4977
5023
|
expiresAt: value.delta.container.expires_at,
|
|
4978
5024
|
id: value.delta.container.id,
|
|
@@ -4998,20 +5044,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4998
5044
|
usage: rawUsage != null ? rawUsage : null,
|
|
4999
5045
|
cacheCreationInputTokens,
|
|
5000
5046
|
stopSequence,
|
|
5047
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
5001
5048
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5002
|
-
(iter) =>
|
|
5003
|
-
type: iter.type,
|
|
5004
|
-
model: iter.model,
|
|
5005
|
-
inputTokens: iter.input_tokens,
|
|
5006
|
-
outputTokens: iter.output_tokens,
|
|
5007
|
-
...iter.cache_creation_input_tokens ? {
|
|
5008
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
5009
|
-
} : {},
|
|
5010
|
-
...iter.cache_read_input_tokens ? {
|
|
5011
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5012
|
-
} : {}
|
|
5013
|
-
} : {
|
|
5049
|
+
(iter) => ({
|
|
5014
5050
|
type: iter.type,
|
|
5051
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
5015
5052
|
inputTokens: iter.input_tokens,
|
|
5016
5053
|
outputTokens: iter.output_tokens,
|
|
5017
5054
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -5020,7 +5057,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5020
5057
|
...iter.cache_read_input_tokens ? {
|
|
5021
5058
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5022
5059
|
} : {}
|
|
5023
|
-
}
|
|
5060
|
+
})
|
|
5024
5061
|
) : null,
|
|
5025
5062
|
container,
|
|
5026
5063
|
contextManagement
|
|
@@ -5084,7 +5121,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5084
5121
|
}
|
|
5085
5122
|
};
|
|
5086
5123
|
function getModelCapabilities(modelId) {
|
|
5087
|
-
if (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")) {
|
|
5088
5125
|
return {
|
|
5089
5126
|
maxOutputTokens: 128e3,
|
|
5090
5127
|
supportsStructuredOutput: true,
|
|
@@ -5185,6 +5222,17 @@ function mapAnthropicResponseContextManagement(contextManagement) {
|
|
|
5185
5222
|
}).filter((edit) => edit !== void 0)
|
|
5186
5223
|
} : null;
|
|
5187
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
|
+
}
|
|
5188
5236
|
|
|
5189
5237
|
// src/tool/bash_20241022.ts
|
|
5190
5238
|
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
@@ -5502,7 +5550,7 @@ var anthropicTools = {
|
|
|
5502
5550
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
5503
5551
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
5504
5552
|
*
|
|
5505
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
5553
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
5506
5554
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
5507
5555
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
5508
5556
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|