@anthropic-ai/sdk 0.14.1 → 0.16.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.
@@ -12,11 +12,11 @@ export class Messages extends APIResource {
12
12
  /**
13
13
  * Create a Message.
14
14
  *
15
- * Send a structured list of input messages, and the model will generate the next
16
- * message in the conversation.
15
+ * Send a structured list of input messages with text and/or image content, and the
16
+ * model will generate the next message in the conversation.
17
17
  *
18
- * Messages can be used for either single queries to the model or for multi-turn
19
- * conversations.
18
+ * The Messages API can be used for for either single queries or stateless
19
+ * multi-turn conversations.
20
20
  */
21
21
  create(body: MessageCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Message>;
22
22
  create(
@@ -75,6 +75,22 @@ export interface ContentBlockStopEvent {
75
75
  type: 'content_block_stop';
76
76
  }
77
77
 
78
+ export interface ImageBlockParam {
79
+ source: ImageBlockParam.Source;
80
+
81
+ type?: 'image';
82
+ }
83
+
84
+ export namespace ImageBlockParam {
85
+ export interface Source {
86
+ data: string;
87
+
88
+ media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
89
+
90
+ type?: 'base64';
91
+ }
92
+ }
93
+
78
94
  export interface Message {
79
95
  /**
80
96
  * Unique object identifier.
@@ -87,7 +103,7 @@ export interface Message {
87
103
  * Content generated by the model.
88
104
  *
89
105
  * This is an array of content blocks, each of which has a `type` that determines
90
- * its shape. Currently, the only `type` available is `"text"`.
106
+ * its shape. Currently, the only `type` in responses is `"text"`.
91
107
  *
92
108
  * Example:
93
109
  *
@@ -107,10 +123,7 @@ export interface Message {
107
123
  * "role": "user",
108
124
  * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
109
125
  * },
110
- * {
111
- * "role": "assistant",
112
- * "content": "The best answer is ("
113
- * }
126
+ * { "role": "assistant", "content": "The best answer is (" }
114
127
  * ]
115
128
  * ```
116
129
  *
@@ -152,16 +165,33 @@ export interface Message {
152
165
  stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
153
166
 
154
167
  /**
155
- * Which custom stop sequence was generated.
168
+ * Which custom stop sequence was generated, if any.
156
169
  *
157
- * This value will be non-null if one of your custom stop sequences was generated.
170
+ * This value will be a non-null string if one of your custom stop sequences was
171
+ * generated.
158
172
  */
159
173
  stop_sequence: string | null;
160
174
 
175
+ /**
176
+ * Object type.
177
+ *
178
+ * For Messages, this is always `"message"`.
179
+ */
161
180
  type: 'message';
162
181
 
163
182
  /**
164
- * Container for the number of tokens used.
183
+ * Billing and rate-limit usage.
184
+ *
185
+ * Anthropic's API bills and rate-limits by token counts, as tokens represent the
186
+ * underlying cost to our systems.
187
+ *
188
+ * Under the hood, the API transforms requests into a format suitable for the
189
+ * model. The model's output then goes through a parsing stage before becoming an
190
+ * API response. As a result, the token counts in `usage` will not match one-to-one
191
+ * with the exact visible content of an API request or response.
192
+ *
193
+ * For example, `output_tokens` will be non-zero, even for an empty string response
194
+ * from Claude.
165
195
  */
166
196
  usage: Usage;
167
197
  }
@@ -172,7 +202,18 @@ export interface MessageDeltaEvent {
172
202
  type: 'message_delta';
173
203
 
174
204
  /**
175
- * Container for the number of tokens used.
205
+ * Billing and rate-limit usage.
206
+ *
207
+ * Anthropic's API bills and rate-limits by token counts, as tokens represent the
208
+ * underlying cost to our systems.
209
+ *
210
+ * Under the hood, the API transforms requests into a format suitable for the
211
+ * model. The model's output then goes through a parsing stage before becoming an
212
+ * API response. As a result, the token counts in `usage` will not match one-to-one
213
+ * with the exact visible content of an API request or response.
214
+ *
215
+ * For example, `output_tokens` will be non-zero, even for an empty string response
216
+ * from Claude.
176
217
  */
177
218
  usage: MessageDeltaUsage;
178
219
  }
@@ -193,7 +234,7 @@ export interface MessageDeltaUsage {
193
234
  }
194
235
 
195
236
  export interface MessageParam {
196
- content: string | Array<TextBlock>;
237
+ content: string | Array<TextBlock | ImageBlockParam>;
197
238
 
198
239
  role: 'user' | 'assistant';
199
240
  }
@@ -250,8 +291,7 @@ export interface MessageCreateParamsBase {
250
291
  * only specifies the absolute maximum number of tokens to generate.
251
292
  *
252
293
  * Different models have different maximum values for this parameter. See
253
- * [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes)
254
- * for details.
294
+ * [models](https://docs.anthropic.com/claude/docs/models-overview) for details.
255
295
  */
256
296
  max_tokens: number;
257
297
 
@@ -291,15 +331,18 @@ export interface MessageCreateParamsBase {
291
331
  *
292
332
  * ```json
293
333
  * [
294
- * { "role": "user", "content": "Please describe yourself using only JSON" },
295
- * { "role": "assistant", "content": "Here is my JSON description:\n{" }
334
+ * {
335
+ * "role": "user",
336
+ * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
337
+ * },
338
+ * { "role": "assistant", "content": "The best answer is (" }
296
339
  * ]
297
340
  * ```
298
341
  *
299
342
  * Each input message `content` may be either a single `string` or an array of
300
- * content blocks, where each block has a specific `type`. Using a `string` is
301
- * shorthand for an array of one content block of type `"text"`. The following
302
- * input messages are equivalent:
343
+ * content blocks, where each block has a specific `type`. Using a `string` for
344
+ * `content` is shorthand for an array of one content block of type `"text"`. The
345
+ * following input messages are equivalent:
303
346
  *
304
347
  * ```json
305
348
  * { "role": "user", "content": "Hello, Claude" }
@@ -309,27 +352,42 @@ export interface MessageCreateParamsBase {
309
352
  * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
310
353
  * ```
311
354
  *
312
- * See our
313
- * [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
314
- * for more details on how to best construct prompts.
355
+ * Starting with Claude 3 models, you can also send image content blocks:
356
+ *
357
+ * ```json
358
+ * {
359
+ * "role": "user",
360
+ * "content": [
361
+ * {
362
+ * "type": "image",
363
+ * "source": {
364
+ * "type": "base64",
365
+ * "media_type": "image/jpeg",
366
+ * "data": "/9j/4AAQSkZJRg..."
367
+ * }
368
+ * },
369
+ * { "type": "text", "text": "What is in this image?" }
370
+ * ]
371
+ * }
372
+ * ```
373
+ *
374
+ * We currently support the `base64` source type for images, and the `image/jpeg`,
375
+ * `image/png`, `image/gif`, and `image/webp` media types.
376
+ *
377
+ * See [examples](https://docs.anthropic.com/claude/reference/messages-examples)
378
+ * for more input examples.
315
379
  *
316
380
  * Note that if you want to include a
317
- * [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts),
318
- * you can use the top-level `system` parameter — there is no `"system"` role for
319
- * input messages in the Messages API.
381
+ * [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can
382
+ * use the top-level `system` parameter — there is no `"system"` role for input
383
+ * messages in the Messages API.
320
384
  */
321
385
  messages: Array<MessageParam>;
322
386
 
323
387
  /**
324
388
  * The model that will complete your prompt.
325
389
  *
326
- * As we improve Claude, we develop new versions of it that you can query. The
327
- * `model` parameter controls which version of Claude responds to your request.
328
- * Right now we offer two model families: Claude, and Claude Instant. You can use
329
- * them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`,
330
- * respectively.
331
- *
332
- * See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
390
+ * See [models](https://docs.anthropic.com/claude/docs/models-overview) for
333
391
  * additional details and options.
334
392
  */
335
393
  model: string;
@@ -365,15 +423,19 @@ export interface MessageCreateParamsBase {
365
423
  *
366
424
  * A system prompt is a way of providing context and instructions to Claude, such
367
425
  * as specifying a particular goal or role. See our
368
- * [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts).
426
+ * [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts).
369
427
  */
370
428
  system?: string;
371
429
 
372
430
  /**
373
431
  * Amount of randomness injected into the response.
374
432
  *
375
- * Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical /
376
- * multiple choice, and closer to 1 for creative and generative tasks.
433
+ * Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
434
+ * for analytical / multiple choice, and closer to `1.0` for creative and
435
+ * generative tasks.
436
+ *
437
+ * Note that even with `temperature` of `0.0`, the results will not be fully
438
+ * deterministic.
377
439
  */
378
440
  temperature?: number;
379
441
 
@@ -382,6 +444,9 @@ export interface MessageCreateParamsBase {
382
444
  *
383
445
  * Used to remove "long tail" low probability responses.
384
446
  * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
447
+ *
448
+ * Recommended for advanced use cases only. You usually only need to use
449
+ * `temperature`.
385
450
  */
386
451
  top_k?: number;
387
452
 
@@ -392,6 +457,9 @@ export interface MessageCreateParamsBase {
392
457
  * for each subsequent token in decreasing probability order and cut it off once it
393
458
  * reaches a particular probability specified by `top_p`. You should either alter
394
459
  * `temperature` or `top_p`, but not both.
460
+ *
461
+ * Recommended for advanced use cases only. You usually only need to use
462
+ * `temperature`.
395
463
  */
396
464
  top_p?: number;
397
465
  }
@@ -443,8 +511,7 @@ export interface MessageStreamParams {
443
511
  * only specifies the absolute maximum number of tokens to generate.
444
512
  *
445
513
  * Different models have different maximum values for this parameter. See
446
- * [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes)
447
- * for details.
514
+ * [models](https://docs.anthropic.com/claude/docs/models-overview) for details.
448
515
  */
449
516
  max_tokens: number;
450
517
 
@@ -484,15 +551,18 @@ export interface MessageStreamParams {
484
551
  *
485
552
  * ```json
486
553
  * [
487
- * { "role": "user", "content": "Please describe yourself using only JSON" },
488
- * { "role": "assistant", "content": "Here is my JSON description:\n{" }
554
+ * {
555
+ * "role": "user",
556
+ * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
557
+ * },
558
+ * { "role": "assistant", "content": "The best answer is (" }
489
559
  * ]
490
560
  * ```
491
561
  *
492
562
  * Each input message `content` may be either a single `string` or an array of
493
- * content blocks, where each block has a specific `type`. Using a `string` is
494
- * shorthand for an array of one content block of type `"text"`. The following
495
- * input messages are equivalent:
563
+ * content blocks, where each block has a specific `type`. Using a `string` for
564
+ * `content` is shorthand for an array of one content block of type `"text"`. The
565
+ * following input messages are equivalent:
496
566
  *
497
567
  * ```json
498
568
  * { "role": "user", "content": "Hello, Claude" }
@@ -502,27 +572,42 @@ export interface MessageStreamParams {
502
572
  * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
503
573
  * ```
504
574
  *
505
- * See our
506
- * [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
507
- * for more details on how to best construct prompts.
575
+ * Starting with Claude 3 models, you can also send image content blocks:
576
+ *
577
+ * ```json
578
+ * {
579
+ * "role": "user",
580
+ * "content": [
581
+ * {
582
+ * "type": "image",
583
+ * "source": {
584
+ * "type": "base64",
585
+ * "media_type": "image/jpeg",
586
+ * "data": "/9j/4AAQSkZJRg..."
587
+ * }
588
+ * },
589
+ * { "type": "text", "text": "What is in this image?" }
590
+ * ]
591
+ * }
592
+ * ```
593
+ *
594
+ * We currently support the `base64` source type for images, and the `image/jpeg`,
595
+ * `image/png`, `image/gif`, and `image/webp` media types.
596
+ *
597
+ * See [examples](https://docs.anthropic.com/claude/reference/messages-examples)
598
+ * for more input examples.
508
599
  *
509
600
  * Note that if you want to include a
510
- * [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts),
511
- * you can use the top-level `system` parameter — there is no `"system"` role for
512
- * input messages in the Messages API.
601
+ * [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can
602
+ * use the top-level `system` parameter — there is no `"system"` role for input
603
+ * messages in the Messages API.
513
604
  */
514
605
  messages: Array<MessageParam>;
515
606
 
516
607
  /**
517
608
  * The model that will complete your prompt.
518
609
  *
519
- * As we improve Claude, we develop new versions of it that you can query. The
520
- * `model` parameter controls which version of Claude responds to your request.
521
- * Right now we offer two model families: Claude, and Claude Instant. You can use
522
- * them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`,
523
- * respectively.
524
- *
525
- * See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
610
+ * See [models](https://docs.anthropic.com/claude/docs/models-overview) for
526
611
  * additional details and options.
527
612
  */
528
613
  model: string;
@@ -550,15 +635,19 @@ export interface MessageStreamParams {
550
635
  *
551
636
  * A system prompt is a way of providing context and instructions to Claude, such
552
637
  * as specifying a particular goal or role. See our
553
- * [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts).
638
+ * [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts).
554
639
  */
555
640
  system?: string;
556
641
 
557
642
  /**
558
643
  * Amount of randomness injected into the response.
559
644
  *
560
- * Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical /
561
- * multiple choice, and closer to 1 for creative and generative tasks.
645
+ * Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
646
+ * for analytical / multiple choice, and closer to `1.0` for creative and
647
+ * generative tasks.
648
+ *
649
+ * Note that even with `temperature` of `0.0`, the results will not be fully
650
+ * deterministic.
562
651
  */
563
652
  temperature?: number;
564
653
 
@@ -567,6 +656,9 @@ export interface MessageStreamParams {
567
656
  *
568
657
  * Used to remove "long tail" low probability responses.
569
658
  * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
659
+ *
660
+ * Recommended for advanced use cases only. You usually only need to use
661
+ * `temperature`.
570
662
  */
571
663
  top_k?: number;
572
664
 
@@ -577,6 +669,9 @@ export interface MessageStreamParams {
577
669
  * for each subsequent token in decreasing probability order and cut it off once it
578
670
  * reaches a particular probability specified by `top_p`. You should either alter
579
671
  * `temperature` or `top_p`, but not both.
672
+ *
673
+ * Recommended for advanced use cases only. You usually only need to use
674
+ * `temperature`.
580
675
  */
581
676
  top_p?: number;
582
677
  }
@@ -602,6 +697,7 @@ export namespace Messages {
602
697
  export import ContentBlockDeltaEvent = MessagesAPI.ContentBlockDeltaEvent;
603
698
  export import ContentBlockStartEvent = MessagesAPI.ContentBlockStartEvent;
604
699
  export import ContentBlockStopEvent = MessagesAPI.ContentBlockStopEvent;
700
+ export import ImageBlockParam = MessagesAPI.ImageBlockParam;
605
701
  export import Message = MessagesAPI.Message;
606
702
  export import MessageDeltaEvent = MessagesAPI.MessageDeltaEvent;
607
703
  export import MessageDeltaUsage = MessagesAPI.MessageDeltaUsage;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.14.1'; // x-release-please-version
1
+ export const VERSION = '0.16.0'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.14.1";
1
+ export declare const VERSION = "0.16.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.14.1'; // x-release-please-version
4
+ exports.VERSION = '0.16.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.14.1'; // x-release-please-version
1
+ export const VERSION = '0.16.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map