@anthropic-ai/sdk 0.21.0 → 0.22.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -1
  3. package/index.d.mts +12 -2
  4. package/index.d.ts +12 -2
  5. package/index.d.ts.map +1 -1
  6. package/index.js +0 -2
  7. package/index.js.map +1 -1
  8. package/index.mjs +0 -2
  9. package/index.mjs.map +1 -1
  10. package/lib/MessageStream.d.ts +3 -2
  11. package/lib/MessageStream.d.ts.map +1 -1
  12. package/lib/MessageStream.js +25 -2
  13. package/lib/MessageStream.js.map +1 -1
  14. package/lib/MessageStream.mjs +25 -2
  15. package/lib/MessageStream.mjs.map +1 -1
  16. package/package.json +2 -2
  17. package/resources/index.d.ts +1 -2
  18. package/resources/index.d.ts.map +1 -1
  19. package/resources/index.js +1 -3
  20. package/resources/index.js.map +1 -1
  21. package/resources/index.mjs +0 -1
  22. package/resources/index.mjs.map +1 -1
  23. package/resources/messages.d.ts +207 -213
  24. package/resources/messages.d.ts.map +1 -1
  25. package/resources/messages.js.map +1 -1
  26. package/resources/messages.mjs.map +1 -1
  27. package/src/_shims/auto/runtime-bun.ts +1 -1
  28. package/src/_shims/auto/runtime-node.ts +1 -1
  29. package/src/_shims/auto/runtime.ts +1 -1
  30. package/src/_shims/auto/types-node.ts +1 -1
  31. package/src/_shims/bun-runtime.ts +2 -2
  32. package/src/_shims/index.d.ts +3 -3
  33. package/src/_shims/index.mjs +1 -1
  34. package/src/_shims/node-runtime.ts +3 -3
  35. package/src/_shims/registry.ts +1 -1
  36. package/src/_shims/web-runtime.ts +3 -3
  37. package/src/core.ts +6 -6
  38. package/src/error.ts +1 -1
  39. package/src/index.ts +17 -8
  40. package/src/lib/MessageStream.ts +36 -10
  41. package/src/resource.ts +1 -1
  42. package/src/resources/completions.ts +5 -5
  43. package/src/resources/index.ts +14 -3
  44. package/src/resources/messages.ts +267 -254
  45. package/src/shims/node.ts +3 -3
  46. package/src/shims/web.ts +3 -3
  47. package/src/streaming.ts +4 -4
  48. package/src/uploads.ts +4 -4
  49. package/src/version.ts +1 -1
  50. package/version.d.ts +1 -1
  51. package/version.js +1 -1
  52. package/version.mjs +1 -1
  53. package/lib/ToolsBetaMessageStream.d.ts +0 -95
  54. package/lib/ToolsBetaMessageStream.d.ts.map +0 -1
  55. package/lib/ToolsBetaMessageStream.js +0 -459
  56. package/lib/ToolsBetaMessageStream.js.map +0 -1
  57. package/lib/ToolsBetaMessageStream.mjs +0 -455
  58. package/lib/ToolsBetaMessageStream.mjs.map +0 -1
  59. package/resources/beta/beta.d.ts +0 -9
  60. package/resources/beta/beta.d.ts.map +0 -1
  61. package/resources/beta/beta.js +0 -40
  62. package/resources/beta/beta.js.map +0 -1
  63. package/resources/beta/beta.mjs +0 -13
  64. package/resources/beta/beta.mjs.map +0 -1
  65. package/resources/beta/index.d.ts +0 -3
  66. package/resources/beta/index.d.ts.map +0 -1
  67. package/resources/beta/index.js +0 -9
  68. package/resources/beta/index.js.map +0 -1
  69. package/resources/beta/index.mjs +0 -4
  70. package/resources/beta/index.mjs.map +0 -1
  71. package/resources/beta/tools/index.d.ts +0 -3
  72. package/resources/beta/tools/index.d.ts.map +0 -1
  73. package/resources/beta/tools/index.js +0 -9
  74. package/resources/beta/tools/index.js.map +0 -1
  75. package/resources/beta/tools/index.mjs +0 -4
  76. package/resources/beta/tools/index.mjs.map +0 -1
  77. package/resources/beta/tools/messages.d.ts +0 -793
  78. package/resources/beta/tools/messages.d.ts.map +0 -1
  79. package/resources/beta/tools/messages.js +0 -29
  80. package/resources/beta/tools/messages.js.map +0 -1
  81. package/resources/beta/tools/messages.mjs +0 -24
  82. package/resources/beta/tools/messages.mjs.map +0 -1
  83. package/resources/beta/tools/tools.d.ts +0 -24
  84. package/resources/beta/tools/tools.d.ts.map +0 -1
  85. package/resources/beta/tools/tools.js +0 -40
  86. package/resources/beta/tools/tools.js.map +0 -1
  87. package/resources/beta/tools/tools.mjs +0 -13
  88. package/resources/beta/tools/tools.mjs.map +0 -1
  89. package/src/lib/ToolsBetaMessageStream.ts +0 -561
  90. package/src/resources/beta/beta.ts +0 -12
  91. package/src/resources/beta/index.ts +0 -4
  92. package/src/resources/beta/tools/index.ts +0 -21
  93. package/src/resources/beta/tools/messages.ts +0 -907
  94. package/src/resources/beta/tools/tools.ts +0 -27
