@@ -12,7 +12,15 @@ export class Messages extends APIResource {
12
12
/**
13
13
* Create a Message.
14
14
*
15
- * The Messages API is currently in beta.
15
+ * Send a structured list of input messages, and the model will generate the next
16
+ * message in the conversation.
17
+ *
18
+ * Messages can be used for either single queries to the model or for multi-turn
19
+ * conversations.
20
+ *
21
+ * The Messages API is currently in beta. During beta, you must send the
22
+ * `anthropic-beta: messages-2023-12-15` header in your requests. If you are using
23
+ * our client SDKs, this is handled for you automatically.
16
24
*/
17
25
create ( body : MessageCreateParamsNonStreaming , options ?: Core . RequestOptions ) : APIPromise < Message > ;
18
26
create (
@@ -156,12 +164,22 @@ export interface Message {
156
164
stop_sequence : string | null ;
157
165
158
166
type : 'message' ;
167
+
168
+ /**
169
+ * Container for the number of tokens used.
170
+ */
171
+ usage : Usage ;
159
172
}
160
173
161
174
export interface MessageDeltaEvent {
162
175
delta : MessageDeltaEvent . Delta ;
163
176
164
177
type : 'message_delta' ;
178
+
179
+ /**
180
+ * Container for the number of tokens used.
181
+ */
182
+ usage : MessageDeltaUsage ;
165
183
}
166
184
167
185
export namespace MessageDeltaEvent {
@@ -172,6 +190,13 @@ export namespace MessageDeltaEvent {
172
190
}
173
191
}
174
192
193
+ export interface MessageDeltaUsage {
194
+ /**
195
+ * The cumulative number of output tokens which were used.
196
+ */
197
+ output_tokens : number ;
198
+ }
199
+
175
200
export interface MessageParam {
176
201
content : string | Array < TextBlock > ;
177
202
@@ -208,6 +233,18 @@ export interface TextDelta {
208
233
type : 'text_delta' ;
209
234
}
210
235
236
+ export interface Usage {
237
+ /**
238
+ * The number of input tokens which were used.
239
+ */
240
+ input_tokens : number ;
241
+
242
+ /**
243
+ * The number of output tokens which were used.
244
+ */
245
+ output_tokens : number ;
246
+ }
247
+
211
248
export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming ;
212
249
213
250
export interface MessageCreateParamsBase {
@@ -283,6 +320,11 @@ export interface MessageCreateParamsBase {
283
320
* See our
284
321
* [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
285
322
* for more details on how to best construct prompts.
323
+ *
324
+ * Note that if you want to include a
325
+ * [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts),
326
+ * you can use the top-level `system` parameter — there is no `"system"` role for
327
+ * input messages in the Messages API.
286
328
*/
287
329
messages : Array < MessageParam > ;
288
330
@@ -321,8 +363,8 @@ export interface MessageCreateParamsBase {
321
363
/**
322
364
* Whether to incrementally stream the response using server-sent events.
323
365
*
324
- * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
325
- * details.
366
+ * See [streaming](https://docs.anthropic.com/claude/reference/messages- streaming)
367
+ * for details.
326
368
*/
327
369
stream ?: boolean ;
328
370
@@ -374,7 +416,7 @@ export namespace MessageCreateParams {
374
416
* this id to help detect abuse. Do not include any identifying information such as
375
417
* name, email address, or phone number.
376
418
*/
377
- user_id ?: string ;
419
+ user_id ?: string | null ;
378
420
}
379
421
380
422
export type MessageCreateParamsNonStreaming = MessagesAPI . MessageCreateParamsNonStreaming ;
@@ -385,8 +427,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
385
427
/**
386
428
* Whether to incrementally stream the response using server-sent events.
387
429
*
388
- * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
389
- * details.
430
+ * See [streaming](https://docs.anthropic.com/claude/reference/messages- streaming)
431
+ * for details.
390
432
*/
391
433
stream ?: false ;
392
434
}
@@ -395,8 +437,8 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
395
437
/**
396
438
* Whether to incrementally stream the response using server-sent events.
397
439
*
398
- * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
399
- * details.
440
+ * See [streaming](https://docs.anthropic.com/claude/reference/messages- streaming)
441
+ * for details.
400
442
*/
401
443
stream : true ;
402
444
}
@@ -474,6 +516,11 @@ export interface MessageStreamParams {
474
516
* See our
475
517
* [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
476
518
* for more details on how to best construct prompts.
519
+ *
520
+ * Note that if you want to include a
521
+ * [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts),
522
+ * you can use the top-level `system` parameter — there is no `"system"` role for
523
+ * input messages in the Messages API.
477
524
*/
478
525
messages : Array < MessageParam > ;
479
526
@@ -557,7 +604,7 @@ export namespace MessageStreamParams {
557
604
* this id to help detect abuse. Do not include any identifying information such as
558
605
* name, email address, or phone number.
559
606
*/
560
- user_id ?: string ;
607
+ user_id ?: string | null ;
561
608
}
562
609
}
563
610
@@ -568,12 +615,14 @@ export namespace Messages {
568
615
export import ContentBlockStopEvent = MessagesAPI . ContentBlockStopEvent ;
569
616
export import Message = MessagesAPI . Message ;
570
617
export import MessageDeltaEvent = MessagesAPI . MessageDeltaEvent ;
618
+ export import MessageDeltaUsage = MessagesAPI . MessageDeltaUsage ;
571
619
export import MessageParam = MessagesAPI . MessageParam ;
572
620
export import MessageStartEvent = MessagesAPI . MessageStartEvent ;
573
621
export import MessageStopEvent = MessagesAPI . MessageStopEvent ;
574
622
export import MessageStreamEvent = MessagesAPI . MessageStreamEvent ;
575
623
export import TextBlock = MessagesAPI . TextBlock ;
576
624
export import TextDelta = MessagesAPI . TextDelta ;
625
+ export import Usage = MessagesAPI . Usage ;
577
626
export import MessageCreateParams = MessagesAPI . MessageCreateParams ;
578
627
export import MessageCreateParamsNonStreaming = MessagesAPI . MessageCreateParamsNonStreaming ;
579
628
export import MessageCreateParamsStreaming = MessagesAPI . MessageCreateParamsStreaming ;
0 commit comments