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