@@ -1,12 +1,12 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import * as Core from "../core";
4
- import { APIPromise } from "../core";
5
- import { APIResource } from "../resource";
6
- import { MessageStream } from "../lib/MessageStream";
7
- export { MessageStream } from "../lib/MessageStream";
8
- import * as MessagesAPI from "./messages";
9
- import { Stream } from "../streaming";
3
+ import * as Core from "../core.js";
4
+ import { APIPromise } from "../core.js";
5
+ import { APIResource } from "../resource.js";
6
+ import { MessageStream } from "../lib/MessageStream.js";
7
+ export { MessageStream } from "../lib/MessageStream.js";
8
+ import * as MessagesAPI from "./messages.js";
9
+ import { Stream } from "../streaming.js";
10
10
 
11
11
  export class Messages extends APIResource {
12
12
  /**
@@ -15,28 +15,28 @@ export class Messages extends APIResource {
15
15
  * Send a structured list of input messages with text and/or image content, and the
16
16
  * model will generate the next message in the conversation.
17
17
  *
18
- * The Messages API can be used for for either single queries or stateless
19
- * multi-turn conversations.
18
+ * The Messages API can be used for either single queries or stateless multi-turn
19
+ * conversations.
20
20
  */
21
21
  create(body: MessageCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Message>;
22
22
  create(
23
23
  body: MessageCreateParamsStreaming,
24
24
  options?: Core.RequestOptions,
25
- ): APIPromise<Stream<MessageStreamEvent>>;
25
+ ): APIPromise<Stream<RawMessageStreamEvent>>;
26
26
  create(
27
27
  body: MessageCreateParamsBase,
28
28
  options?: Core.RequestOptions,
29
- ): APIPromise<Stream<MessageStreamEvent> | Message>;
29
+ ): APIPromise<Stream<RawMessageStreamEvent> | Message>;
30
30
  create(
31
31
  body: MessageCreateParams,
32
32
  options?: Core.RequestOptions,
33
- ): APIPromise<Message> | APIPromise<Stream<MessageStreamEvent>> {
33
+ ): APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>> {
34
34
  return this._client.post('/v1/messages', {
35
35
  body,
36
36
  timeout: 600000,
37
37
  ...options,
38
38
  stream: body.stream ?? false,
39
- }) as APIPromise<Message> | APIPromise<Stream<MessageStreamEvent>>;
39
+ }) as APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>>;
40
40
  }
41
41
 
