@anthropic-ai/sdk 0.51.0 → 0.53.0
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 +48 -0
- package/README.md +79 -45
- package/client.d.mts +1 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts +1 -0
- package/client.d.ts.map +1 -1
- package/client.js +10 -1
- package/client.js.map +1 -1
- package/client.mjs +10 -1
- package/client.mjs.map +1 -1
- package/core/pagination.d.mts +1 -1
- package/core/pagination.d.mts.map +1 -1
- package/core/pagination.d.ts +1 -1
- package/core/pagination.d.ts.map +1 -1
- package/internal/constants.d.mts +5 -0
- package/internal/constants.d.mts.map +1 -0
- package/internal/constants.d.ts +5 -0
- package/internal/constants.d.ts.map +1 -0
- package/internal/constants.js +15 -0
- package/internal/constants.js.map +1 -0
- package/internal/constants.mjs +12 -0
- package/internal/constants.mjs.map +1 -0
- package/internal/detect-platform.js +3 -3
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs +3 -3
- package/internal/detect-platform.mjs.map +1 -1
- package/internal/shim-types.d.mts +11 -22
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +11 -22
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +2 -2
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts +2 -2
- package/internal/shims.d.ts.map +1 -1
- package/internal/to-file.d.mts.map +1 -1
- package/internal/to-file.d.ts.map +1 -1
- package/internal/to-file.js +9 -4
- package/internal/to-file.js.map +1 -1
- package/internal/to-file.mjs +9 -4
- package/internal/to-file.mjs.map +1 -1
- package/internal/uploads.js +7 -2
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +7 -2
- package/internal/uploads.mjs.map +1 -1
- package/lib/BetaMessageStream.d.mts +2 -2
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts +2 -2
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +6 -2
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +6 -2
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.mts +2 -2
- package/lib/MessageStream.d.mts.map +1 -1
- package/lib/MessageStream.d.ts +2 -2
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +5 -2
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +5 -2
- package/lib/MessageStream.mjs.map +1 -1
- package/package.json +1 -4
- package/resources/beta/beta.d.mts +7 -3
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +7 -3
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +4 -0
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +4 -0
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/files.d.mts +151 -0
- package/resources/beta/files.d.mts.map +1 -0
- package/resources/beta/files.d.ts +151 -0
- package/resources/beta/files.d.ts.map +1 -0
- package/resources/beta/files.js +122 -0
- package/resources/beta/files.js.map +1 -0
- package/resources/beta/files.mjs +118 -0
- package/resources/beta/files.mjs.map +1 -0
- package/resources/beta/index.d.mts +2 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +2 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js +3 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +1 -0
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/index.d.mts +1 -1
- package/resources/beta/messages/index.d.mts.map +1 -1
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +250 -12
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +250 -12
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +7 -2
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +7 -2
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/messages/messages.d.mts +54 -9
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +54 -9
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +9 -6
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +8 -4
- package/resources/messages/messages.mjs.map +1 -1
- package/src/client.ts +15 -1
- package/src/core/pagination.ts +1 -1
- package/src/internal/constants.ts +12 -0
- package/src/internal/detect-platform.ts +3 -3
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +2 -2
- package/src/internal/to-file.ts +10 -5
- package/src/internal/uploads.ts +9 -3
- package/src/lib/BetaMessageStream.ts +12 -3
- package/src/lib/MessageStream.ts +10 -3
- package/src/resources/beta/beta.ts +85 -1
- package/src/resources/beta/files.ts +258 -0
- package/src/resources/beta/index.ts +37 -0
- package/src/resources/beta/messages/index.ts +26 -0
- package/src/resources/beta/messages/messages.ts +400 -23
- package/src/resources/messages/messages.ts +87 -13
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/src/internal/shim-types.d.ts +0 -28
package/src/internal/to-file.ts
CHANGED
|
@@ -90,12 +90,19 @@ export async function toFile(
|
|
|
90
90
|
// If it's a promise, resolve it.
|
|
91
91
|
value = await value;
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
name ||= getName(value);
|
|
94
|
+
|
|
95
|
+
// If we've been given a `File` we don't need to do anything if the name / options
|
|
96
|
+
// have not been customised.
|
|
94
97
|
if (isFileLike(value)) {
|
|
95
|
-
if (value instanceof File) {
|
|
98
|
+
if (value instanceof File && name == null && options == null) {
|
|
96
99
|
return value;
|
|
97
100
|
}
|
|
98
|
-
return makeFile([await value.arrayBuffer()], value.name
|
|
101
|
+
return makeFile([await value.arrayBuffer()], name ?? value.name, {
|
|
102
|
+
type: value.type,
|
|
103
|
+
lastModified: value.lastModified,
|
|
104
|
+
...options,
|
|
105
|
+
});
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
if (isResponseLike(value)) {
|
|
@@ -107,8 +114,6 @@ export async function toFile(
|
|
|
107
114
|
|
|
108
115
|
const parts = await getBytes(value);
|
|
109
116
|
|
|
110
|
-
name ||= getName(value);
|
|
111
|
-
|
|
112
117
|
if (!options?.type) {
|
|
113
118
|
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
|
114
119
|
if (typeof type === 'string') {
|
package/src/internal/uploads.ts
CHANGED
|
@@ -138,7 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
|
|
|
138
138
|
|
|
139
139
|
// We check for Blob not File because Bun.File doesn't inherit from File,
|
|
140
140
|
// but they both inherit from Blob and have a `name` property at runtime.
|
|
141
|
-
const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
|
|
141
|
+
const isNamedBlob = (value: object): value is Blob => value instanceof Blob && 'name' in value;
|
|
142
142
|
|
|
143
143
|
const isUploadable = (value: unknown) =>
|
|
144
144
|
typeof value === 'object' &&
|
|
@@ -168,11 +168,17 @@ const addFormValue = async (form: FormData, key: string, value: unknown): Promis
|
|
|
168
168
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
169
169
|
form.append(key, String(value));
|
|
170
170
|
} else if (value instanceof Response) {
|
|
171
|
-
|
|
171
|
+
let options = {} as FilePropertyBag;
|
|
172
|
+
const contentType = value.headers.get('Content-Type');
|
|
173
|
+
if (contentType) {
|
|
174
|
+
options = { type: contentType };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
form.append(key, makeFile([await value.blob()], getName(value), options));
|
|
172
178
|
} else if (isAsyncIterable(value)) {
|
|
173
179
|
form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value)));
|
|
174
180
|
} else if (isNamedBlob(value)) {
|
|
175
|
-
form.append(key, value, getName(value));
|
|
181
|
+
form.append(key, makeFile([value], getName(value), { type: value.type }));
|
|
176
182
|
} else if (Array.isArray(value)) {
|
|
177
183
|
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
|
178
184
|
} else if (typeof value === 'object') {
|
|
@@ -10,11 +10,13 @@ import {
|
|
|
10
10
|
type MessageCreateParamsBase as BetaMessageCreateParamsBase,
|
|
11
11
|
type BetaTextBlock,
|
|
12
12
|
type BetaTextCitation,
|
|
13
|
+
type BetaToolUseBlock,
|
|
14
|
+
type BetaServerToolUseBlock,
|
|
15
|
+
type BetaMCPToolUseBlock,
|
|
13
16
|
} from '../resources/beta/messages/messages';
|
|
14
17
|
import { Stream } from '../streaming';
|
|
15
18
|
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
|
16
19
|
import { type RequestOptions } from '../internal/request-options';
|
|
17
|
-
import { type ReadableStream } from '../internal/shim-types';
|
|
18
20
|
|
|
19
21
|
export interface MessageStreamEvents {
|
|
20
22
|
connect: () => void;
|
|
@@ -39,6 +41,12 @@ type MessageStreamEventListeners<Event extends keyof MessageStreamEvents> = {
|
|
|
39
41
|
|
|
40
42
|
const JSON_BUF_PROPERTY = '__json_buf';
|
|
41
43
|
|
|
44
|
+
export type TracksToolInput = BetaToolUseBlock | BetaServerToolUseBlock | BetaMCPToolUseBlock;
|
|
45
|
+
|
|
46
|
+
function tracksToolInput(content: BetaContentBlock): content is TracksToolInput {
|
|
47
|
+
return content.type === 'tool_use' || content.type === 'server_tool_use' || content.type === 'mcp_tool_use';
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent> {
|
|
43
51
|
messages: BetaMessageParam[] = [];
|
|
44
52
|
receivedMessages: BetaMessage[] = [];
|
|
@@ -432,7 +440,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
432
440
|
break;
|
|
433
441
|
}
|
|
434
442
|
case 'input_json_delta': {
|
|
435
|
-
if (content
|
|
443
|
+
if (tracksToolInput(content) && content.input) {
|
|
436
444
|
this._emit('inputJson', event.delta.partial_json, content.input);
|
|
437
445
|
}
|
|
438
446
|
break;
|
|
@@ -528,6 +536,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
528
536
|
case 'message_stop':
|
|
529
537
|
return snapshot;
|
|
530
538
|
case 'message_delta':
|
|
539
|
+
snapshot.container = event.delta.container;
|
|
531
540
|
snapshot.stop_reason = event.delta.stop_reason;
|
|
532
541
|
snapshot.stop_sequence = event.delta.stop_sequence;
|
|
533
542
|
snapshot.usage.output_tokens = event.usage.output_tokens;
|
|
@@ -570,7 +579,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
570
579
|
break;
|
|
571
580
|
}
|
|
572
581
|
case 'input_json_delta': {
|
|
573
|
-
if (snapshotContent
|
|
582
|
+
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
|
574
583
|
// we need to keep track of the raw JSON string as well so that we can
|
|
575
584
|
// re-parse it for each delta, for now we just store it as an untyped
|
|
576
585
|
// non-enumerable property on the snapshot
|
package/src/lib/MessageStream.ts
CHANGED
|
@@ -10,11 +10,12 @@ import {
|
|
|
10
10
|
type MessageCreateParamsBase,
|
|
11
11
|
type TextBlock,
|
|
12
12
|
type TextCitation,
|
|
13
|
+
type ToolUseBlock,
|
|
14
|
+
type ServerToolUseBlock,
|
|
13
15
|
} from '../resources/messages';
|
|
14
16
|
import { Stream } from '../streaming';
|
|
15
17
|
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
|
16
18
|
import { RequestOptions } from '../internal/request-options';
|
|
17
|
-
import { type ReadableStream } from '../internal/shim-types';
|
|
18
19
|
|
|
19
20
|
export interface MessageStreamEvents {
|
|
20
21
|
connect: () => void;
|
|
@@ -39,6 +40,12 @@ type MessageStreamEventListeners<Event extends keyof MessageStreamEvents> = {
|
|
|
39
40
|
|
|
40
41
|
const JSON_BUF_PROPERTY = '__json_buf';
|
|
41
42
|
|
|
43
|
+
export type TracksToolInput = ToolUseBlock | ServerToolUseBlock;
|
|
44
|
+
|
|
45
|
+
function tracksToolInput(content: ContentBlock): content is TracksToolInput {
|
|
46
|
+
return content.type === 'tool_use' || content.type === 'server_tool_use';
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
43
50
|
messages: MessageParam[] = [];
|
|
44
51
|
receivedMessages: Message[] = [];
|
|
@@ -432,7 +439,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
432
439
|
break;
|
|
433
440
|
}
|
|
434
441
|
case 'input_json_delta': {
|
|
435
|
-
if (content
|
|
442
|
+
if (tracksToolInput(content) && content.input) {
|
|
436
443
|
this._emit('inputJson', event.delta.partial_json, content.input);
|
|
437
444
|
}
|
|
438
445
|
break;
|
|
@@ -571,7 +578,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
571
578
|
break;
|
|
572
579
|
}
|
|
573
580
|
case 'input_json_delta': {
|
|
574
|
-
if (snapshotContent
|
|
581
|
+
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
|
575
582
|
// we need to keep track of the raw JSON string as well so that we can
|
|
576
583
|
// re-parse it for each delta, for now we just store it as an untyped
|
|
577
584
|
// non-enumerable property on the snapshot
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../../core/resource';
|
|
4
|
+
import * as FilesAPI from './files';
|
|
5
|
+
import {
|
|
6
|
+
DeletedFile,
|
|
7
|
+
FileDeleteParams,
|
|
8
|
+
FileDownloadParams,
|
|
9
|
+
FileListParams,
|
|
10
|
+
FileMetadata,
|
|
11
|
+
FileMetadataPage,
|
|
12
|
+
FileRetrieveMetadataParams,
|
|
13
|
+
FileUploadParams,
|
|
14
|
+
Files,
|
|
15
|
+
} from './files';
|
|
4
16
|
import * as ModelsAPI from './models';
|
|
5
17
|
import { BetaModelInfo, BetaModelInfosPage, ModelListParams, ModelRetrieveParams, Models } from './models';
|
|
6
18
|
import * as MessagesAPI from './messages/messages';
|
|
@@ -9,6 +21,7 @@ import {
|
|
|
9
21
|
BetaBase64PDFBlock,
|
|
10
22
|
BetaBase64PDFSource,
|
|
11
23
|
BetaCacheControlEphemeral,
|
|
24
|
+
BetaCacheCreation,
|
|
12
25
|
BetaCitationCharLocation,
|
|
13
26
|
BetaCitationCharLocationParam,
|
|
14
27
|
BetaCitationContentBlockLocation,
|
|
@@ -19,12 +32,32 @@ import {
|
|
|
19
32
|
BetaCitationsConfigParam,
|
|
20
33
|
BetaCitationsDelta,
|
|
21
34
|
BetaCitationsWebSearchResultLocation,
|
|
35
|
+
BetaCodeExecutionOutputBlock,
|
|
36
|
+
BetaCodeExecutionOutputBlockParam,
|
|
37
|
+
BetaCodeExecutionResultBlock,
|
|
38
|
+
BetaCodeExecutionResultBlockParam,
|
|
39
|
+
BetaCodeExecutionTool20250522,
|
|
40
|
+
BetaCodeExecutionToolResultBlock,
|
|
41
|
+
BetaCodeExecutionToolResultBlockContent,
|
|
42
|
+
BetaCodeExecutionToolResultBlockParam,
|
|
43
|
+
BetaCodeExecutionToolResultBlockParamContent,
|
|
44
|
+
BetaCodeExecutionToolResultError,
|
|
45
|
+
BetaCodeExecutionToolResultErrorCode,
|
|
46
|
+
BetaCodeExecutionToolResultErrorParam,
|
|
47
|
+
BetaContainer,
|
|
48
|
+
BetaContainerUploadBlock,
|
|
49
|
+
BetaContainerUploadBlockParam,
|
|
22
50
|
BetaContentBlock,
|
|
23
51
|
BetaContentBlockParam,
|
|
24
52
|
BetaContentBlockSource,
|
|
25
53
|
BetaContentBlockSourceContent,
|
|
54
|
+
BetaFileDocumentSource,
|
|
55
|
+
BetaFileImageSource,
|
|
26
56
|
BetaImageBlockParam,
|
|
27
57
|
BetaInputJSONDelta,
|
|
58
|
+
BetaMCPToolResultBlock,
|
|
59
|
+
BetaMCPToolUseBlock,
|
|
60
|
+
BetaMCPToolUseBlockParam,
|
|
28
61
|
BetaMessage,
|
|
29
62
|
BetaMessageDeltaUsage,
|
|
30
63
|
BetaMessageParam,
|
|
@@ -41,6 +74,9 @@ import {
|
|
|
41
74
|
BetaRawMessageStreamEvent,
|
|
42
75
|
BetaRedactedThinkingBlock,
|
|
43
76
|
BetaRedactedThinkingBlockParam,
|
|
77
|
+
BetaRequestMCPServerToolConfiguration,
|
|
78
|
+
BetaRequestMCPServerURLDefinition,
|
|
79
|
+
BetaRequestMCPToolResultBlockParam,
|
|
44
80
|
BetaServerToolUsage,
|
|
45
81
|
BetaServerToolUseBlock,
|
|
46
82
|
BetaServerToolUseBlockParam,
|
|
@@ -70,6 +106,7 @@ import {
|
|
|
70
106
|
BetaToolResultBlockParam,
|
|
71
107
|
BetaToolTextEditor20241022,
|
|
72
108
|
BetaToolTextEditor20250124,
|
|
109
|
+
BetaToolTextEditor20250429,
|
|
73
110
|
BetaToolUnion,
|
|
74
111
|
BetaToolUseBlock,
|
|
75
112
|
BetaToolUseBlockParam,
|
|
@@ -85,6 +122,7 @@ import {
|
|
|
85
122
|
BetaWebSearchToolResultBlockParam,
|
|
86
123
|
BetaWebSearchToolResultBlockParamContent,
|
|
87
124
|
BetaWebSearchToolResultError,
|
|
125
|
+
BetaWebSearchToolResultErrorCode,
|
|
88
126
|
MessageCountTokensParams,
|
|
89
127
|
MessageCreateParams,
|
|
90
128
|
MessageCreateParamsNonStreaming,
|
|
@@ -95,6 +133,7 @@ import {
|
|
|
95
133
|
export class Beta extends APIResource {
|
|
96
134
|
models: ModelsAPI.Models = new ModelsAPI.Models(this._client);
|
|
97
135
|
messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
|
|
136
|
+
files: FilesAPI.Files = new FilesAPI.Files(this._client);
|
|
98
137
|
}
|
|
99
138
|
|
|
100
139
|
export type AnthropicBeta =
|
|
@@ -106,7 +145,13 @@ export type AnthropicBeta =
|
|
|
106
145
|
| 'pdfs-2024-09-25'
|
|
107
146
|
| 'token-counting-2024-11-01'
|
|
108
147
|
| 'token-efficient-tools-2025-02-19'
|
|
109
|
-
| 'output-128k-2025-02-19'
|
|
148
|
+
| 'output-128k-2025-02-19'
|
|
149
|
+
| 'files-api-2025-04-14'
|
|
150
|
+
| 'mcp-client-2025-04-04'
|
|
151
|
+
| 'dev-full-thinking-2025-05-14'
|
|
152
|
+
| 'interleaved-thinking-2025-05-14'
|
|
153
|
+
| 'code-execution-2025-05-22'
|
|
154
|
+
| 'extended-cache-ttl-2025-04-11';
|
|
110
155
|
|
|
111
156
|
export interface BetaAPIError {
|
|
112
157
|
message: string;
|
|
@@ -181,6 +226,7 @@ export interface BetaRateLimitError {
|
|
|
181
226
|
|
|
182
227
|
Beta.Models = Models;
|
|
183
228
|
Beta.Messages = Messages;
|
|
229
|
+
Beta.Files = Files;
|
|
184
230
|
|
|
185
231
|
export declare namespace Beta {
|
|
186
232
|
export {
|
|
@@ -212,6 +258,7 @@ export declare namespace Beta {
|
|
|
212
258
|
type BetaBase64PDFBlock as BetaBase64PDFBlock,
|
|
213
259
|
type BetaBase64PDFSource as BetaBase64PDFSource,
|
|
214
260
|
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
|
|
261
|
+
type BetaCacheCreation as BetaCacheCreation,
|
|
215
262
|
type BetaCitationCharLocation as BetaCitationCharLocation,
|
|
216
263
|
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
|
|
217
264
|
type BetaCitationContentBlockLocation as BetaCitationContentBlockLocation,
|
|
@@ -222,12 +269,32 @@ export declare namespace Beta {
|
|
|
222
269
|
type BetaCitationsConfigParam as BetaCitationsConfigParam,
|
|
223
270
|
type BetaCitationsDelta as BetaCitationsDelta,
|
|
224
271
|
type BetaCitationsWebSearchResultLocation as BetaCitationsWebSearchResultLocation,
|
|
272
|
+
type BetaCodeExecutionOutputBlock as BetaCodeExecutionOutputBlock,
|
|
273
|
+
type BetaCodeExecutionOutputBlockParam as BetaCodeExecutionOutputBlockParam,
|
|
274
|
+
type BetaCodeExecutionResultBlock as BetaCodeExecutionResultBlock,
|
|
275
|
+
type BetaCodeExecutionResultBlockParam as BetaCodeExecutionResultBlockParam,
|
|
276
|
+
type BetaCodeExecutionTool20250522 as BetaCodeExecutionTool20250522,
|
|
277
|
+
type BetaCodeExecutionToolResultBlock as BetaCodeExecutionToolResultBlock,
|
|
278
|
+
type BetaCodeExecutionToolResultBlockContent as BetaCodeExecutionToolResultBlockContent,
|
|
279
|
+
type BetaCodeExecutionToolResultBlockParam as BetaCodeExecutionToolResultBlockParam,
|
|
280
|
+
type BetaCodeExecutionToolResultBlockParamContent as BetaCodeExecutionToolResultBlockParamContent,
|
|
281
|
+
type BetaCodeExecutionToolResultError as BetaCodeExecutionToolResultError,
|
|
282
|
+
type BetaCodeExecutionToolResultErrorCode as BetaCodeExecutionToolResultErrorCode,
|
|
283
|
+
type BetaCodeExecutionToolResultErrorParam as BetaCodeExecutionToolResultErrorParam,
|
|
284
|
+
type BetaContainer as BetaContainer,
|
|
285
|
+
type BetaContainerUploadBlock as BetaContainerUploadBlock,
|
|
286
|
+
type BetaContainerUploadBlockParam as BetaContainerUploadBlockParam,
|
|
225
287
|
type BetaContentBlock as BetaContentBlock,
|
|
226
288
|
type BetaContentBlockParam as BetaContentBlockParam,
|
|
227
289
|
type BetaContentBlockSource as BetaContentBlockSource,
|
|
228
290
|
type BetaContentBlockSourceContent as BetaContentBlockSourceContent,
|
|
291
|
+
type BetaFileDocumentSource as BetaFileDocumentSource,
|
|
292
|
+
type BetaFileImageSource as BetaFileImageSource,
|
|
229
293
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
230
294
|
type BetaInputJSONDelta as BetaInputJSONDelta,
|
|
295
|
+
type BetaMCPToolResultBlock as BetaMCPToolResultBlock,
|
|
296
|
+
type BetaMCPToolUseBlock as BetaMCPToolUseBlock,
|
|
297
|
+
type BetaMCPToolUseBlockParam as BetaMCPToolUseBlockParam,
|
|
231
298
|
type BetaMessage as BetaMessage,
|
|
232
299
|
type BetaMessageDeltaUsage as BetaMessageDeltaUsage,
|
|
233
300
|
type BetaMessageParam as BetaMessageParam,
|
|
@@ -244,6 +311,9 @@ export declare namespace Beta {
|
|
|
244
311
|
type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
|
|
245
312
|
type BetaRedactedThinkingBlock as BetaRedactedThinkingBlock,
|
|
246
313
|
type BetaRedactedThinkingBlockParam as BetaRedactedThinkingBlockParam,
|
|
314
|
+
type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
|
|
315
|
+
type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
|
|
316
|
+
type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
|
|
247
317
|
type BetaServerToolUsage as BetaServerToolUsage,
|
|
248
318
|
type BetaServerToolUseBlock as BetaServerToolUseBlock,
|
|
249
319
|
type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
|
|
@@ -273,6 +343,7 @@ export declare namespace Beta {
|
|
|
273
343
|
type BetaToolResultBlockParam as BetaToolResultBlockParam,
|
|
274
344
|
type BetaToolTextEditor20241022 as BetaToolTextEditor20241022,
|
|
275
345
|
type BetaToolTextEditor20250124 as BetaToolTextEditor20250124,
|
|
346
|
+
type BetaToolTextEditor20250429 as BetaToolTextEditor20250429,
|
|
276
347
|
type BetaToolUnion as BetaToolUnion,
|
|
277
348
|
type BetaToolUseBlock as BetaToolUseBlock,
|
|
278
349
|
type BetaToolUseBlockParam as BetaToolUseBlockParam,
|
|
@@ -288,9 +359,22 @@ export declare namespace Beta {
|
|
|
288
359
|
type BetaWebSearchToolResultBlockParam as BetaWebSearchToolResultBlockParam,
|
|
289
360
|
type BetaWebSearchToolResultBlockParamContent as BetaWebSearchToolResultBlockParamContent,
|
|
290
361
|
type BetaWebSearchToolResultError as BetaWebSearchToolResultError,
|
|
362
|
+
type BetaWebSearchToolResultErrorCode as BetaWebSearchToolResultErrorCode,
|
|
291
363
|
type MessageCreateParams as MessageCreateParams,
|
|
292
364
|
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
|
|
293
365
|
type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
|
|
294
366
|
type MessageCountTokensParams as MessageCountTokensParams,
|
|
295
367
|
};
|
|
368
|
+
|
|
369
|
+
export {
|
|
370
|
+
Files as Files,
|
|
371
|
+
type DeletedFile as DeletedFile,
|
|
372
|
+
type FileMetadata as FileMetadata,
|
|
373
|
+
type FileMetadataPage as FileMetadataPage,
|
|
374
|
+
type FileListParams as FileListParams,
|
|
375
|
+
type FileDeleteParams as FileDeleteParams,
|
|
376
|
+
type FileDownloadParams as FileDownloadParams,
|
|
377
|
+
type FileRetrieveMetadataParams as FileRetrieveMetadataParams,
|
|
378
|
+
type FileUploadParams as FileUploadParams,
|
|
379
|
+
};
|
|
296
380
|
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../core/resource';
|
|
4
|
+
import * as BetaAPI from './beta';
|
|
5
|
+
import { APIPromise } from '../../core/api-promise';
|
|
6
|
+
import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
|
7
|
+
import { type Uploadable } from '../../core/uploads';
|
|
8
|
+
import { buildHeaders } from '../../internal/headers';
|
|
9
|
+
import { RequestOptions } from '../../internal/request-options';
|
|
10
|
+
import { multipartFormRequestOptions } from '../../internal/uploads';
|
|
11
|
+
import { path } from '../../internal/utils/path';
|
|
12
|
+
|
|
13
|
+
export class Files extends APIResource {
|
|
14
|
+
/**
|
|
15
|
+
* List Files
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Automatically fetches more pages as needed.
|
|
20
|
+
* for await (const fileMetadata of client.beta.files.list()) {
|
|
21
|
+
* // ...
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
list(
|
|
26
|
+
params: FileListParams | null | undefined = {},
|
|
27
|
+
options?: RequestOptions,
|
|
28
|
+
): PagePromise<FileMetadataPage, FileMetadata> {
|
|
29
|
+
const { betas, ...query } = params ?? {};
|
|
30
|
+
return this._client.getAPIList('/v1/files', Page<FileMetadata>, {
|
|
31
|
+
query,
|
|
32
|
+
...options,
|
|
33
|
+
headers: buildHeaders([
|
|
34
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
35
|
+
options?.headers,
|
|
36
|
+
]),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delete File
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const deletedFile = await client.beta.files.delete(
|
|
46
|
+
* 'file_id',
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
delete(
|
|
51
|
+
fileID: string,
|
|
52
|
+
params: FileDeleteParams | null | undefined = {},
|
|
53
|
+
options?: RequestOptions,
|
|
54
|
+
): APIPromise<DeletedFile> {
|
|
55
|
+
const { betas } = params ?? {};
|
|
56
|
+
return this._client.delete(path`/v1/files/${fileID}`, {
|
|
57
|
+
...options,
|
|
58
|
+
headers: buildHeaders([
|
|
59
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
60
|
+
options?.headers,
|
|
61
|
+
]),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Download File
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const response = await client.beta.files.download(
|
|
71
|
+
* 'file_id',
|
|
72
|
+
* );
|
|
73
|
+
*
|
|
74
|
+
* const content = await response.blob();
|
|
75
|
+
* console.log(content);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
download(
|
|
79
|
+
fileID: string,
|
|
80
|
+
params: FileDownloadParams | null | undefined = {},
|
|
81
|
+
options?: RequestOptions,
|
|
82
|
+
): APIPromise<Response> {
|
|
83
|
+
const { betas } = params ?? {};
|
|
84
|
+
return this._client.get(path`/v1/files/${fileID}/content`, {
|
|
85
|
+
...options,
|
|
86
|
+
headers: buildHeaders([
|
|
87
|
+
{
|
|
88
|
+
'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString(),
|
|
89
|
+
Accept: 'application/binary',
|
|
90
|
+
},
|
|
91
|
+
options?.headers,
|
|
92
|
+
]),
|
|
93
|
+
__binaryResponse: true,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get File Metadata
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const fileMetadata =
|
|
103
|
+
* await client.beta.files.retrieveMetadata('file_id');
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
retrieveMetadata(
|
|
107
|
+
fileID: string,
|
|
108
|
+
params: FileRetrieveMetadataParams | null | undefined = {},
|
|
109
|
+
options?: RequestOptions,
|
|
110
|
+
): APIPromise<FileMetadata> {
|
|
111
|
+
const { betas } = params ?? {};
|
|
112
|
+
return this._client.get(path`/v1/files/${fileID}`, {
|
|
113
|
+
...options,
|
|
114
|
+
headers: buildHeaders([
|
|
115
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
116
|
+
options?.headers,
|
|
117
|
+
]),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Upload File
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const fileMetadata = await client.beta.files.upload({
|
|
127
|
+
* file: fs.createReadStream('path/to/file'),
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
upload(params: FileUploadParams, options?: RequestOptions): APIPromise<FileMetadata> {
|
|
132
|
+
const { betas, ...body } = params;
|
|
133
|
+
return this._client.post(
|
|
134
|
+
'/v1/files',
|
|
135
|
+
multipartFormRequestOptions(
|
|
136
|
+
{
|
|
137
|
+
body,
|
|
138
|
+
...options,
|
|
139
|
+
headers: buildHeaders([
|
|
140
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
141
|
+
options?.headers,
|
|
142
|
+
]),
|
|
143
|
+
},
|
|
144
|
+
this._client,
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type FileMetadataPage = Page<FileMetadata>;
|
|
151
|
+
|
|
152
|
+
export interface DeletedFile {
|
|
153
|
+
/**
|
|
154
|
+
* ID of the deleted file.
|
|
155
|
+
*/
|
|
156
|
+
id: string;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Deleted object type.
|
|
160
|
+
*
|
|
161
|
+
* For file deletion, this is always `"file_deleted"`.
|
|
162
|
+
*/
|
|
163
|
+
type?: 'file_deleted';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface FileMetadata {
|
|
167
|
+
/**
|
|
168
|
+
* Unique object identifier.
|
|
169
|
+
*
|
|
170
|
+
* The format and length of IDs may change over time.
|
|
171
|
+
*/
|
|
172
|
+
id: string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* RFC 3339 datetime string representing when the file was created.
|
|
176
|
+
*/
|
|
177
|
+
created_at: string;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Original filename of the uploaded file.
|
|
181
|
+
*/
|
|
182
|
+
filename: string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* MIME type of the file.
|
|
186
|
+
*/
|
|
187
|
+
mime_type: string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Size of the file in bytes.
|
|
191
|
+
*/
|
|
192
|
+
size_bytes: number;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Object type.
|
|
196
|
+
*
|
|
197
|
+
* For files, this is always `"file"`.
|
|
198
|
+
*/
|
|
199
|
+
type: 'file';
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Whether the file can be downloaded.
|
|
203
|
+
*/
|
|
204
|
+
downloadable?: boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface FileListParams extends PageParams {
|
|
208
|
+
/**
|
|
209
|
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
210
|
+
*/
|
|
211
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface FileDeleteParams {
|
|
215
|
+
/**
|
|
216
|
+
* Optional header to specify the beta version(s) you want to use.
|
|
217
|
+
*/
|
|
218
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface FileDownloadParams {
|
|
222
|
+
/**
|
|
223
|
+
* Optional header to specify the beta version(s) you want to use.
|
|
224
|
+
*/
|
|
225
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface FileRetrieveMetadataParams {
|
|
229
|
+
/**
|
|
230
|
+
* Optional header to specify the beta version(s) you want to use.
|
|
231
|
+
*/
|
|
232
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface FileUploadParams {
|
|
236
|
+
/**
|
|
237
|
+
* Body param: The file to upload
|
|
238
|
+
*/
|
|
239
|
+
file: Uploadable;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
243
|
+
*/
|
|
244
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export declare namespace Files {
|
|
248
|
+
export {
|
|
249
|
+
type DeletedFile as DeletedFile,
|
|
250
|
+
type FileMetadata as FileMetadata,
|
|
251
|
+
type FileMetadataPage as FileMetadataPage,
|
|
252
|
+
type FileListParams as FileListParams,
|
|
253
|
+
type FileDeleteParams as FileDeleteParams,
|
|
254
|
+
type FileDownloadParams as FileDownloadParams,
|
|
255
|
+
type FileRetrieveMetadataParams as FileRetrieveMetadataParams,
|
|
256
|
+
type FileUploadParams as FileUploadParams,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -15,12 +15,24 @@ export {
|
|
|
15
15
|
type BetaPermissionError,
|
|
16
16
|
type BetaRateLimitError,
|
|
17
17
|
} from './beta';
|
|
18
|
+
export {
|
|
19
|
+
Files,
|
|
20
|
+
type DeletedFile,
|
|
21
|
+
type FileMetadata,
|
|
22
|
+
type FileListParams,
|
|
23
|
+
type FileDeleteParams,
|
|
24
|
+
type FileDownloadParams,
|
|
25
|
+
type FileRetrieveMetadataParams,
|
|
26
|
+
type FileUploadParams,
|
|
27
|
+
type FileMetadataPage,
|
|
28
|
+
} from './files';
|
|
18
29
|
export {
|
|
19
30
|
Messages,
|
|
20
31
|
type BetaBase64ImageSource,
|
|
21
32
|
type BetaBase64PDFBlock,
|
|
22
33
|
type BetaBase64PDFSource,
|
|
23
34
|
type BetaCacheControlEphemeral,
|
|
35
|
+
type BetaCacheCreation,
|
|
24
36
|
type BetaCitationCharLocation,
|
|
25
37
|
type BetaCitationCharLocationParam,
|
|
26
38
|
type BetaCitationContentBlockLocation,
|
|
@@ -31,12 +43,32 @@ export {
|
|
|
31
43
|
type BetaCitationsConfigParam,
|
|
32
44
|
type BetaCitationsDelta,
|
|
33
45
|
type BetaCitationsWebSearchResultLocation,
|
|
46
|
+
type BetaCodeExecutionOutputBlock,
|
|
47
|
+
type BetaCodeExecutionOutputBlockParam,
|
|
48
|
+
type BetaCodeExecutionResultBlock,
|
|
49
|
+
type BetaCodeExecutionResultBlockParam,
|
|
50
|
+
type BetaCodeExecutionTool20250522,
|
|
51
|
+
type BetaCodeExecutionToolResultBlock,
|
|
52
|
+
type BetaCodeExecutionToolResultBlockContent,
|
|
53
|
+
type BetaCodeExecutionToolResultBlockParam,
|
|
54
|
+
type BetaCodeExecutionToolResultBlockParamContent,
|
|
55
|
+
type BetaCodeExecutionToolResultError,
|
|
56
|
+
type BetaCodeExecutionToolResultErrorCode,
|
|
57
|
+
type BetaCodeExecutionToolResultErrorParam,
|
|
58
|
+
type BetaContainer,
|
|
59
|
+
type BetaContainerUploadBlock,
|
|
60
|
+
type BetaContainerUploadBlockParam,
|
|
34
61
|
type BetaContentBlock,
|
|
35
62
|
type BetaContentBlockParam,
|
|
36
63
|
type BetaContentBlockSource,
|
|
37
64
|
type BetaContentBlockSourceContent,
|
|
65
|
+
type BetaFileDocumentSource,
|
|
66
|
+
type BetaFileImageSource,
|
|
38
67
|
type BetaImageBlockParam,
|
|
39
68
|
type BetaInputJSONDelta,
|
|
69
|
+
type BetaMCPToolResultBlock,
|
|
70
|
+
type BetaMCPToolUseBlock,
|
|
71
|
+
type BetaMCPToolUseBlockParam,
|
|
40
72
|
type BetaMessage,
|
|
41
73
|
type BetaMessageDeltaUsage,
|
|
42
74
|
type BetaMessageParam,
|
|
@@ -53,6 +85,9 @@ export {
|
|
|
53
85
|
type BetaRawMessageStreamEvent,
|
|
54
86
|
type BetaRedactedThinkingBlock,
|
|
55
87
|
type BetaRedactedThinkingBlockParam,
|
|
88
|
+
type BetaRequestMCPServerToolConfiguration,
|
|
89
|
+
type BetaRequestMCPServerURLDefinition,
|
|
90
|
+
type BetaRequestMCPToolResultBlockParam,
|
|
56
91
|
type BetaServerToolUsage,
|
|
57
92
|
type BetaServerToolUseBlock,
|
|
58
93
|
type BetaServerToolUseBlockParam,
|
|
@@ -82,6 +117,7 @@ export {
|
|
|
82
117
|
type BetaToolResultBlockParam,
|
|
83
118
|
type BetaToolTextEditor20241022,
|
|
84
119
|
type BetaToolTextEditor20250124,
|
|
120
|
+
type BetaToolTextEditor20250429,
|
|
85
121
|
type BetaToolUnion,
|
|
86
122
|
type BetaToolUseBlock,
|
|
87
123
|
type BetaToolUseBlockParam,
|
|
@@ -97,6 +133,7 @@ export {
|
|
|
97
133
|
type BetaWebSearchToolResultBlockParam,
|
|
98
134
|
type BetaWebSearchToolResultBlockParamContent,
|
|
99
135
|
type BetaWebSearchToolResultError,
|
|
136
|
+
type BetaWebSearchToolResultErrorCode,
|
|
100
137
|
type MessageCreateParams,
|
|
101
138
|
type MessageCreateParamsNonStreaming,
|
|
102
139
|
type MessageCreateParamsStreaming,
|