@anthropic-ai/sdk 0.40.1 → 0.41.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 (101) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -3
  3. package/index.d.mts +4 -4
  4. package/index.d.ts +4 -4
  5. package/index.d.ts.map +1 -1
  6. package/index.js.map +1 -1
  7. package/index.mjs.map +1 -1
  8. package/lib/BetaMessageStream.d.ts.map +1 -1
  9. package/lib/BetaMessageStream.js +7 -0
  10. package/lib/BetaMessageStream.js.map +1 -1
  11. package/lib/BetaMessageStream.mjs +7 -0
  12. package/lib/BetaMessageStream.mjs.map +1 -1
  13. package/lib/MessageStream.d.ts.map +1 -1
  14. package/lib/MessageStream.js +7 -0
  15. package/lib/MessageStream.js.map +1 -1
  16. package/lib/MessageStream.mjs +7 -0
  17. package/lib/MessageStream.mjs.map +1 -1
  18. package/package.json +1 -1
  19. package/resources/beta/beta.d.ts +4 -4
  20. package/resources/beta/beta.d.ts.map +1 -1
  21. package/resources/beta/beta.js.map +1 -1
  22. package/resources/beta/beta.mjs.map +1 -1
  23. package/resources/beta/index.d.ts +2 -2
  24. package/resources/beta/index.d.ts.map +1 -1
  25. package/resources/beta/index.js.map +1 -1
  26. package/resources/beta/index.mjs +1 -1
  27. package/resources/beta/index.mjs.map +1 -1
  28. package/resources/beta/messages/batches.d.ts +59 -0
  29. package/resources/beta/messages/batches.d.ts.map +1 -1
  30. package/resources/beta/messages/batches.js +19 -0
  31. package/resources/beta/messages/batches.js.map +1 -1
  32. package/resources/beta/messages/batches.mjs +19 -0
  33. package/resources/beta/messages/batches.mjs.map +1 -1
  34. package/resources/beta/messages/index.d.ts +1 -1
  35. package/resources/beta/messages/index.d.ts.map +1 -1
  36. package/resources/beta/messages/index.js.map +1 -1
  37. package/resources/beta/messages/index.mjs.map +1 -1
  38. package/resources/beta/messages/messages.d.ts +228 -17
  39. package/resources/beta/messages/messages.d.ts.map +1 -1
  40. package/resources/beta/messages/messages.js +9 -0
  41. package/resources/beta/messages/messages.js.map +1 -1
  42. package/resources/beta/messages/messages.mjs +9 -0
  43. package/resources/beta/messages/messages.mjs.map +1 -1
  44. package/resources/beta/models.d.ts +29 -2
  45. package/resources/beta/models.d.ts.map +1 -1
  46. package/resources/beta/models.js +24 -12
  47. package/resources/beta/models.js.map +1 -1
  48. package/resources/beta/models.mjs +24 -12
  49. package/resources/beta/models.mjs.map +1 -1
  50. package/resources/completions.d.ts +31 -14
  51. package/resources/completions.d.ts.map +1 -1
  52. package/resources/completions.js +7 -2
  53. package/resources/completions.js.map +1 -1
  54. package/resources/completions.mjs +7 -2
  55. package/resources/completions.mjs.map +1 -1
  56. package/resources/index.d.ts +2 -2
  57. package/resources/index.d.ts.map +1 -1
  58. package/resources/index.js.map +1 -1
  59. package/resources/index.mjs +1 -1
  60. package/resources/index.mjs.map +1 -1
  61. package/resources/messages/batches.d.ts +52 -0
  62. package/resources/messages/batches.d.ts.map +1 -1
  63. package/resources/messages/batches.js +44 -0
  64. package/resources/messages/batches.js.map +1 -1
  65. package/resources/messages/batches.mjs +44 -0
  66. package/resources/messages/batches.mjs.map +1 -1
  67. package/resources/messages/index.d.ts +1 -1
  68. package/resources/messages/index.d.ts.map +1 -1
  69. package/resources/messages/index.js.map +1 -1
  70. package/resources/messages/index.mjs.map +1 -1
  71. package/resources/messages/messages.d.ts +213 -13
  72. package/resources/messages/messages.d.ts.map +1 -1
  73. package/resources/messages/messages.js +9 -0
  74. package/resources/messages/messages.js.map +1 -1
  75. package/resources/messages/messages.mjs +9 -0
  76. package/resources/messages/messages.mjs.map +1 -1
  77. package/resources/models.d.ts +14 -2
  78. package/resources/models.d.ts.map +1 -1
  79. package/resources/models.js +24 -12
  80. package/resources/models.js.map +1 -1
  81. package/resources/models.mjs +24 -12
  82. package/resources/models.mjs.map +1 -1
  83. package/src/index.ts +30 -1
  84. package/src/lib/BetaMessageStream.ts +9 -0
  85. package/src/lib/MessageStream.ts +9 -0
  86. package/src/resources/beta/beta.ts +30 -1
  87. package/src/resources/beta/index.ts +21 -1
  88. package/src/resources/beta/messages/batches.ts +59 -0
  89. package/src/resources/beta/messages/index.ts +14 -0
  90. package/src/resources/beta/messages/messages.ts +336 -13
  91. package/src/resources/beta/models.ts +65 -8
  92. package/src/resources/completions.ts +39 -16
  93. package/src/resources/index.ts +21 -1
  94. package/src/resources/messages/batches.ts +52 -0
  95. package/src/resources/messages/index.ts +14 -0
  96. package/src/resources/messages/messages.ts +321 -11
  97. package/src/resources/models.ts +50 -8
  98. package/src/version.ts +1 -1
  99. package/version.d.ts +1 -1
  100. package/version.js +1 -1
  101. package/version.mjs +1 -1