42
42
  /**
@@ -47,29 +47,13 @@ export class Messages extends APIResource {
47
47
  }
48
48
  }
49
49
 
50
- export type ContentBlock = TextBlock;
50
+ export type ContentBlock = TextBlock | ToolUseBlock;
51
51
 
52
- export interface ContentBlockDeltaEvent {
53
- delta: TextDelta;
52
+ export type ContentBlockDeltaEvent = RawContentBlockDeltaEvent;
54
53
 
55
- index: number;
56
-
57
- type: 'content_block_delta';
58
- }
59
-
60
- export interface ContentBlockStartEvent {
61
- content_block: TextBlock;
54
+ export type ContentBlockStartEvent = RawContentBlockStartEvent;
62
55
 
63
- index: number;
64
-
65
- type: 'content_block_start';
66
- }
67
-
68
- export interface ContentBlockStopEvent {
69
- index: number;
70
-
71
- type: 'content_block_stop';
72
- }
56
+ export type ContentBlockStopEvent = RawContentBlockStopEvent;
73
57
 
74
58
  export interface ImageBlockParam {
75
59
  source: ImageBlockParam.Source;
@@ -87,6 +71,12 @@ export namespace ImageBlockParam {
87
71
  }
88
72
  }
89
73
 
74
+ export interface InputJsonDelta {
75
+ partial_json: string;
76
+
77
+ type: 'input_json_delta';
78
+ }
79
+
90
80
  export interface Message {
91
81
  /**
92
82
  * Unique object identifier.
@@ -99,7 +89,7 @@ export interface Message {
99
89
  * Content generated by the model.
100
90
  *
101
91
  * This is an array of content blocks, each of which has a `type` that determines
102
- * its shape. Currently, the only `type` in responses is `"text"`.
92
+ * its shape.
103
93
  *
104
94
  * Example:
105
95
  *
@@ -129,7 +119,7 @@ export interface Message {
129
119
  * [{ "type": "text", "text": "B)" }]
130
120
  * ```
131
121
  */
132
- content: Array<TextBlock>;
122
+ content: Array<ContentBlock>;
133
123
 
134
124
  /**
135
125
  * The model that handled the request.
@@ -151,11 +141,12 @@ export interface Message {
151
141
  * - `"end_turn"`: the model reached a natural stopping point
152
142
  * - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
153
143
  * - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
144
+ * - `"tool_use"`: the model invoked one or more tools
154
145
  *
155
146
  * In non-streaming mode this value is always non-null. In streaming mode, it is
156
147
  * null in the `message_start` event and non-null otherwise.
157
148
  */
158
- stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
149
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
159
150
 
