@anthropic-ai/sdk 0.28.0 → 0.29.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 (107) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +76 -0
  3. package/core.d.ts +1 -1
  4. package/core.d.ts.map +1 -1
  5. package/core.js +1 -1
  6. package/core.js.map +1 -1
  7. package/core.mjs +1 -1
  8. package/core.mjs.map +1 -1
  9. package/index.d.mts +19 -0
  10. package/index.d.ts +19 -0
  11. package/index.d.ts.map +1 -1
  12. package/index.js +2 -0
  13. package/index.js.map +1 -1
  14. package/index.mjs +2 -0
  15. package/index.mjs.map +1 -1
  16. package/internal/decoders/jsonl.d.ts +12 -0
  17. package/internal/decoders/jsonl.d.ts.map +1 -0
  18. package/internal/decoders/jsonl.js +35 -0
  19. package/internal/decoders/jsonl.js.map +1 -0
  20. package/internal/decoders/jsonl.mjs +31 -0
  21. package/internal/decoders/jsonl.mjs.map +1 -0
  22. package/internal/decoders/line.d.ts +20 -0
  23. package/internal/decoders/line.d.ts.map +1 -0
  24. package/internal/decoders/line.js +88 -0
  25. package/internal/decoders/line.js.map +1 -0
  26. package/internal/decoders/line.mjs +84 -0
  27. package/internal/decoders/line.mjs.map +1 -0
  28. package/package.json +1 -1
  29. package/pagination.d.ts +26 -0
  30. package/pagination.d.ts.map +1 -0
  31. package/pagination.js +54 -0
  32. package/pagination.js.map +1 -0
  33. package/pagination.mjs +50 -0
  34. package/pagination.mjs.map +1 -0
  35. package/resources/beta/beta.d.ts +79 -0
  36. package/resources/beta/beta.d.ts.map +1 -1
  37. package/resources/beta/beta.js +3 -0
  38. package/resources/beta/beta.js.map +1 -1
  39. package/resources/beta/beta.mjs +3 -0
  40. package/resources/beta/beta.mjs.map +1 -1
  41. package/resources/beta/index.d.ts +2 -1
  42. package/resources/beta/index.d.ts.map +1 -1
  43. package/resources/beta/index.js +5 -3
  44. package/resources/beta/index.js.map +1 -1
  45. package/resources/beta/index.mjs +2 -1
  46. package/resources/beta/index.mjs.map +1 -1
  47. package/resources/beta/messages/batches.d.ts +242 -0
  48. package/resources/beta/messages/batches.d.ts.map +1 -0
  49. package/resources/beta/messages/batches.js +120 -0
  50. package/resources/beta/messages/batches.js.map +1 -0
  51. package/resources/beta/messages/batches.mjs +92 -0
  52. package/resources/beta/messages/batches.mjs.map +1 -0
  53. package/resources/beta/messages/index.d.ts +3 -0
  54. package/resources/beta/messages/index.d.ts.map +1 -0
  55. package/resources/beta/messages/index.js +10 -0
  56. package/resources/beta/messages/index.js.map +1 -0
  57. package/resources/beta/messages/index.mjs +4 -0
  58. package/resources/beta/messages/index.mjs.map +1 -0
  59. package/resources/beta/messages/messages.d.ts +663 -0
  60. package/resources/beta/messages/messages.d.ts.map +1 -0
  61. package/resources/beta/messages/messages.js +54 -0
  62. package/resources/beta/messages/messages.js.map +1 -0
  63. package/resources/beta/messages/messages.mjs +27 -0
  64. package/resources/beta/messages/messages.mjs.map +1 -0
  65. package/resources/beta/prompt-caching/messages.d.ts +40 -74
  66. package/resources/beta/prompt-caching/messages.d.ts.map +1 -1
  67. package/resources/beta/prompt-caching/messages.js +7 -3
  68. package/resources/beta/prompt-caching/messages.js.map +1 -1
  69. package/resources/beta/prompt-caching/messages.mjs +7 -3
  70. package/resources/beta/prompt-caching/messages.mjs.map +1 -1
  71. package/resources/completions.d.ts +3 -12
  72. package/resources/completions.d.ts.map +1 -1
  73. package/resources/completions.js.map +1 -1
  74. package/resources/completions.mjs.map +1 -1
  75. package/resources/index.d.ts +2 -2
  76. package/resources/index.d.ts.map +1 -1
  77. package/resources/index.js.map +1 -1
  78. package/resources/index.mjs +1 -1
  79. package/resources/index.mjs.map +1 -1
  80. package/resources/messages.d.ts +76 -55
  81. package/resources/messages.d.ts.map +1 -1
  82. package/resources/messages.js.map +1 -1
  83. package/resources/messages.mjs.map +1 -1
  84. package/src/core.ts +4 -2
  85. package/src/index.ts +20 -0
  86. package/src/internal/decoders/jsonl.ts +41 -0
  87. package/src/internal/decoders/line.ts +114 -0
  88. package/src/pagination.ts +84 -0
  89. package/src/resources/beta/beta.ts +104 -0
  90. package/src/resources/beta/index.ts +47 -1
  91. package/src/resources/beta/messages/batches.ts +393 -0
  92. package/src/resources/beta/messages/index.ts +53 -0
  93. package/src/resources/beta/messages/messages.ts +795 -0
  94. package/src/resources/beta/prompt-caching/messages.ts +45 -81
  95. package/src/resources/completions.ts +3 -12
  96. package/src/resources/index.ts +18 -1
  97. package/src/resources/messages.ts +82 -59
  98. package/src/streaming.ts +1 -111
  99. package/src/version.ts +1 -1
  100. package/streaming.d.ts.map +1 -1
  101. package/streaming.js +4 -85
  102. package/streaming.js.map +1 -1
  103. package/streaming.mjs +1 -82
  104. package/streaming.mjs.map +1 -1
  105. package/version.d.ts +1 -1
  106. package/version.js +1 -1
  107. package/version.mjs +1 -1
