@anthropic-ai/sdk 0.40.0 → 0.41.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 +27 -0
- package/README.md +3 -3
- package/index.d.mts +4 -4
- package/index.d.ts +4 -4
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +7 -0
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +7 -0
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +7 -0
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +7 -0
- package/lib/MessageStream.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/beta.d.ts +4 -4
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.ts +2 -2
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/batches.d.ts +59 -0
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/batches.js +19 -0
- package/resources/beta/messages/batches.js.map +1 -1
- package/resources/beta/messages/batches.mjs +19 -0
- package/resources/beta/messages/batches.mjs.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.ts +228 -17
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +9 -0
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +9 -0
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/models.d.ts +29 -2
- package/resources/beta/models.d.ts.map +1 -1
- package/resources/beta/models.js +24 -12
- package/resources/beta/models.js.map +1 -1
- package/resources/beta/models.mjs +24 -12
- package/resources/beta/models.mjs.map +1 -1
- package/resources/completions.d.ts +31 -14
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js +7 -2
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs +7 -2
- package/resources/completions.mjs.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/messages/batches.d.ts +52 -0
- package/resources/messages/batches.d.ts.map +1 -1
- package/resources/messages/batches.js +44 -0
- package/resources/messages/batches.js.map +1 -1
- package/resources/messages/batches.mjs +44 -0
- package/resources/messages/batches.mjs.map +1 -1
- package/resources/messages/index.d.ts +1 -1
- package/resources/messages/index.d.ts.map +1 -1
- package/resources/messages/index.js.map +1 -1
- package/resources/messages/index.mjs.map +1 -1
- package/resources/messages/messages.d.ts +213 -13
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +9 -0
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +9 -0
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/models.d.ts +14 -2
- package/resources/models.d.ts.map +1 -1
- package/resources/models.js +24 -12
- package/resources/models.js.map +1 -1
- package/resources/models.mjs +24 -12
- package/resources/models.mjs.map +1 -1
- package/src/index.ts +30 -1
- package/src/lib/BetaMessageStream.ts +9 -0
- package/src/lib/MessageStream.ts +9 -0
- package/src/resources/beta/beta.ts +30 -1
- package/src/resources/beta/index.ts +21 -1
- package/src/resources/beta/messages/batches.ts +59 -0
- package/src/resources/beta/messages/index.ts +14 -0
- package/src/resources/beta/messages/messages.ts +336 -13
- package/src/resources/beta/models.ts +65 -8
- package/src/resources/completions.ts +39 -16
- package/src/resources/index.ts +21 -1
- package/src/resources/messages/batches.ts +52 -0
- package/src/resources/messages/index.ts +14 -0
- package/src/resources/messages/messages.ts +321 -11
- package/src/resources/models.ts +50 -8
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -4,6 +4,7 @@ import { APIResource } from "../resource.js";
|
|
|
4
4
|
import { APIPromise } from "../core.js";
|
|
5
5
|
import * as Core from "../core.js";
|
|
6
6
|
import * as CompletionsAPI from "./completions.js";
|
|
7
|
+
import * as BetaAPI from "./beta/beta.js";
|
|
7
8
|
import * as MessagesAPI from "./messages/messages.js";
|
|
8
9
|
import { Stream } from "../streaming.js";
|
|
9
10
|
|
|
@@ -17,25 +18,39 @@ export class Completions extends APIResource {
|
|
|
17
18
|
* Future models and features will not be compatible with Text Completions. See our
|
|
18
19
|
* [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages)
|
|
19
20
|
* for guidance in migrating from Text Completions to Messages.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const completion = await client.completions.create({
|
|
25
|
+
* max_tokens_to_sample: 256,
|
|
26
|
+
* model: 'claude-3-7-sonnet-latest',
|
|
27
|
+
* prompt: '\n\nHuman: Hello, world!\n\nAssistant:',
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
20
30
|
*/
|
|
21
|
-
create(
|
|
31
|
+
create(params: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
|
|
22
32
|
create(
|
|
23
|
-
|
|
33
|
+
params: CompletionCreateParamsStreaming,
|
|
24
34
|
options?: Core.RequestOptions,
|
|
25
35
|
): APIPromise<Stream<Completion>>;
|
|
26
36
|
create(
|
|
27
|
-
|
|
37
|
+
params: CompletionCreateParamsBase,
|
|
28
38
|
options?: Core.RequestOptions,
|
|
29
39
|
): APIPromise<Stream<Completion> | Completion>;
|
|
30
40
|
create(
|
|
31
|
-
|
|
41
|
+
params: CompletionCreateParams,
|
|
32
42
|
options?: Core.RequestOptions,
|
|
33
43
|
): APIPromise<Completion> | APIPromise<Stream<Completion>> {
|
|
44
|
+
const { betas, ...body } = params;
|
|
34
45
|
return this._client.post('/v1/complete', {
|
|
35
46
|
body,
|
|
36
47
|
timeout: (this._client as any)._options.timeout ?? 600000,
|
|
37
48
|
...options,
|
|
38
|
-
|
|
49
|
+
headers: {
|
|
50
|
+
...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
|
|
51
|
+
...options?.headers,
|
|
52
|
+
},
|
|
53
|
+
stream: params.stream ?? false,
|
|
39
54
|
}) as APIPromise<Completion> | APIPromise<Stream<Completion>>;
|
|
40
55
|
}
|
|
41
56
|
}
|
|
@@ -83,7 +98,7 @@ export type CompletionCreateParams = CompletionCreateParamsNonStreaming | Comple
|
|
|
83
98
|
|
|
84
99
|
export interface CompletionCreateParamsBase {
|
|
85
100
|
/**
|
|
86
|
-
* The maximum number of tokens to generate before stopping.
|
|
101
|
+
* Body param: The maximum number of tokens to generate before stopping.
|
|
87
102
|
*
|
|
88
103
|
* Note that our models may stop _before_ reaching this maximum. This parameter
|
|
89
104
|
* only specifies the absolute maximum number of tokens to generate.
|
|
@@ -91,14 +106,14 @@ export interface CompletionCreateParamsBase {
|
|
|
91
106
|
max_tokens_to_sample: number;
|
|
92
107
|
|
|
93
108
|
/**
|
|
94
|
-
* The model that will complete your prompt.\n\nSee
|
|
109
|
+
* Body param: The model that will complete your prompt.\n\nSee
|
|
95
110
|
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
96
111
|
* details and options.
|
|
97
112
|
*/
|
|
98
113
|
model: MessagesAPI.Model;
|
|
99
114
|
|
|
100
115
|
/**
|
|
101
|
-
* The prompt that you want Claude to complete.
|
|
116
|
+
* Body param: The prompt that you want Claude to complete.
|
|
102
117
|
*
|
|
103
118
|
* For proper response generation you will need to format your prompt using
|
|
104
119
|
* alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
|
@@ -115,12 +130,12 @@ export interface CompletionCreateParamsBase {
|
|
|
115
130
|
prompt: string;
|
|
116
131
|
|
|
117
132
|
/**
|
|
118
|
-
* An object describing metadata about the request.
|
|
133
|
+
* Body param: An object describing metadata about the request.
|
|
119
134
|
*/
|
|
120
135
|
metadata?: MessagesAPI.Metadata;
|
|
121
136
|
|
|
122
137
|
/**
|
|
123
|
-
* Sequences that will cause the model to stop generating.
|
|
138
|
+
* Body param: Sequences that will cause the model to stop generating.
|
|
124
139
|
*
|
|
125
140
|
* Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
|
126
141
|
* sequences in the future. By providing the stop_sequences parameter, you may
|
|
@@ -129,14 +144,15 @@ export interface CompletionCreateParamsBase {
|
|
|
129
144
|
stop_sequences?: Array<string>;
|
|
130
145
|
|
|
131
146
|
/**
|
|
132
|
-
* Whether to incrementally stream the response using server-sent
|
|
147
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
148
|
+
* events.
|
|
133
149
|
*
|
|
134
150
|
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
135
151
|
*/
|
|
136
152
|
stream?: boolean;
|
|
137
153
|
|
|
138
154
|
/**
|
|
139
|
-
* Amount of randomness injected into the response.
|
|
155
|
+
* Body param: Amount of randomness injected into the response.
|
|
140
156
|
*
|
|
141
157
|
* Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
|
142
158
|
* for analytical / multiple choice, and closer to `1.0` for creative and
|
|
@@ -148,7 +164,7 @@ export interface CompletionCreateParamsBase {
|
|
|
148
164
|
temperature?: number;
|
|
149
165
|
|
|
150
166
|
/**
|
|
151
|
-
* Only sample from the top K options for each subsequent token.
|
|
167
|
+
* Body param: Only sample from the top K options for each subsequent token.
|
|
152
168
|
*
|
|
153
169
|
* Used to remove "long tail" low probability responses.
|
|
154
170
|
* [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
|
@@ -159,7 +175,7 @@ export interface CompletionCreateParamsBase {
|
|
|
159
175
|
top_k?: number;
|
|
160
176
|
|
|
161
177
|
/**
|
|
162
|
-
* Use nucleus sampling.
|
|
178
|
+
* Body param: Use nucleus sampling.
|
|
163
179
|
*
|
|
164
180
|
* In nucleus sampling, we compute the cumulative distribution over all the options
|
|
165
181
|
* for each subsequent token in decreasing probability order and cut it off once it
|
|
@@ -170,6 +186,11 @@ export interface CompletionCreateParamsBase {
|
|
|
170
186
|
* `temperature`.
|
|
171
187
|
*/
|
|
172
188
|
top_p?: number;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
192
|
+
*/
|
|
193
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
173
194
|
}
|
|
174
195
|
|
|
175
196
|
export namespace CompletionCreateParams {
|
|
@@ -184,7 +205,8 @@ export namespace CompletionCreateParams {
|
|
|
184
205
|
|
|
185
206
|
export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
|
|
186
207
|
/**
|
|
187
|
-
* Whether to incrementally stream the response using server-sent
|
|
208
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
209
|
+
* events.
|
|
188
210
|
*
|
|
189
211
|
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
190
212
|
*/
|
|
@@ -193,7 +215,8 @@ export interface CompletionCreateParamsNonStreaming extends CompletionCreatePara
|
|
|
193
215
|
|
|
194
216
|
export interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {
|
|
195
217
|
/**
|
|
196
|
-
* Whether to incrementally stream the response using server-sent
|
|
218
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
219
|
+
* events.
|
|
197
220
|
*
|
|
198
221
|
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
199
222
|
*/
|
package/src/resources/index.ts
CHANGED
|
@@ -34,8 +34,10 @@ export {
|
|
|
34
34
|
type CitationContentBlockLocationParam,
|
|
35
35
|
type CitationPageLocation,
|
|
36
36
|
type CitationPageLocationParam,
|
|
37
|
+
type CitationWebSearchResultLocationParam,
|
|
37
38
|
type CitationsConfigParam,
|
|
38
39
|
type CitationsDelta,
|
|
40
|
+
type CitationsWebSearchResultLocation,
|
|
39
41
|
type ContentBlock,
|
|
40
42
|
type ContentBlockParam,
|
|
41
43
|
type ContentBlockSource,
|
|
@@ -63,6 +65,9 @@ export {
|
|
|
63
65
|
type RawMessageStreamEvent,
|
|
64
66
|
type RedactedThinkingBlock,
|
|
65
67
|
type RedactedThinkingBlockParam,
|
|
68
|
+
type ServerToolUsage,
|
|
69
|
+
type ServerToolUseBlock,
|
|
70
|
+
type ServerToolUseBlockParam,
|
|
66
71
|
type SignatureDelta,
|
|
67
72
|
type StopReason,
|
|
68
73
|
type TextBlock,
|
|
@@ -91,6 +96,15 @@ export {
|
|
|
91
96
|
type URLImageSource,
|
|
92
97
|
type URLPDFSource,
|
|
93
98
|
type Usage,
|
|
99
|
+
type WebSearchResultBlock,
|
|
100
|
+
type WebSearchResultBlockParam,
|
|
101
|
+
type WebSearchTool20250305,
|
|
102
|
+
type WebSearchToolRequestError,
|
|
103
|
+
type WebSearchToolResultBlock,
|
|
104
|
+
type WebSearchToolResultBlockContent,
|
|
105
|
+
type WebSearchToolResultBlockParam,
|
|
106
|
+
type WebSearchToolResultBlockParamContent,
|
|
107
|
+
type WebSearchToolResultError,
|
|
94
108
|
type MessageStreamEvent,
|
|
95
109
|
type MessageStartEvent,
|
|
96
110
|
type MessageDeltaEvent,
|
|
@@ -103,4 +117,10 @@ export {
|
|
|
103
117
|
type MessageCreateParamsStreaming,
|
|
104
118
|
type MessageCountTokensParams,
|
|
105
119
|
} from "./messages/messages.js";
|
|
106
|
-
export {
|
|
120
|
+
export {
|
|
121
|
+
ModelInfosPage,
|
|
122
|
+
Models,
|
|
123
|
+
type ModelInfo,
|
|
124
|
+
type ModelRetrieveParams,
|
|
125
|
+
type ModelListParams,
|
|
126
|
+
} from "./models.js";
|
|
@@ -20,6 +20,24 @@ export class Batches extends APIResource {
|
|
|
20
20
|
*
|
|
21
21
|
* Learn more about the Message Batches API in our
|
|
22
22
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const messageBatch = await client.messages.batches.create({
|
|
27
|
+
* requests: [
|
|
28
|
+
* {
|
|
29
|
+
* custom_id: 'my-custom-id-1',
|
|
30
|
+
* params: {
|
|
31
|
+
* max_tokens: 1024,
|
|
32
|
+
* messages: [
|
|
33
|
+
* { content: 'Hello, world', role: 'user' },
|
|
34
|
+
* ],
|
|
35
|
+
* model: 'claude-3-7-sonnet-20250219',
|
|
36
|
+
* },
|
|
37
|
+
* },
|
|
38
|
+
* ],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
23
41
|
*/
|
|
24
42
|
create(body: BatchCreateParams, options?: Core.RequestOptions): Core.APIPromise<MessageBatch> {
|
|
25
43
|
return this._client.post('/v1/messages/batches', { body, ...options });
|
|
@@ -32,6 +50,13 @@ export class Batches extends APIResource {
|
|
|
32
50
|
*
|
|
33
51
|
* Learn more about the Message Batches API in our
|
|
34
52
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const messageBatch = await client.messages.batches.retrieve(
|
|
57
|
+
* 'message_batch_id',
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
35
60
|
*/
|
|
36
61
|
retrieve(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<MessageBatch> {
|
|
37
62
|
return this._client.get(`/v1/messages/batches/${messageBatchId}`, options);
|
|
@@ -43,6 +68,14 @@ export class Batches extends APIResource {
|
|
|
43
68
|
*
|
|
44
69
|
* Learn more about the Message Batches API in our
|
|
45
70
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // Automatically fetches more pages as needed.
|
|
75
|
+
* for await (const messageBatch of client.messages.batches.list()) {
|
|
76
|
+
* // ...
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
46
79
|
*/
|
|
47
80
|
list(
|
|
48
81
|
query?: BatchListParams,
|
|
@@ -67,6 +100,12 @@ export class Batches extends APIResource {
|
|
|
67
100
|
*
|
|
68
101
|
* Learn more about the Message Batches API in our
|
|
69
102
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const deletedMessageBatch =
|
|
107
|
+
* await client.messages.batches.delete('message_batch_id');
|
|
108
|
+
* ```
|
|
70
109
|
*/
|
|
71
110
|
delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<DeletedMessageBatch> {
|
|
72
111
|
return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options);
|
|
@@ -85,6 +124,13 @@ export class Batches extends APIResource {
|
|
|
85
124
|
*
|
|
86
125
|
* Learn more about the Message Batches API in our
|
|
87
126
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const messageBatch = await client.messages.batches.cancel(
|
|
131
|
+
* 'message_batch_id',
|
|
132
|
+
* );
|
|
133
|
+
* ```
|
|
88
134
|
*/
|
|
89
135
|
cancel(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<MessageBatch> {
|
|
90
136
|
return this._client.post(`/v1/messages/batches/${messageBatchId}/cancel`, options);
|
|
@@ -99,6 +145,12 @@ export class Batches extends APIResource {
|
|
|
99
145
|
*
|
|
100
146
|
* Learn more about the Message Batches API in our
|
|
101
147
|
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const messageBatchIndividualResponse =
|
|
152
|
+
* await client.messages.batches.results('message_batch_id');
|
|
153
|
+
* ```
|
|
102
154
|
*/
|
|
103
155
|
async results(
|
|
104
156
|
messageBatchId: string,
|
|
@@ -26,8 +26,10 @@ export {
|
|
|
26
26
|
type CitationContentBlockLocationParam,
|
|
27
27
|
type CitationPageLocation,
|
|
28
28
|
type CitationPageLocationParam,
|
|
29
|
+
type CitationWebSearchResultLocationParam,
|
|
29
30
|
type CitationsConfigParam,
|
|
30
31
|
type CitationsDelta,
|
|
32
|
+
type CitationsWebSearchResultLocation,
|
|
31
33
|
type ContentBlock,
|
|
32
34
|
type ContentBlockParam,
|
|
33
35
|
type ContentBlockSource,
|
|
@@ -53,6 +55,9 @@ export {
|
|
|
53
55
|
type RawMessageStreamEvent,
|
|
54
56
|
type RedactedThinkingBlock,
|
|
55
57
|
type RedactedThinkingBlockParam,
|
|
58
|
+
type ServerToolUsage,
|
|
59
|
+
type ServerToolUseBlock,
|
|
60
|
+
type ServerToolUseBlockParam,
|
|
56
61
|
type SignatureDelta,
|
|
57
62
|
type StopReason,
|
|
58
63
|
type TextBlock,
|
|
@@ -81,6 +86,15 @@ export {
|
|
|
81
86
|
type URLImageSource,
|
|
82
87
|
type URLPDFSource,
|
|
83
88
|
type Usage,
|
|
89
|
+
type WebSearchResultBlock,
|
|
90
|
+
type WebSearchResultBlockParam,
|
|
91
|
+
type WebSearchTool20250305,
|
|
92
|
+
type WebSearchToolRequestError,
|
|
93
|
+
type WebSearchToolResultBlock,
|
|
94
|
+
type WebSearchToolResultBlockContent,
|
|
95
|
+
type WebSearchToolResultBlockParam,
|
|
96
|
+
type WebSearchToolResultBlockParamContent,
|
|
97
|
+
type WebSearchToolResultError,
|
|
84
98
|
type MessageStreamEvent,
|
|
85
99
|
type MessageStartEvent,
|
|
86
100
|
type MessageDeltaEvent,
|