160
151
  /**
161
152
  * Which custom stop sequence was generated, if any.
@@ -189,8 +180,51 @@ export interface Message {
189
180
  usage: Usage;
190
181
  }
191
182
 
192
- export interface MessageDeltaEvent {
193
- delta: MessageDeltaEvent.Delta;
183
+ export type MessageDeltaEvent = RawMessageDeltaEvent;
184
+
185
+ export interface MessageDeltaUsage {
186
+ /**
187
+ * The cumulative number of output tokens which were used.
188
+ */
189
+ output_tokens: number;
190
+ }
191
+
192
+ export interface MessageParam {
193
+ content: string | Array<TextBlockParam | ImageBlockParam | ToolUseBlockParam | ToolResultBlockParam>;
194
+
195
+ role: 'user' | 'assistant';
196
+ }
197
+
198
+ export type MessageStartEvent = RawMessageStartEvent;
199
+
200
+ export type MessageStopEvent = RawMessageStopEvent;
201
+
202
+ export type MessageStreamEvent = RawMessageStreamEvent;
203
+
204
+ export interface RawContentBlockDeltaEvent {
205
+ delta: TextDelta | InputJsonDelta;
206
+
207
+ index: number;
208
+
209
+ type: 'content_block_delta';
210
+ }
211
+
212
+ export interface RawContentBlockStartEvent {
213
+ content_block: TextBlock | ToolUseBlock;
214
+
215
+ index: number;
216
+
217
+ type: 'content_block_start';
218
+ }
219
+
220
+ export interface RawContentBlockStopEvent {
221
+ index: number;
222
+
223
+ type: 'content_block_stop';
224
+ }
225
+
226
+ export interface RawMessageDeltaEvent {
227
+ delta: RawMessageDeltaEvent.Delta;
194
228
 
195
229
  type: 'message_delta';
196
230
 
@@ -211,44 +245,31 @@ export interface MessageDeltaEvent {
211
245
  usage: MessageDeltaUsage;
212
246
  }
213
247
 
214
- export namespace MessageDeltaEvent {
248
+ export namespace RawMessageDeltaEvent {
215
249
  export interface Delta {
216
- stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
250
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
217
251
 
218
252
  stop_sequence: string | null;
219
253
  }
220
254
  }
221
255
 
222
- export interface MessageDeltaUsage {
223
- /**
224
- * The cumulative number of output tokens which were used.
225
- */
226
- output_tokens: number;
227
- }
228
-
229
- export interface MessageParam {
230
- content: string | Array<TextBlockParam | ImageBlockParam>;
231
-
232
- role: 'user' | 'assistant';
233
- }
234
-
235
- export interface MessageStartEvent {
256
+ export interface RawMessageStartEvent {
236
257
  message: Message;
237
258
 
238
259
  type: 'message_start';
239
260
  }
240
261
 
241
- export interface MessageStopEvent {
262
+ export interface RawMessageStopEvent {
242
263
  type: 'message_stop';
243
264
  }
244
265
 
245
- export type MessageStreamEvent =
246
- | MessageStartEvent
247
- | MessageDeltaEvent
248
- | MessageStopEvent
249
- | ContentBlockStartEvent
250
- | ContentBlockDeltaEvent
251
- | ContentBlockStopEvent;
266
+ export type RawMessageStreamEvent =
267
+ | RawMessageStartEvent
268
+ | RawMessageDeltaEvent
269
+ | RawMessageStopEvent
270
+ | RawContentBlockStartEvent
271
+ | RawContentBlockDeltaEvent
272
+ | RawContentBlockStopEvent;
252
273
 
253
274
  export interface TextBlock {
254
275
  text: string;
@@ -268,6 +289,73 @@ export interface TextDelta {
268
289
  type: 'text_delta';
269
290
  }
270
291
 
292
+ export interface Tool {
293
+ /**
294
+ * [JSON schema](https://json-schema.org/) for this tool's input.
295
+ *
296
+ * This defines the shape of the `input` that your tool accepts and that the model
297
+ * will produce.
298
+ */
299
+ input_schema: Tool.InputSchema;
300
+
301
+ name: string;
302
+
303
+ /**
304
+ * Description of what this tool does.
305
+ *
306
+ * Tool descriptions should be as detailed as possible. The more information that
307
+ * the model has about what the tool is and how to use it, the better it will
308
+ * perform. You can use natural language descriptions to reinforce important
309
+ * aspects of the tool input JSON schema.
310
+ */
311
+ description?: string;
312
+ }
313
+
314
+ export namespace Tool {
315
+ /**
316
+ * [JSON schema](https://json-schema.org/) for this tool's input.
317
+ *
318
+ * This defines the shape of the `input` that your tool accepts and that the model
319
+ * will produce.
320
+ */
321
+ export interface InputSchema {
322
+ type: 'object';
323
+
324
+ properties?: unknown | null;
325
+ [k: string]: unknown;
326
+ }
327
+ }
328
+
329
+ export interface ToolResultBlockParam {
330
+ tool_use_id: string;
331
+
332
+ type: 'tool_result';
333
+
334
+ content?: Array<TextBlockParam | ImageBlockParam>;
335
+
336
+ is_error?: boolean;
337
+ }
338
+
339
+ export interface ToolUseBlock {
340
+ id: string;
341
+
342
+ input: unknown;
343
+
344
+ name: string;
345
+
346
+ type: 'tool_use';
347
+ }
348
+
349
+ export interface ToolUseBlockParam {
350
+ id: string;
351
+
352
+ input: unknown;
353
+
354
+ name: string;
355
+
356
+ type: 'tool_use';
357
+ }
358
+
271
359
  export interface Usage {
272
360
  /**
273
361
  * The number of input tokens which were used.
@@ -446,223 +534,85 @@ export interface MessageCreateParamsBase {
446
534
  temperature?: number;
447
535
 
448
536
  /**
449
- * Only sample from the top K options for each subsequent token.
450
- *
451
- * Used to remove "long tail" low probability responses.
452
- * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
453
- *
454
- * Recommended for advanced use cases only. You usually only need to use
455
- * `temperature`.
537
+ * How the model should use the provided tools. The model can use a specific tool,
538
+ * any available tool, or decide by itself.
456
539
  */
457
- top_k?: number;
458
-
459
- /**
460
- * Use nucleus sampling.
461
- *
462
- * In nucleus sampling, we compute the cumulative distribution over all the options
463
- * for each subsequent token in decreasing probability order and cut it off once it
464
- * reaches a particular probability specified by `top_p`. You should either alter
465
- * `temperature` or `top_p`, but not both.
466
- *
467
- * Recommended for advanced use cases only. You usually only need to use
468
- * `temperature`.
469
- */
470
- top_p?: number;
471
- }
472
-
473
- export namespace MessageCreateParams {
474
- /**
475
- * An object describing metadata about the request.
476
- */
477
- export interface Metadata {
478
- /**
479
- * An external identifier for the user who is associated with the request.
480
- *
481
- * This should be a uuid, hash value, or other opaque identifier. Anthropic may use
482
- * this id to help detect abuse. Do not include any identifying information such as
483
- * name, email address, or phone number.
484
- */
485
- user_id?: string | null;
486
- }
540
+ tool_choice?:
541
+ | MessageCreateParams.ToolChoiceAuto
542
+ | MessageCreateParams.ToolChoiceAny
543
+ | MessageCreateParams.ToolChoiceTool;
487
544
 
488
- export type MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;
489
- export type MessageCreateParamsStreaming = MessagesAPI.MessageCreateParamsStreaming;
490
- }
491
-
492
- export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
493
545
  /**
494
- * Whether to incrementally stream the response using server-sent events.
546
+ * Definitions of tools that the model may use.
495
547
  *
496
- * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
497
- * details.
498
- */
499
- stream?: false;
500
- }
501
-
502
- export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
503
- /**
504
- * Whether to incrementally stream the response using server-sent events.
548
+ * If you include `tools` in your API request, the model may return `tool_use`
549
+ * content blocks that represent the model's use of those tools. You can then run
550
+ * those tools using the tool input generated by the model and then optionally
551
+ * return results back to the model using `tool_result` content blocks.
505
552
  *
506
- * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
507
- * details.
508
- */
509
- stream: true;
510
- }
511
-
512
- export interface MessageStreamParams {
513
- /**
514
- * The maximum number of tokens to generate before stopping.
553
+ * Each tool definition includes:
515
554
  *
516
- * Note that our models may stop _before_ reaching this maximum. This parameter
517
- * only specifies the absolute maximum number of tokens to generate.
555
+ * - `name`: Name of the tool.
556
+ * - `description`: Optional, but strongly-recommended description of the tool.
557
+ * - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
558
+ * shape that the model will produce in `tool_use` output content blocks.
518
559
  *
519
- * Different models have different maximum values for this parameter. See
520
- * [models](https://docs.anthropic.com/en/docs/models-overview) for details.
521
- */
522
- max_tokens: number;
523
-
524
- /**
525
- * Input messages.
526
- *
527
- * Our models are trained to operate on alternating `user` and `assistant`
528
- * conversational turns. When creating a new `Message`, you specify the prior
529
- * conversational turns with the `messages` parameter, and the model then generates
530
- * the next `Message` in the conversation.
531
- *
532
- * Each input message must be an object with a `role` and `content`. You can
533
- * specify a single `user`-role message, or you can include multiple `user` and
534
- * `assistant` messages. The first message must always use the `user` role.
535
- *
536
- * If the final message uses the `assistant` role, the response content will
537
- * continue immediately from the content in that message. This can be used to
538
- * constrain part of the model's response.
539
- *
540
- * Example with a single `user` message:
541
- *
542
- * ```json
543
- * [{ "role": "user", "content": "Hello, Claude" }]
544
- * ```
545
- *
546
- * Example with multiple conversational turns:
560
+ * For example, if you defined `tools` as:
547
561
  *
548
562
  * ```json
549
563
  * [
550
- * { "role": "user", "content": "Hello there." },
551
- * { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
552
- * { "role": "user", "content": "Can you explain LLMs in plain English?" }
564
+ * {
565
+ * "name": "get_stock_price",
566
+ * "description": "Get the current stock price for a given ticker symbol.",
567
+ * "input_schema": {
568
+ * "type": "object",
569
+ * "properties": {
570
+ * "ticker": {
571
+ * "type": "string",
572
+ * "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
573
+ * }
574
+ * },
575
+ * "required": ["ticker"]
576
+ * }
577
+ * }
553
578
  * ]
554
579
  * ```
555
580
  *
556
- * Example with a partially-filled response from Claude:
581
+ * And then asked the model "What's the S&P 500 at today?", the model might produce
582
+ * `tool_use` content blocks in the response like this:
557
583
  *
558
584
  * ```json
559
585
  * [
560
586
  * {
561
- * "role": "user",
562
- * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
563
- * },
564
- * { "role": "assistant", "content": "The best answer is (" }
587
+ * "type": "tool_use",
588
+ * "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
589
+ * "name": "get_stock_price",
590
+ * "input": { "ticker": "^GSPC" }
591
+ * }
565
592
  * ]
566
593
  * ```
567
594
  *
568
- * Each input message `content` may be either a single `string` or an array of
569
- * content blocks, where each block has a specific `type`. Using a `string` for
570
- * `content` is shorthand for an array of one content block of type `"text"`. The
571
- * following input messages are equivalent:
572
- *
573
- * ```json
574
- * { "role": "user", "content": "Hello, Claude" }
575
- * ```
576
- *
577
- * ```json
578
- * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
579
- * ```
580
- *
581
- * Starting with Claude 3 models, you can also send image content blocks:
595
+ * You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
596
+ * input, and return the following back to the model in a subsequent `user`
597
+ * message:
582
598
  *
583
599
  * ```json
584
- * {
585
- * "role": "user",
586
- * "content": [
587
- * {
588
- * "type": "image",
589
- * "source": {
590
- * "type": "base64",
591
- * "media_type": "image/jpeg",
592
- * "data": "/9j/4AAQSkZJRg..."
593
- * }
594
- * },
595
- * { "type": "text", "text": "What is in this image?" }
596
- * ]
597
- * }
600
+ * [
601
+ * {
602
+ * "type": "tool_result",
603
+ * "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
604
+ * "content": "259.75 USD"
605
+ * }
606
+ * ]
598
607
  * ```
599
608
  *
600
- * We currently support the `base64` source type for images, and the `image/jpeg`,
601
- * `image/png`, `image/gif`, and `image/webp` media types.
602
- *
603
- * See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
604
- * input examples.
605
- *
606
- * Note that if you want to include a
607
- * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
608
- * the top-level `system` parameter — there is no `"system"` role for input
609
- * messages in the Messages API.
610
- */
611
- messages: Array<MessageParam>;
612
-
613
- /**
614
- * The model that will complete your prompt.
615
- *
616
- * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
617
- * details and options.
618
- */
619
- model:
620
- | (string & {})
621
- | 'claude-3-opus-20240229'
622
- | 'claude-3-sonnet-20240229'
623
- | 'claude-3-haiku-20240307'
624
- | 'claude-2.1'
625
- | 'claude-2.0'
626
- | 'claude-instant-1.2';
627
-
628
- /**
629
- * An object describing metadata about the request.
630
- */
631
- metadata?: MessageStreamParams.Metadata;
632
-
633
- /**
634
- * Custom text sequences that will cause the model to stop generating.
635
- *
636
- * Our models will normally stop when they have naturally completed their turn,
637
- * which will result in a response `stop_reason` of `"end_turn"`.
609
+ * Tools can be used for workflows that include running client-side tools and
610
+ * functions, or more generally whenever you want the model to produce a particular
611
+ * JSON structure of output.
638
612
  *
639
- * If you want the model to stop generating when it encounters custom strings of
640
- * text, you can use the `stop_sequences` parameter. If the model encounters one of
641
- * the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
642
- * and the response `stop_sequence` value will contain the matched stop sequence.
643
- */
644
- stop_sequences?: Array<string>;
645
-
646
- /**
647
- * System prompt.
648
- *
649
- * A system prompt is a way of providing context and instructions to Claude, such
650
- * as specifying a particular goal or role. See our
651
- * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
652
- */
653
- system?: string;
654
-
655
- /**
656
- * Amount of randomness injected into the response.
657
- *
658
- * Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
659
- * for analytical / multiple choice, and closer to `1.0` for creative and
660
- * generative tasks.
661
- *
662
- * Note that even with `temperature` of `0.0`, the results will not be fully
663
- * deterministic.
613
+ * See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
664
614
  */
665
- temperature?: number;
615
+ tools?: Array<Tool>;
666
616
 
667
617
  /**
668
618
  * Only sample from the top K options for each subsequent token.
@@ -689,7 +639,7 @@ export interface MessageStreamParams {
689
639
  top_p?: number;
690
640
  }
691
641
 
692
- export namespace MessageStreamParams {
642
+ export namespace MessageCreateParams {
693
643
  /**
694
644
  * An object describing metadata about the request.
695
645
  */
@@ -703,14 +653,66 @@ export namespace MessageStreamParams {
703
653
  */
704
654
  user_id?: string | null;
705
655
  }
656
+
657
+ /**
658
+ * The model will automatically decide whether to use tools.
659
+ */
660
+ export interface ToolChoiceAuto {
661
+ type: 'auto';
662
+ }
663
+
664
+ /**
665
+ * The model will use any available tools.
666
+ */
667
+ export interface ToolChoiceAny {
668
+ type: 'any';
669
+ }
670
+
671
+ /**
672
+ * The model will use the specified tool with `tool_choice.name`.
673
+ */
674
+ export interface ToolChoiceTool {
675
+ /**
676
+ * The name of the tool to use.
677
+ */
678
+ name: string;
679
+
680
+ type: 'tool';
681
+ }
682
+
683
+ export type MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;
684
+ export type MessageCreateParamsStreaming = MessagesAPI.MessageCreateParamsStreaming;
706
685
  }
707
686
 
687
+ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
688
+ /**
689
+ * Whether to incrementally stream the response using server-sent events.
690
+ *
691
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
692
+ * details.
693
+ */
694
+ stream?: false;
695
+ }
696
+
697
+ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
698
+ /**
699
+ * Whether to incrementally stream the response using server-sent events.
700
+ *
701
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
702
+ * details.
703
+ */
704
+ stream: true;
705
+ }
706
+
707
+ export type MessageStreamParams = MessageCreateParamsBase;
708
+
708
709
  export namespace Messages {
709
710
  export import ContentBlock = MessagesAPI.ContentBlock;
710
711
  export import ContentBlockDeltaEvent = MessagesAPI.ContentBlockDeltaEvent;
711
712
  export import ContentBlockStartEvent = MessagesAPI.ContentBlockStartEvent;
712
713
  export import ContentBlockStopEvent = MessagesAPI.ContentBlockStopEvent;
713
714
  export import ImageBlockParam = MessagesAPI.ImageBlockParam;
715
+ export import InputJsonDelta = MessagesAPI.InputJsonDelta;
714
716
  export import Message = MessagesAPI.Message;
715
717
  export import MessageDeltaEvent = MessagesAPI.MessageDeltaEvent;
716
718
  export import MessageDeltaUsage = MessagesAPI.MessageDeltaUsage;
@@ -718,9 +720,20 @@ export namespace Messages {
718
720
  export import MessageStartEvent = MessagesAPI.MessageStartEvent;
719
721
  export import MessageStopEvent = MessagesAPI.MessageStopEvent;
720
722
  export import MessageStreamEvent = MessagesAPI.MessageStreamEvent;
723
+ export import RawContentBlockDeltaEvent = MessagesAPI.RawContentBlockDeltaEvent;
724
+ export import RawContentBlockStartEvent = MessagesAPI.RawContentBlockStartEvent;
725
+ export import RawContentBlockStopEvent = MessagesAPI.RawContentBlockStopEvent;
726
+ export import RawMessageDeltaEvent = MessagesAPI.RawMessageDeltaEvent;
727
+ export import RawMessageStartEvent = MessagesAPI.RawMessageStartEvent;
728
+ export import RawMessageStopEvent = MessagesAPI.RawMessageStopEvent;
729
+ export import RawMessageStreamEvent = MessagesAPI.RawMessageStreamEvent;
721
730
  export import TextBlock = MessagesAPI.TextBlock;
722
731
  export import TextBlockParam = MessagesAPI.TextBlockParam;
723
732
  export import TextDelta = MessagesAPI.TextDelta;
733
+ export import Tool = MessagesAPI.Tool;
734
+ export import ToolResultBlockParam = MessagesAPI.ToolResultBlockParam;
735
+ export import ToolUseBlock = MessagesAPI.ToolUseBlock;
736
+ export import ToolUseBlockParam = MessagesAPI.ToolUseBlockParam;
724
737
  export import Usage = MessagesAPI.Usage;
725
738
  export import MessageCreateParams = MessagesAPI.MessageCreateParams;
726
739
  export import MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;