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