@@ -54,6 +54,15 @@ export class Messages extends APIResource {
54
54
  * conversations.
55
55
  *
56
56
  * Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const betaMessage = await client.beta.messages.create({
61
+ * max_tokens: 1024,
62
+ * messages: [{ content: 'Hello, world', role: 'user' }],
63
+ * model: 'claude-3-7-sonnet-20250219',
64
+ * });
65
+ * ```
57
66
  */
58
67
  create(params: MessageCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<BetaMessage>;
59
68
  create(
@@ -107,6 +116,15 @@ export class Messages extends APIResource {
107
116
  *
108
117
  * Learn more about token counting in our
109
118
  * [user guide](/en/docs/build-with-claude/token-counting)
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const betaMessageTokensCount =
123
+ * await client.beta.messages.countTokens({
124
+ * messages: [{ content: 'string', role: 'user' }],
125
+ * model: 'claude-3-7-sonnet-latest',
126
+ * });
127
+ * ```
110
128
  */
111
129
  countTokens(
112
130
  params: MessageCountTokensParams,
@@ -139,6 +157,9 @@ export interface BetaBase64PDFBlock {
139
157
 
140
158
  type: 'document';
141
159
 
160
+ /**
161
+ * Create a cache control breakpoint at this content block.
162
+ */
142
163
  cache_control?: BetaCacheControlEphemeral | null;
143
164
 
144
165
  citations?: BetaCitationsConfigParam;
@@ -244,19 +265,49 @@ export interface BetaCitationPageLocationParam {
244
265
  type: 'page_location';
245
266
  }
246
267
 
268
+ export interface BetaCitationWebSearchResultLocationParam {
269
+ cited_text: string;
270
+
271
+ encrypted_index: string;
272
+
273
+ title: string | null;
274
+
275
+ type: 'web_search_result_location';
276
+
277
+ url: string;
278
+ }
279
+
247
280
  export interface BetaCitationsConfigParam {
248
281
  enabled?: boolean;
249
282
  }
250
283
 
251
284
  export interface BetaCitationsDelta {
252
- citation: BetaCitationCharLocation | BetaCitationPageLocation | BetaCitationContentBlockLocation;
285
+ citation:
286
+ | BetaCitationCharLocation
287
+ | BetaCitationPageLocation
288
+ | BetaCitationContentBlockLocation
289
+ | BetaCitationsWebSearchResultLocation;
253
290
 
254
291
  type: 'citations_delta';
255
292
  }
256
293
 
294
+ export interface BetaCitationsWebSearchResultLocation {
295
+ cited_text: string;
296
+
297
+ encrypted_index: string;
298
+
299
+ title: string | null;
300
+
301
+ type: 'web_search_result_location';
302
+
303
+ url: string;
304
+ }
305
+
257
306
  export type BetaContentBlock =
258
307
  | BetaTextBlock
259
308
  | BetaToolUseBlock
309
+ | BetaServerToolUseBlock
310
+ | BetaWebSearchToolResultBlock
260
311
  | BetaThinkingBlock
261
312
  | BetaRedactedThinkingBlock;
262
313
 
@@ -264,6 +315,8 @@ export type BetaContentBlockParam =
264
315
  | BetaTextBlockParam
265
316
  | BetaImageBlockParam
266
317
  | BetaToolUseBlockParam
318
+ | BetaServerToolUseBlockParam
319
+ | BetaWebSearchToolResultBlockParam
267
320
  | BetaToolResultBlockParam
268
321
  | BetaBase64PDFBlock
269
322
  | BetaThinkingBlockParam
@@ -282,6 +335,9 @@ export interface BetaImageBlockParam {
282
335
 
283
336
  type: 'image';
284
337
 
338
+ /**
339
+ * Create a cache control breakpoint at this content block.
340
+ */
285
341
  cache_control?: BetaCacheControlEphemeral | null;
286
342
  }
287
343
 
@@ -400,10 +456,30 @@ export interface BetaMessage {
400
456
  }
401
457
 
402
458
  export interface BetaMessageDeltaUsage {
459
+ /**
460
+ * The cumulative number of input tokens used to create the cache entry.
461
+ */
462
+ cache_creation_input_tokens: number | null;
463
+
464
+ /**
465
+ * The cumulative number of input tokens read from the cache.
466
+ */
467
+ cache_read_input_tokens: number | null;
468
+
469
+ /**
470
+ * The cumulative number of input tokens which were used.
471
+ */
472
+ input_tokens: number | null;
473
+
403
474
  /**
404
475
  * The cumulative number of output tokens which were used.
405
476
  */
406
477
  output_tokens: number;
478
+
479
+ /**
480
+ * The number of server tool requests.
481
+ */
482
+ server_tool_use: BetaServerToolUsage | null;
407
483
  }
408
484
 
409
485
  export interface BetaMessageParam {
@@ -455,7 +531,13 @@ export interface BetaRawContentBlockDeltaEvent {
455
531
  }
456
532
 
457
533
  export interface BetaRawContentBlockStartEvent {
458
- content_block: BetaTextBlock | BetaToolUseBlock | BetaThinkingBlock | BetaRedactedThinkingBlock;
534
+ content_block:
535
+ | BetaTextBlock
536
+ | BetaToolUseBlock
537
+ | BetaServerToolUseBlock
538
+ | BetaWebSearchToolResultBlock
539
+ | BetaThinkingBlock
540
+ | BetaRedactedThinkingBlock;
459
541
 
460
542
  index: number;
461
543
 
@@ -531,13 +613,51 @@ export interface BetaRedactedThinkingBlockParam {
531
613
  type: 'redacted_thinking';
532
614
  }
533
615
 
616
+ export interface BetaServerToolUsage {
617
+ /**
618
+ * The number of web search tool requests.
619
+ */
620
+ web_search_requests: number;
621
+ }
622
+
623
+ export interface BetaServerToolUseBlock {
624
+ id: string;
625
+
626
+ input: unknown;
627
+
628
+ name: 'web_search';
629
+
630
+ type: 'server_tool_use';
631
+ }
632
+
633
+ export interface BetaServerToolUseBlockParam {
634
+ id: string;
635
+
636
+ input: unknown;
637
+
638
+ name: 'web_search';
639
+
640
+ type: 'server_tool_use';
641
+
642
+ /**
643
+ * Create a cache control breakpoint at this content block.
644
+ */
645
+ cache_control?: BetaCacheControlEphemeral | null;
646
+ }
647
+
534
648
  export interface BetaSignatureDelta {
535
649
  signature: string;
536
650
 
537
651
  type: 'signature_delta';
538
652
  }
539
653
 
540
- export type BetaStopReason = 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use';
654
+ export type BetaStopReason =
655
+ | 'end_turn'
656
+ | 'max_tokens'
657
+ | 'stop_sequence'
658
+ | 'tool_use'
659
+ | 'pause_turn'
660
+ | 'refusal';
541
661
 
542
662
  export interface BetaTextBlock {
543
663
  /**
@@ -559,6 +679,9 @@ export interface BetaTextBlockParam {
559
679
 
560
680
  type: 'text';
561
681
 
682
+ /**
683
+ * Create a cache control breakpoint at this content block.
684
+ */
562
685
  cache_control?: BetaCacheControlEphemeral | null;
563
686
 
564
687
  citations?: Array<BetaTextCitationParam> | null;
@@ -567,12 +690,14 @@ export interface BetaTextBlockParam {
567
690
  export type BetaTextCitation =
568
691
  | BetaCitationCharLocation
569
692
  | BetaCitationPageLocation
570
- | BetaCitationContentBlockLocation;
693
+ | BetaCitationContentBlockLocation
694
+ | BetaCitationsWebSearchResultLocation;
571
695
 
572
696
  export type BetaTextCitationParam =
573
697
  | BetaCitationCharLocationParam
574
698
  | BetaCitationPageLocationParam
575
- | BetaCitationContentBlockLocationParam;
699
+ | BetaCitationContentBlockLocationParam
700
+ | BetaCitationWebSearchResultLocationParam;
576
701
 
577
702
  export interface BetaTextDelta {
578
703
  text: string;
@@ -648,10 +773,13 @@ export interface BetaTool {
648
773
  /**
649
774
  * Name of the tool.
650
775
  *
651
- * This is how the tool will be called by the model and in tool_use blocks.
776
+ * This is how the tool will be called by the model and in `tool_use` blocks.
652
777
  */
653
778
  name: string;
654
779
 
780
+ /**
781
+ * Create a cache control breakpoint at this content block.
782
+ */
655
783
  cache_control?: BetaCacheControlEphemeral | null;
656
784
 
657
785
  /**
@@ -687,12 +815,15 @@ export interface BetaToolBash20241022 {
687
815
  /**
688
816
  * Name of the tool.
689
817
  *
690
- * This is how the tool will be called by the model and in tool_use blocks.
818
+ * This is how the tool will be called by the model and in `tool_use` blocks.
691
819
  */
692
820
  name: 'bash';
693
821
 
694
822
  type: 'bash_20241022';
695
823
 
824
+ /**
825
+ * Create a cache control breakpoint at this content block.
826
+ */
696
827
  cache_control?: BetaCacheControlEphemeral | null;
697
828
  }
698
829
 
@@ -700,12 +831,15 @@ export interface BetaToolBash20250124 {
700
831
  /**
701
832
  * Name of the tool.
702
833
  *
703
- * This is how the tool will be called by the model and in tool_use blocks.
834
+ * This is how the tool will be called by the model and in `tool_use` blocks.
704
835
  */
705
836
  name: 'bash';
706
837
 
707
838
  type: 'bash_20250124';
708
839
 
840
+ /**
841
+ * Create a cache control breakpoint at this content block.
842
+ */
709
843
  cache_control?: BetaCacheControlEphemeral | null;
710
844
  }
711
845
 
@@ -786,12 +920,15 @@ export interface BetaToolComputerUse20241022 {
786
920
  /**
787
921
  * Name of the tool.
788
922
  *
789
- * This is how the tool will be called by the model and in tool_use blocks.
923
+ * This is how the tool will be called by the model and in `tool_use` blocks.
790
924
  */
791
925
  name: 'computer';
792
926
 
793
927
  type: 'computer_20241022';
794
928
 
929
+ /**
930
+ * Create a cache control breakpoint at this content block.
931
+ */
795
932
  cache_control?: BetaCacheControlEphemeral | null;
796
933
 
797
934
  /**
@@ -814,12 +951,15 @@ export interface BetaToolComputerUse20250124 {
814
951
  /**
815
952
  * Name of the tool.
816
953
  *
817
- * This is how the tool will be called by the model and in tool_use blocks.
954
+ * This is how the tool will be called by the model and in `tool_use` blocks.
818
955
  */
819
956
  name: 'computer';
820
957
 
821
958
  type: 'computer_20250124';
822
959
 
960
+ /**
961
+ * Create a cache control breakpoint at this content block.
962
+ */
823
963
  cache_control?: BetaCacheControlEphemeral | null;
824
964
 
825
965
  /**
@@ -833,6 +973,9 @@ export interface BetaToolResultBlockParam {
833
973
 
834
974
  type: 'tool_result';
835
975
 
976
+ /**
977
+ * Create a cache control breakpoint at this content block.
978
+ */
836
979
  cache_control?: BetaCacheControlEphemeral | null;
837
980
 
838
981
  content?: string | Array<BetaTextBlockParam | BetaImageBlockParam>;
@@ -844,12 +987,15 @@ export interface BetaToolTextEditor20241022 {
844
987
  /**
845
988
  * Name of the tool.
846
989
  *
847
- * This is how the tool will be called by the model and in tool_use blocks.
990
+ * This is how the tool will be called by the model and in `tool_use` blocks.
848
991
  */
849
992
  name: 'str_replace_editor';
850
993
 
851
994
  type: 'text_editor_20241022';
852
995
 
996
+ /**
997
+ * Create a cache control breakpoint at this content block.
998
+ */
853
999
  cache_control?: BetaCacheControlEphemeral | null;
854
1000
  }
855
1001
 
@@ -857,12 +1003,15 @@ export interface BetaToolTextEditor20250124 {
857
1003
  /**
858
1004
  * Name of the tool.
859
1005
  *
860
- * This is how the tool will be called by the model and in tool_use blocks.
1006
+ * This is how the tool will be called by the model and in `tool_use` blocks.
861
1007
  */
862
1008
  name: 'str_replace_editor';
863
1009
 
864
1010
  type: 'text_editor_20250124';
865
1011
 
1012
+ /**
1013
+ * Create a cache control breakpoint at this content block.
1014
+ */
866
1015
  cache_control?: BetaCacheControlEphemeral | null;
867
1016
  }
868
1017
 
@@ -873,7 +1022,8 @@ export type BetaToolUnion =
873
1022
  | BetaToolTextEditor20241022
874
1023
  | BetaToolComputerUse20250124
875
1024
  | BetaToolBash20250124
876
- | BetaToolTextEditor20250124;
1025
+ | BetaToolTextEditor20250124
1026
+ | BetaWebSearchTool20250305;
877
1027
 
878
1028
  export interface BetaToolUseBlock {
879
1029
  id: string;
@@ -894,6 +1044,9 @@ export interface BetaToolUseBlockParam {
894
1044
 
895
1045
  type: 'tool_use';
896
1046
 
1047
+ /**
1048
+ * Create a cache control breakpoint at this content block.
1049
+ */
897
1050
  cache_control?: BetaCacheControlEphemeral | null;
898
1051
  }
899
1052
 
@@ -929,6 +1082,157 @@ export interface BetaUsage {
929
1082
  * The number of output tokens which were used.
930
1083
  */
931
1084
  output_tokens: number;
1085
+
1086
+ /**
1087
+ * The number of server tool requests.
1088
+ */
1089
+ server_tool_use: BetaServerToolUsage | null;
1090
+ }
1091
+
1092
+ export interface BetaWebSearchResultBlock {
1093
+ encrypted_content: string;
1094
+
1095
+ page_age: string | null;
1096
+
1097
+ title: string;
1098
+
1099
+ type: 'web_search_result';
1100
+
1101
+ url: string;
1102
+ }
1103
+
1104
+ export interface BetaWebSearchResultBlockParam {
1105
+ encrypted_content: string;
1106
+
1107
+ title: string;
1108
+
1109
+ type: 'web_search_result';
1110
+
1111
+ url: string;
1112
+
1113
+ page_age?: string | null;
1114
+ }
1115
+
1116
+ export interface BetaWebSearchTool20250305 {
1117
+ /**
1118
+ * Name of the tool.
1119
+ *
1120
+ * This is how the tool will be called by the model and in `tool_use` blocks.
1121
+ */
1122
+ name: 'web_search';
1123
+
1124
+ type: 'web_search_20250305';
1125
+
1126
+ /**
1127
+ * If provided, only these domains will be included in results. Cannot be used
1128
+ * alongside `blocked_domains`.
1129
+ */
1130
+ allowed_domains?: Array<string> | null;
1131
+
1132
+ /**
1133
+ * If provided, these domains will never appear in results. Cannot be used
1134
+ * alongside `allowed_domains`.
1135
+ */
1136
+ blocked_domains?: Array<string> | null;
1137
+
1138
+ /**
1139
+ * Create a cache control breakpoint at this content block.
1140
+ */
1141
+ cache_control?: BetaCacheControlEphemeral | null;
1142
+
1143
+ /**
1144
+ * Maximum number of times the tool can be used in the API request.
1145
+ */
1146
+ max_uses?: number | null;
1147
+
1148
+ /**
1149
+ * Parameters for the user's location. Used to provide more relevant search
1150
+ * results.
1151
+ */
1152
+ user_location?: BetaWebSearchTool20250305.UserLocation | null;
1153
+ }
1154
+
1155
+ export namespace BetaWebSearchTool20250305 {
1156
+ /**
1157
+ * Parameters for the user's location. Used to provide more relevant search
1158
+ * results.
1159
+ */
1160
+ export interface UserLocation {
1161
+ type: 'approximate';
1162
+
1163
+ /**
1164
+ * The city of the user.
1165
+ */
1166
+ city?: string | null;
1167
+
1168
+ /**
1169
+ * The two letter
1170
+ * [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the
1171
+ * user.
1172
+ */
1173
+ country?: string | null;
1174
+
1175
+ /**
1176
+ * The region of the user.
1177
+ */
1178
+ region?: string | null;
1179
+
1180
+ /**
1181
+ * The [IANA timezone](https://nodatime.org/TimeZones) of the user.
1182
+ */
1183
+ timezone?: string | null;
1184
+ }
1185
+ }
1186
+
1187
+ export interface BetaWebSearchToolRequestError {
1188
+ error_code:
1189
+ | 'invalid_tool_input'
1190
+ | 'unavailable'
1191
+ | 'max_uses_exceeded'
1192
+ | 'too_many_requests'
1193
+ | 'query_too_long';
1194
+
1195
+ type: 'web_search_tool_result_error';
1196
+ }
1197
+
1198
+ export interface BetaWebSearchToolResultBlock {
1199
+ content: BetaWebSearchToolResultBlockContent;
1200
+
1201
+ tool_use_id: string;
1202
+
1203
+ type: 'web_search_tool_result';
1204
+ }
1205
+
1206
+ export type BetaWebSearchToolResultBlockContent =
1207
+ | BetaWebSearchToolResultError
1208
+ | Array<BetaWebSearchResultBlock>;
1209
+
1210
+ export interface BetaWebSearchToolResultBlockParam {
1211
+ content: BetaWebSearchToolResultBlockParamContent;
1212
+
1213
+ tool_use_id: string;
1214
+
1215
+ type: 'web_search_tool_result';
1216
+
1217
+ /**
1218
+ * Create a cache control breakpoint at this content block.
1219
+ */
1220
+ cache_control?: BetaCacheControlEphemeral | null;
1221
+ }
1222
+
1223
+ export type BetaWebSearchToolResultBlockParamContent =
1224
+ | Array<BetaWebSearchResultBlockParam>
1225
+ | BetaWebSearchToolRequestError;
1226
+
1227
+ export interface BetaWebSearchToolResultError {
1228
+ error_code:
1229
+ | 'invalid_tool_input'
1230
+ | 'unavailable'
1231
+ | 'max_uses_exceeded'
1232
+ | 'too_many_requests'
1233
+ | 'query_too_long';
1234
+
1235
+ type: 'web_search_tool_result_error';
932
1236
  }
933
1237
 
934
1238
  export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming;
@@ -1032,6 +1336,8 @@ export interface MessageCreateParamsBase {
1032
1336
  * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
1033
1337
  * the top-level `system` parameter — there is no `"system"` role for input
1034
1338
  * messages in the Messages API.
1339
+ *
1340
+ * There is a limit of 100000 messages in a single request.
1035
1341
  */
1036
1342
  messages: Array<BetaMessageParam>;
1037
1343
 
@@ -1327,6 +1633,8 @@ export interface MessageCountTokensParams {
1327
1633
  * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
1328
1634
  * the top-level `system` parameter — there is no `"system"` role for input
1329
1635
  * messages in the Messages API.
1636
+ *
1637
+ * There is a limit of 100000 messages in a single request.
1330
1638
  */
1331
1639
  messages: Array<BetaMessageParam>;
1332
1640
 
@@ -1444,6 +1752,7 @@ export interface MessageCountTokensParams {
1444
1752
  | BetaToolComputerUse20250124
1445
1753
  | BetaToolBash20250124
1446
1754
  | BetaToolTextEditor20250124
1755
+ | BetaWebSearchTool20250305
1447
1756
  >;
1448
1757
 
1449
1758
  /**
@@ -1467,8 +1776,10 @@ export declare namespace Messages {
1467
1776
  type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
1468
1777
  type BetaCitationPageLocation as BetaCitationPageLocation,
1469
1778
  type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
1779
+ type BetaCitationWebSearchResultLocationParam as BetaCitationWebSearchResultLocationParam,
1470
1780
  type BetaCitationsConfigParam as BetaCitationsConfigParam,
1471
1781
  type BetaCitationsDelta as BetaCitationsDelta,
1782
+ type BetaCitationsWebSearchResultLocation as BetaCitationsWebSearchResultLocation,
1472
1783
  type BetaContentBlock as BetaContentBlock,
1473
1784
  type BetaContentBlockParam as BetaContentBlockParam,
1474
1785
  type BetaContentBlockSource as BetaContentBlockSource,
@@ -1491,6 +1802,9 @@ export declare namespace Messages {
1491
1802
  type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
1492
1803
  type BetaRedactedThinkingBlock as BetaRedactedThinkingBlock,
1493
1804
  type BetaRedactedThinkingBlockParam as BetaRedactedThinkingBlockParam,
1805
+ type BetaServerToolUsage as BetaServerToolUsage,
1806
+ type BetaServerToolUseBlock as BetaServerToolUseBlock,
1807
+ type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
1494
1808
  type BetaSignatureDelta as BetaSignatureDelta,
1495
1809
  type BetaStopReason as BetaStopReason,
1496
1810
  type BetaTextBlock as BetaTextBlock,
@@ -1523,6 +1837,15 @@ export declare namespace Messages {
1523
1837
  type BetaURLImageSource as BetaURLImageSource,
1524
1838
  type BetaURLPDFSource as BetaURLPDFSource,
1525
1839
  type BetaUsage as BetaUsage,
1840
+ type BetaWebSearchResultBlock as BetaWebSearchResultBlock,
1841
+ type BetaWebSearchResultBlockParam as BetaWebSearchResultBlockParam,
1842
+ type BetaWebSearchTool20250305 as BetaWebSearchTool20250305,
1843
+ type BetaWebSearchToolRequestError as BetaWebSearchToolRequestError,
1844
+ type BetaWebSearchToolResultBlock as BetaWebSearchToolResultBlock,
1845
+ type BetaWebSearchToolResultBlockContent as BetaWebSearchToolResultBlockContent,
1846
+ type BetaWebSearchToolResultBlockParam as BetaWebSearchToolResultBlockParam,
1847
+ type BetaWebSearchToolResultBlockParamContent as BetaWebSearchToolResultBlockParamContent,
1848
+ type BetaWebSearchToolResultError as BetaWebSearchToolResultError,
1526
1849
  type MessageCreateParams as MessageCreateParams,
1527
1850
  type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
1528
1851
  type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
@@ -3,6 +3,7 @@
3
3
  import { APIResource } from "../../resource.js";
4
4
  import { isRequestOptions } from "../../core.js";
5
5
  import * as Core from "../../core.js";
6
+ import * as BetaAPI from "./beta.js";
6
7
  import { Page, type PageParams } from "../../pagination.js";
7
8
 
8
9
  export class Models extends APIResource {
@@ -11,9 +12,36 @@ export class Models extends APIResource {
11
12
  *
12
13
  * The Models API response can be used to determine information about a specific
13
14
  * model or resolve a model alias to a model ID.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const betaModelInfo = await client.beta.models.retrieve(
19
+ * 'model_id',
20
+ * );
21
+ * ```
14
22
  */
15
- retrieve(modelId: string, options?: Core.RequestOptions): Core.APIPromise<BetaModelInfo> {
16
- return this._client.get(`/v1/models/${modelId}?beta=true`, options);
23
+ retrieve(
24
+ modelId: string,
25
+ params?: ModelRetrieveParams,
26
+ options?: Core.RequestOptions,
27
+ ): Core.APIPromise<BetaModelInfo>;
28
+ retrieve(modelId: string, options?: Core.RequestOptions): Core.APIPromise<BetaModelInfo>;
29
+ retrieve(
30
+ modelId: string,
31
+ params: ModelRetrieveParams | Core.RequestOptions = {},
32
+ options?: Core.RequestOptions,
33
+ ): Core.APIPromise<BetaModelInfo> {
34
+ if (isRequestOptions(params)) {
35
+ return this.retrieve(modelId, {}, params);
36
+ }
37
+ const { betas } = params;
38
+ return this._client.get(`/v1/models/${modelId}?beta=true`, {
39
+ ...options,
40
+ headers: {
41
+ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
42
+ ...options?.headers,
43
+ },
44
+ });
17
45
  }
18
46
 
19
47
  /**
@@ -21,20 +49,36 @@ export class Models extends APIResource {
21
49
  *
22
50
  * The Models API response can be used to determine which models are available for
23
51
  * use in the API. More recently released models are listed first.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * // Automatically fetches more pages as needed.
56
+ * for await (const betaModelInfo of client.beta.models.list()) {
57
+ * // ...
58
+ * }
59
+ * ```
24
60
  */
25
61
  list(
26
- query?: ModelListParams,
62
+ params?: ModelListParams,
27
63
  options?: Core.RequestOptions,
28
64
  ): Core.PagePromise<BetaModelInfosPage, BetaModelInfo>;
29
65
  list(options?: Core.RequestOptions): Core.PagePromise<BetaModelInfosPage, BetaModelInfo>;
30
66
  list(
31
- query: ModelListParams | Core.RequestOptions = {},
67
+ params: ModelListParams | Core.RequestOptions = {},
32
68
  options?: Core.RequestOptions,
33
69
  ): Core.PagePromise<BetaModelInfosPage, BetaModelInfo> {
34
- if (isRequestOptions(query)) {
35
- return this.list({}, query);
70
+ if (isRequestOptions(params)) {
71
+ return this.list({}, params);
36
72
  }
37
- return this._client.getAPIList('/v1/models?beta=true', BetaModelInfosPage, { query, ...options });
73
+ const { betas, ...query } = params;
74
+ return this._client.getAPIList('/v1/models?beta=true', BetaModelInfosPage, {
75
+ query,
76
+ ...options,
77
+ headers: {
78
+ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
79
+ ...options?.headers,
80
+ },
81
+ });
38
82
  }
39
83
  }
40
84
 
@@ -65,7 +109,19 @@ export interface BetaModelInfo {
65
109
  type: 'model';
66
110
  }
67
111
 
68
- export interface ModelListParams extends PageParams {}
112
+ export interface ModelRetrieveParams {
113
+ /**
114
+ * Optional header to specify the beta version(s) you want to use.
115
+ */
116
+ betas?: Array<BetaAPI.AnthropicBeta>;
117
+ }
118
+
119
+ export interface ModelListParams extends PageParams {
120
+ /**
121
+ * Header param: Optional header to specify the beta version(s) you want to use.
122
+ */
123
+ betas?: Array<BetaAPI.AnthropicBeta>;
124
+ }
69
125
 
70
126
  Models.BetaModelInfosPage = BetaModelInfosPage;
71
127
 
@@ -73,6 +129,7 @@ export declare namespace Models {
73
129
  export {
74
130
  type BetaModelInfo as BetaModelInfo,
75
131
  BetaModelInfosPage as BetaModelInfosPage,
132
+ type ModelRetrieveParams as ModelRetrieveParams,
76
133
  type ModelListParams as ModelListParams,
77
134
  };
78
135
  }