@@ -0,0 +1,795 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../../resource.js";
4
+ import { APIPromise } from "../../../core.js";
5
+ import * as Core from "../../../core.js";
6
+ import * as MessagesMessagesAPI from "./messages.js";
7
+ import * as MessagesAPI from "../../messages.js";
8
+ import * as BetaAPI from "../beta.js";
9
+ import * as BatchesAPI from "./batches.js";
10
+ import { Stream } from "../../../streaming.js";
11
+
12
+ export class Messages extends APIResource {
13
+ batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
14
+
15
+ /**
16
+ * Send a structured list of input messages with text and/or image content, and the
17
+ * model will generate the next message in the conversation.
18
+ *
19
+ * The Messages API can be used for either single queries or stateless multi-turn
20
+ * conversations.
21
+ */
22
+ create(params: MessageCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<BetaMessage>;
23
+ create(
24
+ params: MessageCreateParamsStreaming,
25
+ options?: Core.RequestOptions,
26
+ ): APIPromise<Stream<BetaRawMessageStreamEvent>>;
27
+ create(
28
+ params: MessageCreateParamsBase,
29
+ options?: Core.RequestOptions,
30
+ ): APIPromise<Stream<BetaRawMessageStreamEvent> | BetaMessage>;
31
+ create(
32
+ params: MessageCreateParams,
33
+ options?: Core.RequestOptions,
34
+ ): APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>> {
35
+ const { betas, ...body } = params;
36
+ return this._client.post('/v1/messages?beta=true', {
37
+ body,
38
+ timeout: (this._client as any)._options.timeout ?? 600000,
39
+ ...options,
40
+ headers: {
41
+ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
42
+ ...options?.headers,
43
+ },
44
+ stream: params.stream ?? false,
45
+ }) as APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>>;
46
+ }
47
+ }
48
+
49
+ export interface BetaCacheControlEphemeral {
50
+ type: 'ephemeral';
51
+ }
52
+
53
+ export type BetaContentBlock = BetaTextBlock | BetaToolUseBlock;
54
+
55
+ export type BetaContentBlockParam =
56
+ | BetaTextBlockParam
57
+ | BetaImageBlockParam
58
+ | BetaToolUseBlockParam
59
+ | BetaToolResultBlockParam;
60
+
61
+ export interface BetaImageBlockParam {
62
+ source: BetaImageBlockParam.Source;
63
+
64
+ type: 'image';
65
+
66
+ cache_control?: BetaCacheControlEphemeral | null;
67
+ }
68
+
69
+ export namespace BetaImageBlockParam {
70
+ export interface Source {
71
+ data: string;
72
+
73
+ media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
74
+
75
+ type: 'base64';
76
+ }
77
+ }
78
+
79
+ export interface BetaInputJSONDelta {
80
+ partial_json: string;
81
+
82
+ type: 'input_json_delta';
83
+ }
84
+
85
+ export interface BetaMessage {
86
+ /**
87
+ * Unique object identifier.
88
+ *
89
+ * The format and length of IDs may change over time.
90
+ */
91
+ id: string;
92
+
93
+ /**
94
+ * Content generated by the model.
95
+ *
96
+ * This is an array of content blocks, each of which has a `type` that determines
97
+ * its shape.
98
+ *
99
+ * Example:
100
+ *
101
+ * ```json
102
+ * [{ "type": "text", "text": "Hi, I'm Claude." }]
103
+ * ```
104
+ *
105
+ * If the request input `messages` ended with an `assistant` turn, then the
106
+ * response `content` will continue directly from that last turn. You can use this
107
+ * to constrain the model's output.
108
+ *
109
+ * For example, if the input `messages` were:
110
+ *
111
+ * ```json
112
+ * [
113
+ * {
114
+ * "role": "user",
115
+ * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
116
+ * },
117
+ * { "role": "assistant", "content": "The best answer is (" }
118
+ * ]
119
+ * ```
120
+ *
121
+ * Then the response `content` might be:
122
+ *
123
+ * ```json
124
+ * [{ "type": "text", "text": "B)" }]
125
+ * ```
126
+ */
127
+ content: Array<BetaContentBlock>;
128
+
129
+ /**
130
+ * The model that will complete your prompt.\n\nSee
131
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for additional
132
+ * details and options.
133
+ */
134
+ model: MessagesAPI.Model;
135
+
136
+ /**
137
+ * Conversational role of the generated message.
138
+ *
139
+ * This will always be `"assistant"`.
140
+ */
141
+ role: 'assistant';
142
+
143
+ /**
144
+ * The reason that we stopped.
145
+ *
146
+ * This may be one the following values:
147
+ *
148
+ * - `"end_turn"`: the model reached a natural stopping point
149
+ * - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
150
+ * - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
151
+ * - `"tool_use"`: the model invoked one or more tools
152
+ *
153
+ * In non-streaming mode this value is always non-null. In streaming mode, it is
154
+ * null in the `message_start` event and non-null otherwise.
155
+ */
156
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
157
+
158
+ /**
159
+ * Which custom stop sequence was generated, if any.
160
+ *
161
+ * This value will be a non-null string if one of your custom stop sequences was
162
+ * generated.
163
+ */
164
+ stop_sequence: string | null;
165
+
166
+ /**
167
+ * Object type.
168
+ *
169
+ * For Messages, this is always `"message"`.
170
+ */
171
+ type: 'message';
172
+
173
+ /**
174
+ * Billing and rate-limit usage.
175
+ *
176
+ * Anthropic's API bills and rate-limits by token counts, as tokens represent the
177
+ * underlying cost to our systems.
178
+ *
179
+ * Under the hood, the API transforms requests into a format suitable for the
180
+ * model. The model's output then goes through a parsing stage before becoming an
181
+ * API response. As a result, the token counts in `usage` will not match one-to-one
182
+ * with the exact visible content of an API request or response.
183
+ *
184
+ * For example, `output_tokens` will be non-zero, even for an empty string response
185
+ * from Claude.
186
+ */
187
+ usage: BetaUsage;
188
+ }
189
+
190
+ export interface BetaMessageDeltaUsage {
191
+ /**
192
+ * The cumulative number of output tokens which were used.
193
+ */
194
+ output_tokens: number;
195
+ }
196
+
197
+ export interface BetaMessageParam {
198
+ content: string | Array<BetaContentBlockParam>;
199
+
200
+ role: 'user' | 'assistant';
201
+ }
202
+
203
+ export interface BetaMetadata {
204
+ /**
205
+ * An external identifier for the user who is associated with the request.
206
+ *
207
+ * This should be a uuid, hash value, or other opaque identifier. Anthropic may use
208
+ * this id to help detect abuse. Do not include any identifying information such as
209
+ * name, email address, or phone number.
210
+ */
211
+ user_id?: string | null;
212
+ }
213
+
214
+ export interface BetaRawContentBlockDeltaEvent {
215
+ delta: BetaTextDelta | BetaInputJSONDelta;
216
+
217
+ index: number;
218
+
219
+ type: 'content_block_delta';
220
+ }
221
+
222
+ export interface BetaRawContentBlockStartEvent {
223
+ content_block: BetaTextBlock | BetaToolUseBlock;
224
+
225
+ index: number;
226
+
227
+ type: 'content_block_start';
228
+ }
229
+
230
+ export interface BetaRawContentBlockStopEvent {
231
+ index: number;
232
+
233
+ type: 'content_block_stop';
234
+ }
235
+
236
+ export interface BetaRawMessageDeltaEvent {
237
+ delta: BetaRawMessageDeltaEvent.Delta;
238
+
239
+ type: 'message_delta';
240
+
241
+ /**
242
+ * Billing and rate-limit usage.
243
+ *
244
+ * Anthropic's API bills and rate-limits by token counts, as tokens represent the
245
+ * underlying cost to our systems.
246
+ *
247
+ * Under the hood, the API transforms requests into a format suitable for the
248
+ * model. The model's output then goes through a parsing stage before becoming an
249
+ * API response. As a result, the token counts in `usage` will not match one-to-one
250
+ * with the exact visible content of an API request or response.
251
+ *
252
+ * For example, `output_tokens` will be non-zero, even for an empty string response
253
+ * from Claude.
254
+ */
255
+ usage: BetaMessageDeltaUsage;
256
+ }
257
+
258
+ export namespace BetaRawMessageDeltaEvent {
259
+ export interface Delta {
260
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
261
+
262
+ stop_sequence: string | null;
263
+ }
264
+ }
265
+
266
+ export interface BetaRawMessageStartEvent {
267
+ message: BetaMessage;
268
+
269
+ type: 'message_start';
270
+ }
271
+
272
+ export interface BetaRawMessageStopEvent {
273
+ type: 'message_stop';
274
+ }
275
+
276
+ export type BetaRawMessageStreamEvent =
277
+ | BetaRawMessageStartEvent
278
+ | BetaRawMessageDeltaEvent
279
+ | BetaRawMessageStopEvent
280
+ | BetaRawContentBlockStartEvent
281
+ | BetaRawContentBlockDeltaEvent
282
+ | BetaRawContentBlockStopEvent;
283
+
284
+ export interface BetaTextBlock {
285
+ text: string;
286
+
287
+ type: 'text';
288
+ }
289
+
290
+ export interface BetaTextBlockParam {
291
+ text: string;
292
+
293
+ type: 'text';
294
+
295
+ cache_control?: BetaCacheControlEphemeral | null;
296
+ }
297
+
298
+ export interface BetaTextDelta {
299
+ text: string;
300
+
301
+ type: 'text_delta';
302
+ }
303
+
304
+ export interface BetaTool {
305
+ /**
306
+ * [JSON schema](https://json-schema.org/) for this tool's input.
307
+ *
308
+ * This defines the shape of the `input` that your tool accepts and that the model
309
+ * will produce.
310
+ */
311
+ input_schema: BetaTool.InputSchema;
312
+
313
+ name: string;
314
+
315
+ cache_control?: BetaCacheControlEphemeral | null;
316
+
317
+ /**
318
+ * Description of what this tool does.
319
+ *
320
+ * Tool descriptions should be as detailed as possible. The more information that
321
+ * the model has about what the tool is and how to use it, the better it will
322
+ * perform. You can use natural language descriptions to reinforce important
323
+ * aspects of the tool input JSON schema.
324
+ */
325
+ description?: string;
326
+ }
327
+
328
+ export namespace BetaTool {
329
+ /**
330
+ * [JSON schema](https://json-schema.org/) for this tool's input.
331
+ *
332
+ * This defines the shape of the `input` that your tool accepts and that the model
333
+ * will produce.
334
+ */
335
+ export interface InputSchema {
336
+ type: 'object';
337
+
338
+ properties?: unknown | null;
339
+ [k: string]: unknown;
340
+ }
341
+ }
342
+
343
+ /**
344
+ * How the model should use the provided tools. The model can use a specific tool,
345
+ * any available tool, or decide by itself.
346
+ */
347
+ export type BetaToolChoice = BetaToolChoiceAuto | BetaToolChoiceAny | BetaToolChoiceTool;
348
+
349
+ /**
350
+ * The model will use any available tools.
351
+ */
352
+ export interface BetaToolChoiceAny {
353
+ type: 'any';
354
+
355
+ /**
356
+ * Whether to disable parallel tool use.
357
+ *
358
+ * Defaults to `false`. If set to `true`, the model will output exactly one tool
359
+ * use.
360
+ */
361
+ disable_parallel_tool_use?: boolean;
362
+ }
363
+
364
+ /**
365
+ * The model will automatically decide whether to use tools.
366
+ */
367
+ export interface BetaToolChoiceAuto {
368
+ type: 'auto';
369
+
370
+ /**
371
+ * Whether to disable parallel tool use.
372
+ *
373
+ * Defaults to `false`. If set to `true`, the model will output at most one tool
374
+ * use.
375
+ */
376
+ disable_parallel_tool_use?: boolean;
377
+ }
378
+
379
+ /**
380
+ * The model will use the specified tool with `tool_choice.name`.
381
+ */
382
+ export interface BetaToolChoiceTool {
383
+ /**
384
+ * The name of the tool to use.
385
+ */
386
+ name: string;
387
+
388
+ type: 'tool';
389
+
390
+ /**
391
+ * Whether to disable parallel tool use.
392
+ *
393
+ * Defaults to `false`. If set to `true`, the model will output exactly one tool
394
+ * use.
395
+ */
396
+ disable_parallel_tool_use?: boolean;
397
+ }
398
+
399
+ export interface BetaToolResultBlockParam {
400
+ tool_use_id: string;
401
+
402
+ type: 'tool_result';
403
+
404
+ cache_control?: BetaCacheControlEphemeral | null;
405
+
406
+ content?: string | Array<BetaTextBlockParam | BetaImageBlockParam>;
407
+
408
+ is_error?: boolean;
409
+ }
410
+
411
+ export interface BetaToolUseBlock {
412
+ id: string;
413
+
414
+ input: unknown;
415
+
416
+ name: string;
417
+
418
+ type: 'tool_use';
419
+ }
420
+
421
+ export interface BetaToolUseBlockParam {
422
+ id: string;
423
+
424
+ input: unknown;
425
+
426
+ name: string;
427
+
428
+ type: 'tool_use';
429
+
430
+ cache_control?: BetaCacheControlEphemeral | null;
431
+ }
432
+
433
+ export interface BetaUsage {
434
+ /**
435
+ * The number of input tokens used to create the cache entry.
436
+ */
437
+ cache_creation_input_tokens: number | null;
438
+
439
+ /**
440
+ * The number of input tokens read from the cache.
441
+ */
442
+ cache_read_input_tokens: number | null;
443
+
444
+ /**
445
+ * The number of input tokens which were used.
446
+ */
447
+ input_tokens: number;
448
+
449
+ /**
450
+ * The number of output tokens which were used.
451
+ */
452
+ output_tokens: number;
453
+ }
454
+
455
+ export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming;
456
+
457
+ export interface MessageCreateParamsBase {
458
+ /**
459
+ * Body param: The maximum number of tokens to generate before stopping.
460
+ *
461
+ * Note that our models may stop _before_ reaching this maximum. This parameter
462
+ * only specifies the absolute maximum number of tokens to generate.
463
+ *
464
+ * Different models have different maximum values for this parameter. See
465
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for details.
466
+ */
467
+ max_tokens: number;
468
+
469
+ /**
470
+ * Body param: Input messages.
471
+ *
472
+ * Our models are trained to operate on alternating `user` and `assistant`
473
+ * conversational turns. When creating a new `Message`, you specify the prior
474
+ * conversational turns with the `messages` parameter, and the model then generates
475
+ * the next `Message` in the conversation.
476
+ *
477
+ * Each input message must be an object with a `role` and `content`. You can
478
+ * specify a single `user`-role message, or you can include multiple `user` and
479
+ * `assistant` messages. The first message must always use the `user` role.
480
+ *
481
+ * If the final message uses the `assistant` role, the response content will
482
+ * continue immediately from the content in that message. This can be used to
483
+ * constrain part of the model's response.
484
+ *
485
+ * Example with a single `user` message:
486
+ *
487
+ * ```json
488
+ * [{ "role": "user", "content": "Hello, Claude" }]
489
+ * ```
490
+ *
491
+ * Example with multiple conversational turns:
492
+ *
493
+ * ```json
494
+ * [
495
+ * { "role": "user", "content": "Hello there." },
496
+ * { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
497
+ * { "role": "user", "content": "Can you explain LLMs in plain English?" }
498
+ * ]
499
+ * ```
500
+ *
501
+ * Example with a partially-filled response from Claude:
502
+ *
503
+ * ```json
504
+ * [
505
+ * {
506
+ * "role": "user",
507
+ * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
508
+ * },
509
+ * { "role": "assistant", "content": "The best answer is (" }
510
+ * ]
511
+ * ```
512
+ *
513
+ * Each input message `content` may be either a single `string` or an array of
514
+ * content blocks, where each block has a specific `type`. Using a `string` for
515
+ * `content` is shorthand for an array of one content block of type `"text"`. The
516
+ * following input messages are equivalent:
517
+ *
518
+ * ```json
519
+ * { "role": "user", "content": "Hello, Claude" }
520
+ * ```
521
+ *
522
+ * ```json
523
+ * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
524
+ * ```
525
+ *
526
+ * Starting with Claude 3 models, you can also send image content blocks:
527
+ *
528
+ * ```json
529
+ * {
530
+ * "role": "user",
531
+ * "content": [
532
+ * {
533
+ * "type": "image",
534
+ * "source": {
535
+ * "type": "base64",
536
+ * "media_type": "image/jpeg",
537
+ * "data": "/9j/4AAQSkZJRg..."
538
+ * }
539
+ * },
540
+ * { "type": "text", "text": "What is in this image?" }
541
+ * ]
542
+ * }
543
+ * ```
544
+ *
545
+ * We currently support the `base64` source type for images, and the `image/jpeg`,
546
+ * `image/png`, `image/gif`, and `image/webp` media types.
547
+ *
548
+ * See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
549
+ * more input examples.
550
+ *
551
+ * Note that if you want to include a
552
+ * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
553
+ * the top-level `system` parameter — there is no `"system"` role for input
554
+ * messages in the Messages API.
555
+ */
556
+ messages: Array<BetaMessageParam>;
557
+
558
+ /**
559
+ * Body param: The model that will complete your prompt.\n\nSee
560
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for additional
561
+ * details and options.
562
+ */
563
+ model: MessagesAPI.Model;
564
+
565
+ /**
566
+ * Body param: An object describing metadata about the request.
567
+ */
568
+ metadata?: BetaMetadata;
569
+
570
+ /**
571
+ * Body param: Custom text sequences that will cause the model to stop generating.
572
+ *
573
+ * Our models will normally stop when they have naturally completed their turn,
574
+ * which will result in a response `stop_reason` of `"end_turn"`.
575
+ *
576
+ * If you want the model to stop generating when it encounters custom strings of
577
+ * text, you can use the `stop_sequences` parameter. If the model encounters one of
578
+ * the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
579
+ * and the response `stop_sequence` value will contain the matched stop sequence.
580
+ */
581
+ stop_sequences?: Array<string>;
582
+
583
+ /**
584
+ * Body param: Whether to incrementally stream the response using server-sent
585
+ * events.
586
+ *
587
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
588
+ * details.
589
+ */
590
+ stream?: boolean;
591
+
592
+ /**
593
+ * Body param: System prompt.
594
+ *
595
+ * A system prompt is a way of providing context and instructions to Claude, such
596
+ * as specifying a particular goal or role. See our
597
+ * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
598
+ */
599
+ system?: string | Array<BetaTextBlockParam>;
600
+
601
+ /**
602
+ * Body param: Amount of randomness injected into the response.
603
+ *
604
+ * Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
605
+ * for analytical / multiple choice, and closer to `1.0` for creative and
606
+ * generative tasks.
607
+ *
608
+ * Note that even with `temperature` of `0.0`, the results will not be fully
609
+ * deterministic.
610
+ */
611
+ temperature?: number;
612
+
613
+ /**
614
+ * Body param: How the model should use the provided tools. The model can use a
615
+ * specific tool, any available tool, or decide by itself.
616
+ */
617
+ tool_choice?: BetaToolChoice;
618
+
619
+ /**
620
+ * Body param: Definitions of tools that the model may use.
621
+ *
622
+ * If you include `tools` in your API request, the model may return `tool_use`
623
+ * content blocks that represent the model's use of those tools. You can then run
624
+ * those tools using the tool input generated by the model and then optionally
625
+ * return results back to the model using `tool_result` content blocks.
626
+ *
627
+ * Each tool definition includes:
628
+ *
629
+ * - `name`: Name of the tool.
630
+ * - `description`: Optional, but strongly-recommended description of the tool.
631
+ * - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
632
+ * shape that the model will produce in `tool_use` output content blocks.
633
+ *
634
+ * For example, if you defined `tools` as:
635
+ *
636
+ * ```json
637
+ * [
638
+ * {
639
+ * "name": "get_stock_price",
640
+ * "description": "Get the current stock price for a given ticker symbol.",
641
+ * "input_schema": {
642
+ * "type": "object",
643
+ * "properties": {
644
+ * "ticker": {
645
+ * "type": "string",
646
+ * "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
647
+ * }
648
+ * },
649
+ * "required": ["ticker"]
650
+ * }
651
+ * }
652
+ * ]
653
+ * ```
654
+ *
655
+ * And then asked the model "What's the S&P 500 at today?", the model might produce
656
+ * `tool_use` content blocks in the response like this:
657
+ *
658
+ * ```json
659
+ * [
660
+ * {
661
+ * "type": "tool_use",
662
+ * "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
663
+ * "name": "get_stock_price",
664
+ * "input": { "ticker": "^GSPC" }
665
+ * }
666
+ * ]
667
+ * ```
668
+ *
669
+ * You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
670
+ * input, and return the following back to the model in a subsequent `user`
671
+ * message:
672
+ *
673
+ * ```json
674
+ * [
675
+ * {
676
+ * "type": "tool_result",
677
+ * "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
678
+ * "content": "259.75 USD"
679
+ * }
680
+ * ]
681
+ * ```
682
+ *
683
+ * Tools can be used for workflows that include running client-side tools and
684
+ * functions, or more generally whenever you want the model to produce a particular
685
+ * JSON structure of output.
686
+ *
687
+ * See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
688
+ */
689
+ tools?: Array<BetaTool>;
690
+
691
+ /**
692
+ * Body param: Only sample from the top K options for each subsequent token.
693
+ *
694
+ * Used to remove "long tail" low probability responses.
695
+ * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
696
+ *
697
+ * Recommended for advanced use cases only. You usually only need to use
698
+ * `temperature`.
699
+ */
700
+ top_k?: number;
701
+
702
+ /**
703
+ * Body param: Use nucleus sampling.
704
+ *
705
+ * In nucleus sampling, we compute the cumulative distribution over all the options
706
+ * for each subsequent token in decreasing probability order and cut it off once it
707
+ * reaches a particular probability specified by `top_p`. You should either alter
708
+ * `temperature` or `top_p`, but not both.
709
+ *
710
+ * Recommended for advanced use cases only. You usually only need to use
711
+ * `temperature`.
712
+ */
713
+ top_p?: number;
714
+
715
+ /**
716
+ * Header param: Optional header to specify the beta version(s) you want to use.
717
+ */
718
+ betas?: Array<BetaAPI.AnthropicBeta>;
719
+ }
720
+
721
+ export namespace MessageCreateParams {
722
+ export type MessageCreateParamsNonStreaming = MessagesMessagesAPI.MessageCreateParamsNonStreaming;
723
+ export type MessageCreateParamsStreaming = MessagesMessagesAPI.MessageCreateParamsStreaming;
724
+ }
725
+
726
+ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
727
+ /**
728
+ * Body param: Whether to incrementally stream the response using server-sent
729
+ * events.
730
+ *
731
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
732
+ * details.
733
+ */
734
+ stream?: false;
735
+ }
736
+
737
+ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
738
+ /**
739
+ * Body param: Whether to incrementally stream the response using server-sent
740
+ * events.
741
+ *
742
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
743
+ * details.
744
+ */
745
+ stream: true;
746
+ }
747
+
748
+ export namespace Messages {
749
+ export import BetaCacheControlEphemeral = MessagesMessagesAPI.BetaCacheControlEphemeral;
750
+ export import BetaContentBlock = MessagesMessagesAPI.BetaContentBlock;
751
+ export import BetaContentBlockParam = MessagesMessagesAPI.BetaContentBlockParam;
752
+ export import BetaImageBlockParam = MessagesMessagesAPI.BetaImageBlockParam;
753
+ export import BetaInputJSONDelta = MessagesMessagesAPI.BetaInputJSONDelta;
754
+ export import BetaMessage = MessagesMessagesAPI.BetaMessage;
755
+ export import BetaMessageDeltaUsage = MessagesMessagesAPI.BetaMessageDeltaUsage;
756
+ export import BetaMessageParam = MessagesMessagesAPI.BetaMessageParam;
757
+ export import BetaMetadata = MessagesMessagesAPI.BetaMetadata;
758
+ export import BetaRawContentBlockDeltaEvent = MessagesMessagesAPI.BetaRawContentBlockDeltaEvent;
759
+ export import BetaRawContentBlockStartEvent = MessagesMessagesAPI.BetaRawContentBlockStartEvent;
760
+ export import BetaRawContentBlockStopEvent = MessagesMessagesAPI.BetaRawContentBlockStopEvent;
761
+ export import BetaRawMessageDeltaEvent = MessagesMessagesAPI.BetaRawMessageDeltaEvent;
762
+ export import BetaRawMessageStartEvent = MessagesMessagesAPI.BetaRawMessageStartEvent;
763
+ export import BetaRawMessageStopEvent = MessagesMessagesAPI.BetaRawMessageStopEvent;
764
+ export import BetaRawMessageStreamEvent = MessagesMessagesAPI.BetaRawMessageStreamEvent;
765
+ export import BetaTextBlock = MessagesMessagesAPI.BetaTextBlock;
766
+ export import BetaTextBlockParam = MessagesMessagesAPI.BetaTextBlockParam;
767
+ export import BetaTextDelta = MessagesMessagesAPI.BetaTextDelta;
768
+ export import BetaTool = MessagesMessagesAPI.BetaTool;
769
+ export import BetaToolChoice = MessagesMessagesAPI.BetaToolChoice;
770
+ export import BetaToolChoiceAny = MessagesMessagesAPI.BetaToolChoiceAny;
771
+ export import BetaToolChoiceAuto = MessagesMessagesAPI.BetaToolChoiceAuto;
772
+ export import BetaToolChoiceTool = MessagesMessagesAPI.BetaToolChoiceTool;
773
+ export import BetaToolResultBlockParam = MessagesMessagesAPI.BetaToolResultBlockParam;
774
+ export import BetaToolUseBlock = MessagesMessagesAPI.BetaToolUseBlock;
775
+ export import BetaToolUseBlockParam = MessagesMessagesAPI.BetaToolUseBlockParam;
776
+ export import BetaUsage = MessagesMessagesAPI.BetaUsage;
777
+ export import MessageCreateParams = MessagesMessagesAPI.MessageCreateParams;
778
+ export import MessageCreateParamsNonStreaming = MessagesMessagesAPI.MessageCreateParamsNonStreaming;
779
+ export import MessageCreateParamsStreaming = MessagesMessagesAPI.MessageCreateParamsStreaming;
780
+ export import Batches = BatchesAPI.Batches;
781
+ export import BetaMessageBatch = BatchesAPI.BetaMessageBatch;
782
+ export import BetaMessageBatchCanceledResult = BatchesAPI.BetaMessageBatchCanceledResult;
783
+ export import BetaMessageBatchErroredResult = BatchesAPI.BetaMessageBatchErroredResult;
784
+ export import BetaMessageBatchExpiredResult = BatchesAPI.BetaMessageBatchExpiredResult;
785
+ export import BetaMessageBatchIndividualResponse = BatchesAPI.BetaMessageBatchIndividualResponse;
786
+ export import BetaMessageBatchRequestCounts = BatchesAPI.BetaMessageBatchRequestCounts;
787
+ export import BetaMessageBatchResult = BatchesAPI.BetaMessageBatchResult;
788
+ export import BetaMessageBatchSucceededResult = BatchesAPI.BetaMessageBatchSucceededResult;
789
+ export import BetaMessageBatchesPage = BatchesAPI.BetaMessageBatchesPage;
790
+ export import BatchCreateParams = BatchesAPI.BatchCreateParams;
791
+ export import BatchRetrieveParams = BatchesAPI.BatchRetrieveParams;
792
+ export import BatchListParams = BatchesAPI.BatchListParams;
793
+ export import BatchCancelParams = BatchesAPI.BatchCancelParams;
794
+ export import BatchResultsParams = BatchesAPI.BatchResultsParams;
795
+ }