@ai-sdk/anthropic 2.0.73 → 2.0.75
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 +13 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +96 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -11
- 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 +95 -10
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +95 -10
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
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' | (string & {});
|
|
5
|
+
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' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
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' | (string & {});
|
|
5
|
+
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' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
package/dist/internal/index.js
CHANGED
|
@@ -642,7 +642,13 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
642
642
|
thinking: import_v43.z.discriminatedUnion("type", [
|
|
643
643
|
import_v43.z.object({
|
|
644
644
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
645
|
-
type: import_v43.z.literal("adaptive")
|
|
645
|
+
type: import_v43.z.literal("adaptive"),
|
|
646
|
+
/**
|
|
647
|
+
* Controls whether thinking content is included in the response.
|
|
648
|
+
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
649
|
+
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
650
|
+
*/
|
|
651
|
+
display: import_v43.z.enum(["omitted", "summarized"]).optional()
|
|
646
652
|
}),
|
|
647
653
|
import_v43.z.object({
|
|
648
654
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
@@ -698,7 +704,19 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
698
704
|
/**
|
|
699
705
|
* @default 'high'
|
|
700
706
|
*/
|
|
701
|
-
effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
|
|
707
|
+
effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
708
|
+
/**
|
|
709
|
+
* Task budget for agentic turns. Informs the model of the total token budget
|
|
710
|
+
* available for the current task, allowing it to prioritize work and wind down
|
|
711
|
+
* gracefully as the budget is consumed.
|
|
712
|
+
*
|
|
713
|
+
* Advisory only — does not enforce a hard token limit.
|
|
714
|
+
*/
|
|
715
|
+
taskBudget: import_v43.z.object({
|
|
716
|
+
type: import_v43.z.literal("tokens"),
|
|
717
|
+
total: import_v43.z.number().int().min(2e4),
|
|
718
|
+
remaining: import_v43.z.number().int().min(0).optional()
|
|
719
|
+
}).optional(),
|
|
702
720
|
/**
|
|
703
721
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
704
722
|
* Only supported with claude-opus-4-6.
|
|
@@ -1965,7 +1983,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1965
1983
|
toolChoice,
|
|
1966
1984
|
providerOptions
|
|
1967
1985
|
}) {
|
|
1968
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1986
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1969
1987
|
const warnings = [];
|
|
1970
1988
|
if (frequencyPenalty != null) {
|
|
1971
1989
|
warnings.push({
|
|
@@ -2023,8 +2041,36 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2023
2041
|
const {
|
|
2024
2042
|
maxOutputTokens: maxOutputTokensForModel,
|
|
2025
2043
|
supportsStructuredOutput,
|
|
2044
|
+
rejectsSamplingParameters,
|
|
2026
2045
|
isKnownModel
|
|
2027
2046
|
} = getModelCapabilities(this.modelId);
|
|
2047
|
+
if (rejectsSamplingParameters) {
|
|
2048
|
+
if (temperature != null) {
|
|
2049
|
+
warnings.push({
|
|
2050
|
+
type: "unsupported-setting",
|
|
2051
|
+
setting: "temperature",
|
|
2052
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
2053
|
+
});
|
|
2054
|
+
temperature = void 0;
|
|
2055
|
+
}
|
|
2056
|
+
if (topK != null) {
|
|
2057
|
+
warnings.push({
|
|
2058
|
+
type: "unsupported-setting",
|
|
2059
|
+
setting: "topK",
|
|
2060
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
2061
|
+
});
|
|
2062
|
+
topK = void 0;
|
|
2063
|
+
}
|
|
2064
|
+
if (topP != null) {
|
|
2065
|
+
warnings.push({
|
|
2066
|
+
type: "unsupported-setting",
|
|
2067
|
+
setting: "topP",
|
|
2068
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
2069
|
+
});
|
|
2070
|
+
topP = void 0;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
2028
2074
|
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
|
|
2029
2075
|
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
2030
2076
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
@@ -2043,6 +2089,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2043
2089
|
const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
|
|
2044
2090
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
2045
2091
|
let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
|
|
2092
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.display : void 0;
|
|
2046
2093
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
2047
2094
|
const baseArgs = {
|
|
2048
2095
|
// model id:
|
|
@@ -2057,11 +2104,31 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2057
2104
|
...isThinking && {
|
|
2058
2105
|
thinking: {
|
|
2059
2106
|
type: thinkingType,
|
|
2060
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
2107
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
2108
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
2061
2109
|
}
|
|
2062
2110
|
},
|
|
2063
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
2064
|
-
output_config: {
|
|
2111
|
+
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
2112
|
+
output_config: {
|
|
2113
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
2114
|
+
effort: anthropicOptions.effort
|
|
2115
|
+
},
|
|
2116
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
|
|
2117
|
+
task_budget: {
|
|
2118
|
+
type: anthropicOptions.taskBudget.type,
|
|
2119
|
+
total: anthropicOptions.taskBudget.total,
|
|
2120
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
2121
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
},
|
|
2125
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2126
|
+
format: {
|
|
2127
|
+
type: "json_schema",
|
|
2128
|
+
schema: responseFormat.schema
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2065
2132
|
},
|
|
2066
2133
|
...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
|
|
2067
2134
|
speed: anthropicOptions.speed
|
|
@@ -2069,7 +2136,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2069
2136
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
2070
2137
|
cache_control: anthropicOptions.cacheControl
|
|
2071
2138
|
},
|
|
2072
|
-
...((
|
|
2139
|
+
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
2073
2140
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2074
2141
|
},
|
|
2075
2142
|
// structured output:
|
|
@@ -2083,7 +2150,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2083
2150
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2084
2151
|
container: {
|
|
2085
2152
|
id: anthropicOptions.container.id,
|
|
2086
|
-
skills: (
|
|
2153
|
+
skills: (_g = anthropicOptions.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2087
2154
|
type: skill.type,
|
|
2088
2155
|
skill_id: skill.skillId,
|
|
2089
2156
|
version: skill.version
|
|
@@ -2203,6 +2270,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2203
2270
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2204
2271
|
betas.add("effort-2025-11-24");
|
|
2205
2272
|
}
|
|
2273
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
2274
|
+
betas.add("task-budgets-2026-03-13");
|
|
2275
|
+
}
|
|
2206
2276
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
2207
2277
|
betas.add("fast-mode-2026-02-01");
|
|
2208
2278
|
}
|
|
@@ -2246,7 +2316,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2246
2316
|
...betas,
|
|
2247
2317
|
...toolsBetas,
|
|
2248
2318
|
...userSuppliedBetas,
|
|
2249
|
-
...(
|
|
2319
|
+
...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
|
|
2250
2320
|
]),
|
|
2251
2321
|
usesJsonResponseTool: jsonResponseTool != null
|
|
2252
2322
|
};
|
|
@@ -3210,52 +3280,67 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3210
3280
|
}
|
|
3211
3281
|
};
|
|
3212
3282
|
function getModelCapabilities(modelId) {
|
|
3213
|
-
if (modelId.includes("claude-
|
|
3283
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
3284
|
+
return {
|
|
3285
|
+
maxOutputTokens: 128e3,
|
|
3286
|
+
supportsStructuredOutput: true,
|
|
3287
|
+
rejectsSamplingParameters: true,
|
|
3288
|
+
isKnownModel: true
|
|
3289
|
+
};
|
|
3290
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
3214
3291
|
return {
|
|
3215
3292
|
maxOutputTokens: 128e3,
|
|
3216
3293
|
supportsStructuredOutput: true,
|
|
3294
|
+
rejectsSamplingParameters: false,
|
|
3217
3295
|
isKnownModel: true
|
|
3218
3296
|
};
|
|
3219
3297
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
3220
3298
|
return {
|
|
3221
3299
|
maxOutputTokens: 64e3,
|
|
3222
3300
|
supportsStructuredOutput: true,
|
|
3301
|
+
rejectsSamplingParameters: false,
|
|
3223
3302
|
isKnownModel: true
|
|
3224
3303
|
};
|
|
3225
3304
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
3226
3305
|
return {
|
|
3227
3306
|
maxOutputTokens: 32e3,
|
|
3228
3307
|
supportsStructuredOutput: true,
|
|
3308
|
+
rejectsSamplingParameters: false,
|
|
3229
3309
|
isKnownModel: true
|
|
3230
3310
|
};
|
|
3231
3311
|
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet")) {
|
|
3232
3312
|
return {
|
|
3233
3313
|
maxOutputTokens: 64e3,
|
|
3234
3314
|
supportsStructuredOutput: false,
|
|
3315
|
+
rejectsSamplingParameters: false,
|
|
3235
3316
|
isKnownModel: true
|
|
3236
3317
|
};
|
|
3237
3318
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
3238
3319
|
return {
|
|
3239
3320
|
maxOutputTokens: 32e3,
|
|
3240
3321
|
supportsStructuredOutput: false,
|
|
3322
|
+
rejectsSamplingParameters: false,
|
|
3241
3323
|
isKnownModel: true
|
|
3242
3324
|
};
|
|
3243
3325
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
3244
3326
|
return {
|
|
3245
3327
|
maxOutputTokens: 8192,
|
|
3246
3328
|
supportsStructuredOutput: false,
|
|
3329
|
+
rejectsSamplingParameters: false,
|
|
3247
3330
|
isKnownModel: true
|
|
3248
3331
|
};
|
|
3249
3332
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
3250
3333
|
return {
|
|
3251
3334
|
maxOutputTokens: 4096,
|
|
3252
3335
|
supportsStructuredOutput: false,
|
|
3336
|
+
rejectsSamplingParameters: false,
|
|
3253
3337
|
isKnownModel: true
|
|
3254
3338
|
};
|
|
3255
3339
|
} else {
|
|
3256
3340
|
return {
|
|
3257
3341
|
maxOutputTokens: 4096,
|
|
3258
3342
|
supportsStructuredOutput: false,
|
|
3343
|
+
rejectsSamplingParameters: false,
|
|
3259
3344
|
isKnownModel: false
|
|
3260
3345
|
};
|
|
3261
3346
|
}
|