@ai-sdk/anthropic 4.0.96 → 4.0.97
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 +26 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -24
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +12 -3
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +143 -24
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +87 -0
- package/package.json +3 -3
- package/src/anthropic-api.ts +5 -0
- package/src/anthropic-batch.ts +2 -0
- package/src/anthropic-language-model-options.ts +11 -2
- package/src/anthropic-language-model.ts +37 -3
- package/src/anthropic-message-metadata.ts +3 -0
- package/src/anthropic-model-catalog.ts +2 -0
- package/src/anthropic-prepare-tools.ts +3 -1
- package/src/anthropic-provider.ts +1 -1
- package/src/convert-to-anthropic-prompt.ts +5 -1
- package/src/files/anthropic-files-api.ts +26 -0
- package/src/files/anthropic-files.ts +217 -0
- package/src/internal/index.ts +1 -1
- package/src/anthropic-files.ts +0 -104
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { FilesV4, FilesV4DeleteFileCallOptions, FilesV4DeleteFileResult, FilesV4DownloadFileCallOptions, FilesV4DownloadFileResult, FilesV4GetFileMetadataCallOptions, FilesV4GetFileMetadataResult, FilesV4UploadFileCallOptions, FilesV4UploadFileResult, JSONObject, JSONSchema7, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FilePart, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SharedV4ProviderMetadata, SharedV4Warning, SkillsV4 } from "@ai-sdk/provider";
|
|
1
2
|
import { Experimental_SandboxSession, FetchFunction, InferSchema, ProviderDefinedTool, Resolvable, Tool, ToolExecuteFunction, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@ai-sdk/provider-utils";
|
|
2
3
|
import { z } from "zod/v4";
|
|
3
|
-
|
|
4
|
-
//#region src/anthropic-files.d.ts
|
|
4
|
+
//#region src/files/anthropic-files.d.ts
|
|
5
5
|
interface AnthropicFilesConfig {
|
|
6
6
|
provider: string;
|
|
7
7
|
baseURL: string;
|
|
@@ -13,7 +13,13 @@ export declare class AnthropicFiles implements FilesV4 {
|
|
|
13
13
|
readonly specificationVersion = "v4";
|
|
14
14
|
get provider(): string;
|
|
15
15
|
constructor(config: AnthropicFilesConfig);
|
|
16
|
+
private getFileId;
|
|
17
|
+
private getHeaders;
|
|
16
18
|
uploadFile({ data, mediaType, filename, abortSignal, headers }: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult>;
|
|
19
|
+
deleteFile({ file, abortSignal, headers }: FilesV4DeleteFileCallOptions): Promise<FilesV4DeleteFileResult>;
|
|
20
|
+
getFileMetadata({ file, abortSignal, headers }: FilesV4GetFileMetadataCallOptions): Promise<FilesV4GetFileMetadataResult>;
|
|
21
|
+
private toFileMetadata;
|
|
22
|
+
downloadFile({ file, abortSignal, headers }: FilesV4DownloadFileCallOptions): Promise<FilesV4DownloadFileResult>;
|
|
17
23
|
}
|
|
18
24
|
//#endregion
|
|
19
25
|
//#region src/anthropic-api.d.ts
|
|
@@ -757,6 +763,7 @@ declare const anthropicResponseSchema: import("@ai-sdk/provider-utils").LazySche
|
|
|
757
763
|
[x: string]: unknown;
|
|
758
764
|
input_tokens: number;
|
|
759
765
|
output_tokens: number;
|
|
766
|
+
service_tier?: string | null | undefined;
|
|
760
767
|
output_tokens_details?: {
|
|
761
768
|
thinking_tokens?: number | null | undefined;
|
|
762
769
|
} | null | undefined;
|
|
@@ -775,6 +782,7 @@ declare const anthropicResponseSchema: import("@ai-sdk/provider-utils").LazySche
|
|
|
775
782
|
model?: string | null | undefined;
|
|
776
783
|
stop_reason?: string | null | undefined;
|
|
777
784
|
stop_sequence?: string | null | undefined;
|
|
785
|
+
service_tier?: string | null | undefined;
|
|
778
786
|
stop_details?: {
|
|
779
787
|
type: string;
|
|
780
788
|
category?: string | null | undefined;
|
|
@@ -990,7 +998,7 @@ export declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
990
998
|
speed?: "fast" | "standard" | undefined;
|
|
991
999
|
}[] | undefined;
|
|
992
1000
|
inference_geo?: "us" | "global" | undefined;
|
|
993
|
-
service_tier?: "auto" | "standard_only" | undefined;
|
|
1001
|
+
service_tier?: "auto" | "standard" | "standard_only" | "priority" | undefined;
|
|
994
1002
|
speed?: "fast" | "standard" | undefined;
|
|
995
1003
|
output_config?: {
|
|
996
1004
|
format?: {
|
|
@@ -1022,6 +1030,7 @@ export declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1022
1030
|
warnings: SharedV4Warning[];
|
|
1023
1031
|
betas: Set<string>;
|
|
1024
1032
|
usesJsonResponseTool: boolean;
|
|
1033
|
+
includePings: boolean;
|
|
1025
1034
|
toolNameMapping: import("@ai-sdk/provider-utils").ToolNameMapping;
|
|
1026
1035
|
providerOptionsName: string;
|
|
1027
1036
|
usedCustomProviderKey: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/get-cache-control.ts","../../src/convert-to-anthropic-prompt.ts","../../src/anthropic-model-catalog.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/anthropic-prepare-tools.ts","../../src/sanitize-json-schema.ts","../../src/supports-native-structured-output-schema.ts","../../src/skills/anthropic-skills.ts"],"mappings":";;;;UAiCU;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,0BAA0B;mBAOR;WANpB;MAEL;EAIyB,YAAA,QAAQ;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/files/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/get-cache-control.ts","../../src/convert-to-anthropic-prompt.ts","../../src/anthropic-model-catalog.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/anthropic-prepare-tools.ts","../../src/sanitize-json-schema.ts","../../src/supports-native-structured-output-schema.ts","../../src/skills/anthropic-skills.ts"],"mappings":";;;;UAiCU;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,0BAA0B;mBAOR;WANpB;MAEL;EAIyB,YAAA,QAAQ;UAE7B;UAWM;EAUR,aACJ,MACA,WACA,UACA,aACA,WACC,+BAA+B,QAAQ;EAwCpC,aACJ,MACA,aACA,WACC,+BAA+B,QAAQ;EAmBpC,kBACJ,MACA,aACA,WACC,oCAAoC,QAAQ;UA4BvC;EAqBF,eACJ,MACA,aACA,WACC,iCAAiC,QAAQ;;;;KCvLlC,mBACR,uBACA,4BACA;KAEQ;EACV;EACA;;UAGe;EACf;EACA,SAAS,MAAM,uBAAuB;EACtC;EACA;IACE;;;;;;;;;;UAWa;EACf;EACA;IAAQ;IAAwB;;EAChC;;UAGe;EACf;EACA,SAAS,MACL,uBACA,wBACA,wBACA,2BACA,kCACA;;UAIW;EACf;EACA,SAAS,MACL,uBACA,2BACA,mCACA,2BACA,2BACA,gCACA,0CACA,qCACA,sCACA,uCACA,8CACA,oDACA,oCACA,6BACA,gCACA;;cAIO,sCAA8B,EAAA;;;;;;;;GAKvC,EAAA,KAAA;KAKQ,2BAA2B,YACrC,kBAAkB;EAElB;;UAGe;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf;EACA;EACA,YAAY;EACZ,eAAe;;UAGA;EACf;EACA;EACA;EAGA;;UAGe;EACf;EACA;EAGA;;KAGG;EAEC;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;;UAGW;EACf;EACA,QAAQ;EACR,eAAe;;;UAIA;EACf;EACA,QAAQ;EACR,eAAe;;UAGA;EACf;EACA,QAAQ;EACR;EACA;EACA;IAAc;;EACd,eAAe;;UAGA;EACf;EACA;EACA;;;;;;KAOU;EAEN;EACA;;EAGA;EACA;;EAGA;;UAGW;EACf;EACA;EACA;EACA;;;;;EAKA,SAAS;;;;;EAKT;EACA,eAAe;;UAGA;EACf;EACA;EACA;EAaA;EACA,SAAS;EACT,eAAe;;KAKZ,6BAA6B,KAChC;EAGA;;KAGG,8BAA8B,KACjC;EAGA;;KAGG,iCAAiC,KACpC;EAGA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;;;EAIA;EACA,kBAEI,MACI,6BACA,8BACA,iCACA;EAER;EACA,eAAe;;UAGA;EACf;EACA;EACA,SACI;IACE;IACA;IACA;IACA;IACA;;IAGA;IACA;;EAEN,SAAS;EACT,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA,iBAAiB;MACf;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;;IAGA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA;MACE;MACA;;;IAIF;IACA;;EAEN,eAA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cAAc;EACd,OAAO;;;;;;;;;;;wBC3BO,mBAAmB,QAAQ,cAAc;;;;;;;;;;;;wBCDzC,qCACd,QAAQ;;;UCtBA;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,2BAA2B;mBAOT;WANpB;MAEL;EAIyB,YAAA,QAAQ;UAEvB;UAMA;EA0BR,YACJ,QAAQ,WAAW,8BAClB,QAAQ,QAAQ,WAAW"}
|
package/dist/internal/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
-
import { z } from "zod/v4";
|
|
3
1
|
import { APICallError, InvalidArgumentError, InvalidResponseDataError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
4
|
//#region src/anthropic-error.ts
|
|
5
5
|
const anthropicErrorDataSchema = lazySchema(() => zodSchema(z.object({
|
|
6
6
|
type: z.literal("error"),
|
|
@@ -14,16 +14,23 @@ const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
14
14
|
errorToMessage: (data) => data.error.message
|
|
15
15
|
});
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region src/anthropic-files.ts
|
|
17
|
+
//#region src/files/anthropic-files-api.ts
|
|
18
18
|
const anthropicUploadFileResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
19
19
|
id: z.string(),
|
|
20
|
-
type: z.literal("file"),
|
|
21
|
-
filename: z.string(),
|
|
22
|
-
mime_type: z.string(),
|
|
23
|
-
size_bytes: z.number(),
|
|
24
|
-
created_at: z.string(),
|
|
25
|
-
downloadable: z.boolean().nullish()
|
|
20
|
+
type: z.literal("file").nullish(),
|
|
21
|
+
filename: z.string().nullish(),
|
|
22
|
+
mime_type: z.string().nullish(),
|
|
23
|
+
size_bytes: z.number().nullish(),
|
|
24
|
+
created_at: z.string().nullish(),
|
|
25
|
+
downloadable: z.boolean().nullish(),
|
|
26
|
+
expires_at: z.string().nullish()
|
|
26
27
|
})));
|
|
28
|
+
const anthropicDeleteFileResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
29
|
+
type: z.literal("file_deleted").nullish(),
|
|
30
|
+
id: z.string()
|
|
31
|
+
})));
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/files/anthropic-files.ts
|
|
27
34
|
var AnthropicFiles = class {
|
|
28
35
|
get provider() {
|
|
29
36
|
return this.config.provider;
|
|
@@ -32,6 +39,17 @@ var AnthropicFiles = class {
|
|
|
32
39
|
this.config = config;
|
|
33
40
|
this.specificationVersion = "v4";
|
|
34
41
|
}
|
|
42
|
+
getFileId(file) {
|
|
43
|
+
const fileId = file.anthropic;
|
|
44
|
+
if (fileId == null || fileId.trim() === "") throw new InvalidArgumentError({
|
|
45
|
+
argument: "file",
|
|
46
|
+
message: "file reference is missing an 'anthropic' file id."
|
|
47
|
+
});
|
|
48
|
+
return fileId;
|
|
49
|
+
}
|
|
50
|
+
async getHeaders(headers) {
|
|
51
|
+
return combineHeaders(await resolve(this.config.headers), { "anthropic-beta": "files-api-2025-04-14" }, headers);
|
|
52
|
+
}
|
|
35
53
|
async uploadFile({ data, mediaType, filename, abortSignal, headers }) {
|
|
36
54
|
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
37
55
|
const blob = new Blob([fileBytes], { type: mediaType });
|
|
@@ -40,7 +58,7 @@ var AnthropicFiles = class {
|
|
|
40
58
|
else formData.append("file", blob);
|
|
41
59
|
const { value: response } = await postFormDataToApi({
|
|
42
60
|
url: `${this.config.baseURL}/files`,
|
|
43
|
-
headers:
|
|
61
|
+
headers: await this.getHeaders(headers),
|
|
44
62
|
formData,
|
|
45
63
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
46
64
|
successfulResponseHandler: createJsonResponseHandler(anthropicUploadFileResponseSchema),
|
|
@@ -52,13 +70,76 @@ var AnthropicFiles = class {
|
|
|
52
70
|
providerReference: { anthropic: response.id },
|
|
53
71
|
mediaType: response.mime_type ?? mediaType,
|
|
54
72
|
filename: response.filename ?? filename,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
byteSize: response.size_bytes ?? void 0,
|
|
74
|
+
createdAt: response.created_at != null ? new Date(response.created_at) : void 0,
|
|
75
|
+
expiresAt: response.expires_at != null ? new Date(response.expires_at) : void 0,
|
|
76
|
+
providerMetadata: { anthropic: this.toFileMetadata(response) }
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async deleteFile({ file, abortSignal, headers }) {
|
|
80
|
+
const fileId = this.getFileId(file);
|
|
81
|
+
const { value: response } = await deleteFromApi({
|
|
82
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
83
|
+
headers: await this.getHeaders(headers),
|
|
84
|
+
abortSignal,
|
|
85
|
+
fetch: this.config.fetch,
|
|
86
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
87
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicDeleteFileResponseSchema)
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
warnings: [],
|
|
91
|
+
providerReference: { anthropic: response.id },
|
|
92
|
+
deleted: true
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async getFileMetadata({ file, abortSignal, headers }) {
|
|
96
|
+
const fileId = this.getFileId(file);
|
|
97
|
+
const { value: response } = await getFromApi({
|
|
98
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
99
|
+
headers: await this.getHeaders(headers),
|
|
100
|
+
abortSignal,
|
|
101
|
+
fetch: this.config.fetch,
|
|
102
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
103
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicUploadFileResponseSchema),
|
|
104
|
+
validateUrl: false
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
warnings: [],
|
|
108
|
+
providerReference: { anthropic: response.id },
|
|
109
|
+
filename: response.filename ?? void 0,
|
|
110
|
+
mediaType: response.mime_type ?? void 0,
|
|
111
|
+
byteSize: response.size_bytes ?? void 0,
|
|
112
|
+
createdAt: response.created_at != null ? new Date(response.created_at) : void 0,
|
|
113
|
+
expiresAt: response.expires_at != null ? new Date(response.expires_at) : void 0,
|
|
114
|
+
providerMetadata: { anthropic: this.toFileMetadata(response) }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
toFileMetadata(response) {
|
|
118
|
+
return {
|
|
119
|
+
...response.filename != null ? { filename: response.filename } : {},
|
|
120
|
+
...response.mime_type != null ? { mimeType: response.mime_type } : {},
|
|
121
|
+
...response.size_bytes != null ? { sizeBytes: response.size_bytes } : {},
|
|
122
|
+
...response.created_at != null ? { createdAt: response.created_at } : {},
|
|
123
|
+
...response.downloadable != null ? { downloadable: response.downloadable } : {},
|
|
124
|
+
...response.expires_at != null ? { expiresAt: response.expires_at } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async downloadFile({ file, abortSignal, headers }) {
|
|
128
|
+
const fileId = this.getFileId(file);
|
|
129
|
+
const { value: content, responseHeaders } = await getFromApi({
|
|
130
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
|
|
131
|
+
headers: await this.getHeaders(headers),
|
|
132
|
+
abortSignal,
|
|
133
|
+
fetch: this.config.fetch,
|
|
134
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
135
|
+
successfulResponseHandler: createBinaryStreamResponseHandler(),
|
|
136
|
+
validateUrl: false
|
|
137
|
+
});
|
|
138
|
+
const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
|
|
139
|
+
return {
|
|
140
|
+
warnings: [],
|
|
141
|
+
content,
|
|
142
|
+
...mediaType ? { mediaType } : {}
|
|
62
143
|
};
|
|
63
144
|
}
|
|
64
145
|
};
|
|
@@ -70,6 +151,7 @@ var AnthropicFiles = class {
|
|
|
70
151
|
*/
|
|
71
152
|
const anthropicProviderOptions = { language: {
|
|
72
153
|
sendReasoning: { description: "Whether to send reasoning to the model." },
|
|
154
|
+
includePings: { description: "Include transient ping events in streams." },
|
|
73
155
|
structuredOutputMode: { description: "How structured outputs are generated." },
|
|
74
156
|
thinking: { description: "Extended thinking configuration." },
|
|
75
157
|
disableParallelToolUse: { description: "Use at most one tool per response." },
|
|
@@ -345,6 +427,7 @@ function createAnthropicLanguageModelEntry(modelId, documented) {
|
|
|
345
427
|
compaction: documented?.compaction ?? "unknown"
|
|
346
428
|
} },
|
|
347
429
|
providerOptions: { language: declareProviderOptions(anthropicProviderOptions.language, declared ? true : "unknown", {
|
|
430
|
+
includePings: true,
|
|
348
431
|
thinking: reasoningSupport,
|
|
349
432
|
effort: documented?.effort ?? "unknown",
|
|
350
433
|
speed: declared ? modelId === "claude-opus-4-6" : "unknown",
|
|
@@ -721,10 +804,12 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
721
804
|
])),
|
|
722
805
|
stop_reason: z.string().nullish(),
|
|
723
806
|
stop_sequence: z.string().nullish(),
|
|
807
|
+
service_tier: z.string().nullish(),
|
|
724
808
|
stop_details: anthropicStopDetailsSchema().nullish(),
|
|
725
809
|
input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
|
|
726
810
|
safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
|
|
727
811
|
usage: z.looseObject({
|
|
812
|
+
service_tier: z.string().nullish(),
|
|
728
813
|
input_tokens: z.number(),
|
|
729
814
|
output_tokens: z.number(),
|
|
730
815
|
output_tokens_details: z.object({ thinking_tokens: z.number().nullish() }).nullish(),
|
|
@@ -774,7 +859,9 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
774
859
|
id: z.string().nullish(),
|
|
775
860
|
model: z.string().nullish(),
|
|
776
861
|
role: z.string().nullish(),
|
|
862
|
+
service_tier: z.string().nullish(),
|
|
777
863
|
usage: z.looseObject({
|
|
864
|
+
service_tier: z.string().nullish(),
|
|
778
865
|
input_tokens: z.number(),
|
|
779
866
|
cache_creation_input_tokens: z.number().nullish(),
|
|
780
867
|
cache_read_input_tokens: z.number().nullish()
|
|
@@ -1063,6 +1150,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
1063
1150
|
}).nullish()
|
|
1064
1151
|
}),
|
|
1065
1152
|
usage: z.looseObject({
|
|
1153
|
+
service_tier: z.string().nullish(),
|
|
1066
1154
|
input_tokens: z.number().nullish(),
|
|
1067
1155
|
output_tokens: z.number(),
|
|
1068
1156
|
output_tokens_details: z.object({ thinking_tokens: z.number().nullish() }).nullish(),
|
|
@@ -1203,6 +1291,8 @@ const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
1203
1291
|
"jsonTool",
|
|
1204
1292
|
"auto"
|
|
1205
1293
|
]).optional(),
|
|
1294
|
+
/** Emit typed streaming heartbeat parts. Disabled by default. */
|
|
1295
|
+
includePings: z.boolean().optional(),
|
|
1206
1296
|
/**
|
|
1207
1297
|
* Configuration for enabling Claude's extended thinking.
|
|
1208
1298
|
*
|
|
@@ -1352,8 +1442,17 @@ userId: z.string().optional() }).optional(),
|
|
|
1352
1442
|
* Only supported with claude-opus-4-6.
|
|
1353
1443
|
*/
|
|
1354
1444
|
speed: z.enum(["fast", "standard"]).optional(),
|
|
1355
|
-
/**
|
|
1356
|
-
|
|
1445
|
+
/**
|
|
1446
|
+
* Request admission tier. Anthropic accepts `auto` and `standard_only`;
|
|
1447
|
+
* MiniMax accepts `standard` and `priority`. Values for another known
|
|
1448
|
+
* provider are omitted with an unsupported-setting warning.
|
|
1449
|
+
*/
|
|
1450
|
+
serviceTier: z.enum([
|
|
1451
|
+
"auto",
|
|
1452
|
+
"standard_only",
|
|
1453
|
+
"standard",
|
|
1454
|
+
"priority"
|
|
1455
|
+
]).optional(),
|
|
1357
1456
|
/**
|
|
1358
1457
|
* Controls where model inference runs for this request.
|
|
1359
1458
|
*
|
|
@@ -1863,7 +1962,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
1863
1962
|
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1864
1963
|
...tool.inputExamples != null ? { input_examples: tool.inputExamples.map((example) => example.input) } : {}
|
|
1865
1964
|
});
|
|
1866
|
-
if (supportsStructuredOutput === true) betas.add("structured-outputs-2025-11-13");
|
|
1965
|
+
if (supportsStructuredOutput === true && supportsStrictTools === true) betas.add("structured-outputs-2025-11-13");
|
|
1867
1966
|
if (tool.inputExamples != null || allowedCallers != null) betas.add("advanced-tool-use-2025-11-20");
|
|
1868
1967
|
break;
|
|
1869
1968
|
}
|
|
@@ -2994,7 +3093,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2994
3093
|
for (let j = 0; j < block.messages.length; j++) {
|
|
2995
3094
|
const message = block.messages[j];
|
|
2996
3095
|
const isLastMessage = j === block.messages.length - 1;
|
|
2997
|
-
const
|
|
3096
|
+
const content = message.content.filter((part) => part.type !== "text" || part.text.length > 0);
|
|
2998
3097
|
for (let k = 0; k < content.length; k++) {
|
|
2999
3098
|
const part = content[k];
|
|
3000
3099
|
const isLastContentPart = k === content.length - 1;
|
|
@@ -4120,6 +4219,17 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4120
4219
|
}) : null;
|
|
4121
4220
|
const usedCustomProviderKey = customProviderOptions != null;
|
|
4122
4221
|
const anthropicOptions = Object.assign({}, canonicalOptions ?? {}, customProviderOptions ?? {});
|
|
4222
|
+
if (anthropicOptions.serviceTier != null) {
|
|
4223
|
+
const supportedTiers = providerOptionsName === "anthropic" ? ["auto", "standard_only"] : providerOptionsName === "minimax" ? ["standard", "priority"] : void 0;
|
|
4224
|
+
if (supportedTiers != null && !supportedTiers.includes(anthropicOptions.serviceTier)) {
|
|
4225
|
+
warnings.push({
|
|
4226
|
+
type: "unsupported",
|
|
4227
|
+
feature: "serviceTier",
|
|
4228
|
+
details: `serviceTier "${anthropicOptions.serviceTier}" is not supported by ${providerOptionsName}. Use ${supportedTiers.map((tier) => `"${tier}"`).join(" or ")}.`
|
|
4229
|
+
});
|
|
4230
|
+
anthropicOptions.serviceTier = void 0;
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4123
4233
|
const { maxOutputTokens: maxOutputTokensForModel, supportsStructuredOutput: modelSupportsStructuredOutput, supportsAdaptiveThinking, rejectsSamplingParameters, supportsXhighEffort, rejectsThinkingDisabledAboveHighEffort, rejectsThinkingDisabled, rejectsBudgetThinking, rejectsForcedToolUse, supportsBetweenToolsThinking, isKnownModel } = getAnthropicModelCapabilities(modelId);
|
|
4124
4234
|
if (!isKnownModel && maxOutputTokens == null) warnings.push({
|
|
4125
4235
|
type: "compatibility",
|
|
@@ -4495,6 +4605,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4495
4605
|
...anthropicOptions?.anthropicBeta ?? []
|
|
4496
4606
|
]),
|
|
4497
4607
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4608
|
+
includePings: stream === true && anthropicOptions?.includePings === true,
|
|
4498
4609
|
toolNameMapping,
|
|
4499
4610
|
providerOptionsName,
|
|
4500
4611
|
usedCustomProviderKey
|
|
@@ -4928,9 +5039,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4928
5039
|
warnings,
|
|
4929
5040
|
providerMetadata: (() => {
|
|
4930
5041
|
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
5042
|
+
const serviceTier = response.usage.service_tier ?? response.service_tier;
|
|
4931
5043
|
const anthropicMetadata = {
|
|
4932
5044
|
usage: response.usage,
|
|
4933
5045
|
stopSequence: response.stop_sequence ?? null,
|
|
5046
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
4934
5047
|
...stopDetails != null ? { stopDetails } : {},
|
|
4935
5048
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
4936
5049
|
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
@@ -4962,7 +5075,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4962
5075
|
async doStream(options) {
|
|
4963
5076
|
"use step";
|
|
4964
5077
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4965
|
-
const { args: body, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5078
|
+
const { args: body, warnings, betas, usesJsonResponseTool, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4966
5079
|
...options,
|
|
4967
5080
|
stream: true,
|
|
4968
5081
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
@@ -5001,6 +5114,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5001
5114
|
let contextManagement = null;
|
|
5002
5115
|
let rawUsage = void 0;
|
|
5003
5116
|
let stopSequence = null;
|
|
5117
|
+
let serviceTier = null;
|
|
5004
5118
|
let stopDetails = void 0;
|
|
5005
5119
|
let inputTransformations;
|
|
5006
5120
|
let safeguardResults;
|
|
@@ -5045,7 +5159,9 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5045
5159
|
}
|
|
5046
5160
|
const value = chunk.value;
|
|
5047
5161
|
switch (value.type) {
|
|
5048
|
-
case "ping":
|
|
5162
|
+
case "ping":
|
|
5163
|
+
if (includePings) controller.enqueue({ type: "ping" });
|
|
5164
|
+
return;
|
|
5049
5165
|
case "content_block_start": {
|
|
5050
5166
|
const part = value.content_block;
|
|
5051
5167
|
const contentBlockType = part.type;
|
|
@@ -5609,6 +5725,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5609
5725
|
});
|
|
5610
5726
|
return;
|
|
5611
5727
|
}
|
|
5728
|
+
serviceTier = value.message.usage.service_tier ?? value.message.service_tier ?? null;
|
|
5612
5729
|
isMessageOpen = true;
|
|
5613
5730
|
activeMessageId = value.message.id;
|
|
5614
5731
|
heldBackTextByIndex.clear();
|
|
@@ -5700,6 +5817,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5700
5817
|
if (value.context_management) contextManagement = mapAnthropicResponseContextManagement(value.context_management);
|
|
5701
5818
|
if (value.input_transformations != null) inputTransformations = value.input_transformations;
|
|
5702
5819
|
if (value.delta.safeguard_results != null) safeguardResults = value.delta.safeguard_results;
|
|
5820
|
+
serviceTier = value.usage.service_tier ?? serviceTier;
|
|
5703
5821
|
rawUsage = {
|
|
5704
5822
|
...rawUsage,
|
|
5705
5823
|
...value.usage
|
|
@@ -5711,6 +5829,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5711
5829
|
const anthropicMetadata = {
|
|
5712
5830
|
usage: rawUsage ?? null,
|
|
5713
5831
|
stopSequence,
|
|
5832
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
5714
5833
|
...stopDetails != null ? { stopDetails } : {},
|
|
5715
5834
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5716
5835
|
...safeguardResults != null ? { safeguardResults } : {},
|
|
@@ -5820,7 +5939,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5820
5939
|
try {
|
|
5821
5940
|
await firstChunkReader.read();
|
|
5822
5941
|
let result = await firstChunkReader.read();
|
|
5823
|
-
|
|
5942
|
+
while (result.value?.type === "raw" || result.value?.type === "ping") result = await firstChunkReader.read();
|
|
5824
5943
|
if (result.value?.type === "error") {
|
|
5825
5944
|
const error = result.value.error;
|
|
5826
5945
|
if (!isProviderStreamError(error)) throw new Error("Expected a normalized Anthropic stream error");
|