@@ -12,7 +12,15 @@ export class Messages extends APIResource {
1212 /**
1313 * Create a Message.
1414 *
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.
1624 */
1725 create ( body : MessageCreateParamsNonStreaming , options ?: Core . RequestOptions ) : APIPromise < Message > ;
1826 create (
@@ -156,12 +164,22 @@ export interface Message {
156164 stop_sequence : string | null ;
157165
158166 type : 'message' ;
167+
168+ /**
169+ * Container for the number of tokens used.
170+ */
171+ usage : Usage ;
159172}
160173
161174export interface MessageDeltaEvent {
162175 delta : MessageDeltaEvent . Delta ;
163176
164177 type : 'message_delta' ;
178+
179+ /**
180+ * Container for the number of tokens used.
181+ */
182+ usage : MessageDeltaUsage ;
165183}
166184
167185export namespace MessageDeltaEvent {
@@ -172,6 +190,13 @@ export namespace MessageDeltaEvent {
172190 }
173191}
174192
193+ export interface MessageDeltaUsage {
194+ /**
195+ * The cumulative number of output tokens which were used.
196+ */
197+ output_tokens : number ;
198+ }
199+
175200export interface MessageParam {
176201 content : string | Array < TextBlock > ;
177202
@@ -208,6 +233,18 @@ export interface TextDelta {
208233 type : 'text_delta' ;
209234}
210235
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+
211248export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming ;
212249
213250export interface MessageCreateParamsBase {
@@ -283,6 +320,11 @@ export interface MessageCreateParamsBase {
283320 * See our
284321 * [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
285322 * 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.
286328 */
287329 messages : Array < MessageParam > ;
288330
@@ -321,8 +363,8 @@ export interface MessageCreateParamsBase {
321363 /**
322364 * Whether to incrementally stream the response using server-sent events.
323365 *
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.
326368 */
327369 stream ?: boolean ;
328370
@@ -374,7 +416,7 @@ export namespace MessageCreateParams {
374416 * this id to help detect abuse. Do not include any identifying information such as
375417 * name, email address, or phone number.
376418 */
377- user_id ?: string ;
419+ user_id ?: string | null ;
378420 }
379421
380422 export type MessageCreateParamsNonStreaming = MessagesAPI . MessageCreateParamsNonStreaming ;
@@ -385,8 +427,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
385427 /**
386428 * Whether to incrementally stream the response using server-sent events.
387429 *
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.
390432 */
391433 stream ?: false ;
392434}
@@ -395,8 +437,8 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
395437 /**
396438 * Whether to incrementally stream the response using server-sent events.
397439 *
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.
400442 */
401443 stream : true ;
402444}
@@ -474,6 +516,11 @@ export interface MessageStreamParams {
474516 * See our
475517 * [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
476518 * 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.
477524 */
478525 messages : Array < MessageParam > ;
479526
@@ -557,7 +604,7 @@ export namespace MessageStreamParams {
557604 * this id to help detect abuse. Do not include any identifying information such as
558605 * name, email address, or phone number.
559606 */
560- user_id ?: string ;
607+ user_id ?: string | null ;
561608 }
562609}
563610
@@ -568,12 +615,14 @@ export namespace Messages {
568615 export import ContentBlockStopEvent = MessagesAPI . ContentBlockStopEvent ;
569616 export import Message = MessagesAPI . Message ;
570617 export import MessageDeltaEvent = MessagesAPI . MessageDeltaEvent ;
618+ export import MessageDeltaUsage = MessagesAPI . MessageDeltaUsage ;
571619 export import MessageParam = MessagesAPI . MessageParam ;
572620 export import MessageStartEvent = MessagesAPI . MessageStartEvent ;
573621 export import MessageStopEvent = MessagesAPI . MessageStopEvent ;
574622 export import MessageStreamEvent = MessagesAPI . MessageStreamEvent ;
575623 export import TextBlock = MessagesAPI . TextBlock ;
576624 export import TextDelta = MessagesAPI . TextDelta ;
625+ export import Usage = MessagesAPI . Usage ;
577626 export import MessageCreateParams = MessagesAPI . MessageCreateParams ;
578627 export import MessageCreateParamsNonStreaming = MessagesAPI . MessageCreateParamsNonStreaming ;
579628 export import MessageCreateParamsStreaming = MessagesAPI . MessageCreateParamsStreaming ;
0 commit comments