@anthropic-ai/sdk 0.32.1 → 0.33.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 (129) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +27 -15
  3. package/core.d.ts +12 -8
  4. package/core.d.ts.map +1 -1
  5. package/core.js +20 -14
  6. package/core.js.map +1 -1
  7. package/core.mjs +20 -14
  8. package/core.mjs.map +1 -1
  9. package/error.d.ts +18 -24
  10. package/error.d.ts.map +1 -1
  11. package/error.js +1 -31
  12. package/error.js.map +1 -1
  13. package/error.mjs +1 -31
  14. package/error.mjs.map +1 -1
  15. package/index.d.mts +21 -8
  16. package/index.d.ts +21 -8
  17. package/index.d.ts.map +1 -1
  18. package/index.js +13 -8
  19. package/index.js.map +1 -1
  20. package/index.mjs +9 -6
  21. package/index.mjs.map +1 -1
  22. package/package.json +1 -1
  23. package/resources/beta/beta.d.ts +14 -6
  24. package/resources/beta/beta.d.ts.map +1 -1
  25. package/resources/beta/beta.js +5 -4
  26. package/resources/beta/beta.js.map +1 -1
  27. package/resources/beta/beta.mjs +5 -4
  28. package/resources/beta/beta.mjs.map +1 -1
  29. package/resources/beta/index.d.ts +2 -2
  30. package/resources/beta/index.d.ts.map +1 -1
  31. package/resources/beta/index.js +4 -3
  32. package/resources/beta/index.js.map +1 -1
  33. package/resources/beta/index.mjs +1 -1
  34. package/resources/beta/index.mjs.map +1 -1
  35. package/resources/beta/messages/messages.d.ts +1 -1
  36. package/resources/beta/messages/messages.d.ts.map +1 -1
  37. package/resources/beta/models.d.ts +49 -0
  38. package/resources/beta/models.d.ts.map +1 -0
  39. package/resources/beta/models.js +30 -0
  40. package/resources/beta/models.js.map +1 -0
  41. package/resources/beta/models.mjs +25 -0
  42. package/resources/beta/models.mjs.map +1 -0
  43. package/resources/completions.d.ts +1 -1
  44. package/resources/completions.d.ts.map +1 -1
  45. package/resources/index.d.ts +4 -2
  46. package/resources/index.d.ts.map +1 -1
  47. package/resources/index.js +20 -2
  48. package/resources/index.js.map +1 -1
  49. package/resources/index.mjs +3 -1
  50. package/resources/index.mjs.map +1 -1
  51. package/resources/messages/batches.d.ts +212 -0
  52. package/resources/messages/batches.d.ts.map +1 -0
  53. package/resources/messages/batches.js +71 -0
  54. package/resources/messages/batches.js.map +1 -0
  55. package/resources/messages/batches.mjs +66 -0
  56. package/resources/messages/batches.mjs.map +1 -0
  57. package/resources/messages/index.d.ts +3 -0
  58. package/resources/messages/index.d.ts.map +1 -0
  59. package/resources/messages/index.js +10 -0
  60. package/resources/messages/index.js.map +1 -0
  61. package/resources/{beta/prompt-caching → messages}/index.mjs +1 -1
  62. package/resources/messages/index.mjs.map +1 -0
  63. package/resources/{messages.d.ts → messages/messages.d.ts} +235 -9
  64. package/resources/messages/messages.d.ts.map +1 -0
  65. package/resources/messages/messages.js +76 -0
  66. package/resources/messages/messages.js.map +1 -0
  67. package/resources/{messages.mjs → messages/messages.mjs} +20 -3
  68. package/resources/messages/messages.mjs.map +1 -0
  69. package/resources/models.d.ts +49 -0
  70. package/resources/models.d.ts.map +1 -0
  71. package/resources/models.js +30 -0
  72. package/resources/models.js.map +1 -0
  73. package/resources/models.mjs +25 -0
  74. package/resources/models.mjs.map +1 -0
  75. package/resources/shared.d.ts +42 -0
  76. package/resources/shared.d.ts.map +1 -0
  77. package/resources/shared.js +4 -0
  78. package/resources/shared.js.map +1 -0
  79. package/resources/shared.mjs +3 -0
  80. package/resources/shared.mjs.map +1 -0
  81. package/src/core.ts +52 -32
  82. package/src/error.ts +23 -39
  83. package/src/index.ts +72 -37
  84. package/src/resources/beta/beta.ts +28 -6
  85. package/src/resources/beta/index.ts +3 -1
  86. package/src/resources/beta/messages/messages.ts +1 -1
  87. package/src/resources/beta/models.ts +78 -0
  88. package/src/resources/completions.ts +1 -1
  89. package/src/resources/index.ts +11 -1
  90. package/src/resources/messages/batches.ts +298 -0
  91. package/src/resources/messages/index.ts +63 -0
  92. package/src/resources/{messages.ts → messages/messages.ts} +304 -10
  93. package/src/resources/models.ts +75 -0
  94. package/src/resources/shared.ts +72 -0
  95. package/src/version.ts +1 -1
  96. package/version.d.ts +1 -1
  97. package/version.js +1 -1
  98. package/version.mjs +1 -1
  99. package/lib/PromptCachingBetaMessageStream.d.ts +0 -96
  100. package/lib/PromptCachingBetaMessageStream.d.ts.map +0 -1
  101. package/lib/PromptCachingBetaMessageStream.js +0 -459
  102. package/lib/PromptCachingBetaMessageStream.js.map +0 -1
  103. package/lib/PromptCachingBetaMessageStream.mjs +0 -455
  104. package/lib/PromptCachingBetaMessageStream.mjs.map +0 -1
  105. package/resources/beta/prompt-caching/index.d.ts +0 -3
  106. package/resources/beta/prompt-caching/index.d.ts.map +0 -1
  107. package/resources/beta/prompt-caching/index.js +0 -9
  108. package/resources/beta/prompt-caching/index.js.map +0 -1
  109. package/resources/beta/prompt-caching/index.mjs.map +0 -1
  110. package/resources/beta/prompt-caching/messages.d.ts +0 -518
  111. package/resources/beta/prompt-caching/messages.d.ts.map +0 -1
  112. package/resources/beta/prompt-caching/messages.js +0 -29
  113. package/resources/beta/prompt-caching/messages.js.map +0 -1
  114. package/resources/beta/prompt-caching/messages.mjs +0 -25
  115. package/resources/beta/prompt-caching/messages.mjs.map +0 -1
  116. package/resources/beta/prompt-caching/prompt-caching.d.ts +0 -10
  117. package/resources/beta/prompt-caching/prompt-caching.d.ts.map +0 -1
  118. package/resources/beta/prompt-caching/prompt-caching.js +0 -39
  119. package/resources/beta/prompt-caching/prompt-caching.js.map +0 -1
  120. package/resources/beta/prompt-caching/prompt-caching.mjs +0 -12
  121. package/resources/beta/prompt-caching/prompt-caching.mjs.map +0 -1
  122. package/resources/messages.d.ts.map +0 -1
  123. package/resources/messages.js +0 -36
  124. package/resources/messages.js.map +0 -1
  125. package/resources/messages.mjs.map +0 -1
  126. package/src/lib/PromptCachingBetaMessageStream.ts +0 -579
  127. package/src/resources/beta/prompt-caching/index.ts +0 -20
  128. package/src/resources/beta/prompt-caching/messages.ts +0 -642
  129. package/src/resources/beta/prompt-caching/prompt-caching.ts +0 -47
@@ -1,15 +1,32 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { APIResource } from "../resource.js";
4
- import { APIPromise } from "../core.js";
5
- import * as Core from "../core.js";
3
+ import { APIResource } from "../../resource.js";
4
+ import { APIPromise } from "../../core.js";
5
+ import * as Core from "../../core.js";
6
6
  import * as MessagesAPI from "./messages.js";
7
- import { Stream } from "../streaming.js";
8
- import { MessageStream } from "../lib/MessageStream.js";
9
-
10
- export { MessageStream } from "../lib/MessageStream.js";
7
+ import * as BatchesAPI from "./batches.js";
8
+ import {
9
+ BatchCreateParams,
10
+ BatchListParams,
11
+ Batches,
12
+ MessageBatch,
13
+ MessageBatchCanceledResult,
14
+ MessageBatchErroredResult,
15
+ MessageBatchExpiredResult,
16
+ MessageBatchIndividualResponse,
17
+ MessageBatchRequestCounts,
18
+ MessageBatchResult,
19
+ MessageBatchSucceededResult,
20
+ MessageBatchesPage,
21
+ } from "./batches.js";
22
+ import { Stream } from "../../streaming.js";
23
+ import { MessageStream } from "../../lib/MessageStream.js";
24
+
25
+ export { MessageStream } from "../../lib/MessageStream.js";
11
26
 
12
27
  export class Messages extends APIResource {
28
+ batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
29
+
13
30
  /**
14
31
  * Send a structured list of input messages with text and/or image content, and the
15
32
  * model will generate the next message in the conversation.
@@ -51,20 +68,62 @@ export class Messages extends APIResource {
51
68
  stream(body: MessageStreamParams, options?: Core.RequestOptions): MessageStream {
52
69
  return MessageStream.createMessage(this, body, options);
53
70
  }
71
+
72
+ /**
73
+ * Count the number of tokens in a Message.
74
+ *
75
+ * The Token Count API can be used to count the number of tokens in a Message,
76
+ * including tools, images, and documents, without creating it.
77
+ */
78
+ countTokens(
79
+ body: MessageCountTokensParams,
80
+ options?: Core.RequestOptions,
81
+ ): Core.APIPromise<MessageTokensCount> {
82
+ return this._client.post('/v1/messages/count_tokens', { body, ...options });
83
+ }
84
+ }
85
+
86
+ export interface Base64PDFSource {
87
+ data: string;
88
+
89
+ media_type: 'application/pdf';
90
+
91
+ type: 'base64';
92
+ }
93
+
94
+ export interface CacheControlEphemeral {
95
+ type: 'ephemeral';
54
96
  }
55
97
 
56
98
  export type ContentBlock = TextBlock | ToolUseBlock;
57
99
 
58
100
  export type ContentBlockDeltaEvent = RawContentBlockDeltaEvent;
59
101
 
102
+ export type ContentBlockParam =
103
+ | TextBlockParam
104
+ | ImageBlockParam
105
+ | ToolUseBlockParam
106
+ | ToolResultBlockParam
107
+ | DocumentBlockParam;
108
+
60
109
  export type ContentBlockStartEvent = RawContentBlockStartEvent;
61
110
 
62
111
  export type ContentBlockStopEvent = RawContentBlockStopEvent;
63
112
 
113
+ export interface DocumentBlockParam {
114
+ source: Base64PDFSource;
115
+
116
+ type: 'document';
117
+
118
+ cache_control?: CacheControlEphemeral | null;
119
+ }
120
+
64
121
  export interface ImageBlockParam {
65
122
  source: ImageBlockParam.Source;
66
123
 
67
124
  type: 'image';
125
+
126
+ cache_control?: CacheControlEphemeral | null;
68
127
  }
69
128
 
70
129
  export namespace ImageBlockParam {
@@ -200,7 +259,7 @@ export interface MessageDeltaUsage {
200
259
  }
201
260
 
202
261
  export interface MessageParam {
203
- content: string | Array<TextBlockParam | ImageBlockParam | ToolUseBlockParam | ToolResultBlockParam>;
262
+ content: string | Array<ContentBlockParam>;
204
263
 
205
264
  role: 'user' | 'assistant';
206
265
  }
@@ -211,6 +270,14 @@ export type MessageStopEvent = RawMessageStopEvent;
211
270
 
212
271
  export type MessageStreamEvent = RawMessageStreamEvent;
213
272
 
273
+ export interface MessageTokensCount {
274
+ /**
275
+ * The total number of tokens across the provided list of messages, system prompt,
276
+ * and tools.
277
+ */
278
+ input_tokens: number;
279
+ }
280
+
214
281
  export interface Metadata {
215
282
  /**
216
283
  * An external identifier for the user who is associated with the request.
@@ -239,8 +306,7 @@ export type Model =
239
306
  | 'claude-3-sonnet-20240229'
240
307
  | 'claude-3-haiku-20240307'
241
308
  | 'claude-2.1'
242
- | 'claude-2.0'
243
- | 'claude-instant-1.2';
309
+ | 'claude-2.0';
244
310
 
245
311
  type DeprecatedModelsType = {
246
312
  [K in Model]?: string;
@@ -334,6 +400,8 @@ export interface TextBlockParam {
334
400
  text: string;
335
401
 
336
402
  type: 'text';
403
+
404
+ cache_control?: CacheControlEphemeral | null;
337
405
  }
338
406
 
339
407
  export interface TextDelta {
@@ -358,6 +426,8 @@ export interface Tool {
358
426
  */
359
427
  name: string;
360
428
 
429
+ cache_control?: CacheControlEphemeral | null;
430
+
361
431
  /**
362
432
  * Description of what this tool does.
363
433
  *
@@ -445,6 +515,8 @@ export interface ToolResultBlockParam {
445
515
 
446
516
  type: 'tool_result';
447
517
 
518
+ cache_control?: CacheControlEphemeral | null;
519
+
448
520
  content?: string | Array<TextBlockParam | ImageBlockParam>;
449
521
 
450
522
  is_error?: boolean;
@@ -468,9 +540,21 @@ export interface ToolUseBlockParam {
468
540
  name: string;
469
541
 
470
542
  type: 'tool_use';
543
+
544
+ cache_control?: CacheControlEphemeral | null;
471
545
  }
472
546
 
473
547
  export interface Usage {
548
+ /**
549
+ * The number of input tokens used to create the cache entry.
550
+ */
551
+ cache_creation_input_tokens: number | null;
552
+
553
+ /**
554
+ * The number of input tokens read from the cache.
555
+ */
556
+ cache_read_input_tokens: number | null;
557
+
474
558
  /**
475
559
  * The number of input tokens which were used.
476
560
  */
@@ -790,12 +874,205 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
790
874
 
791
875
  export type MessageStreamParams = MessageCreateParamsBase;
792
876
 
877
+ export interface MessageCountTokensParams {
878
+ /**
879
+ * Input messages.
880
+ *
881
+ * Our models are trained to operate on alternating `user` and `assistant`
882
+ * conversational turns. When creating a new `Message`, you specify the prior
883
+ * conversational turns with the `messages` parameter, and the model then generates
884
+ * the next `Message` in the conversation. Consecutive `user` or `assistant` turns
885
+ * in your request will be combined into a single turn.
886
+ *
887
+ * Each input message must be an object with a `role` and `content`. You can
888
+ * specify a single `user`-role message, or you can include multiple `user` and
889
+ * `assistant` messages.
890
+ *
891
+ * If the final message uses the `assistant` role, the response content will
892
+ * continue immediately from the content in that message. This can be used to
893
+ * constrain part of the model's response.
894
+ *
895
+ * Example with a single `user` message:
896
+ *
897
+ * ```json
898
+ * [{ "role": "user", "content": "Hello, Claude" }]
899
+ * ```
900
+ *
901
+ * Example with multiple conversational turns:
902
+ *
903
+ * ```json
904
+ * [
905
+ * { "role": "user", "content": "Hello there." },
906
+ * { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
907
+ * { "role": "user", "content": "Can you explain LLMs in plain English?" }
908
+ * ]
909
+ * ```
910
+ *
911
+ * Example with a partially-filled response from Claude:
912
+ *
913
+ * ```json
914
+ * [
915
+ * {
916
+ * "role": "user",
917
+ * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
918
+ * },
919
+ * { "role": "assistant", "content": "The best answer is (" }
920
+ * ]
921
+ * ```
922
+ *
923
+ * Each input message `content` may be either a single `string` or an array of
924
+ * content blocks, where each block has a specific `type`. Using a `string` for
925
+ * `content` is shorthand for an array of one content block of type `"text"`. The
926
+ * following input messages are equivalent:
927
+ *
928
+ * ```json
929
+ * { "role": "user", "content": "Hello, Claude" }
930
+ * ```
931
+ *
932
+ * ```json
933
+ * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
934
+ * ```
935
+ *
936
+ * Starting with Claude 3 models, you can also send image content blocks:
937
+ *
938
+ * ```json
939
+ * {
940
+ * "role": "user",
941
+ * "content": [
942
+ * {
943
+ * "type": "image",
944
+ * "source": {
945
+ * "type": "base64",
946
+ * "media_type": "image/jpeg",
947
+ * "data": "/9j/4AAQSkZJRg..."
948
+ * }
949
+ * },
950
+ * { "type": "text", "text": "What is in this image?" }
951
+ * ]
952
+ * }
953
+ * ```
954
+ *
955
+ * We currently support the `base64` source type for images, and the `image/jpeg`,
956
+ * `image/png`, `image/gif`, and `image/webp` media types.
957
+ *
958
+ * See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
959
+ * more input examples.
960
+ *
961
+ * Note that if you want to include a
962
+ * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
963
+ * the top-level `system` parameter — there is no `"system"` role for input
964
+ * messages in the Messages API.
965
+ */
966
+ messages: Array<MessageParam>;
967
+
968
+ /**
969
+ * The model that will complete your prompt.\n\nSee
970
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for additional
971
+ * details and options.
972
+ */
973
+ model: Model;
974
+
975
+ /**
976
+ * System prompt.
977
+ *
978
+ * A system prompt is a way of providing context and instructions to Claude, such
979
+ * as specifying a particular goal or role. See our
980
+ * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
981
+ */
982
+ system?: string | Array<TextBlockParam>;
983
+
984
+ /**
985
+ * How the model should use the provided tools. The model can use a specific tool,
986
+ * any available tool, or decide by itself.
987
+ */
988
+ tool_choice?: ToolChoice;
989
+
990
+ /**
991
+ * Definitions of tools that the model may use.
992
+ *
993
+ * If you include `tools` in your API request, the model may return `tool_use`
994
+ * content blocks that represent the model's use of those tools. You can then run
995
+ * those tools using the tool input generated by the model and then optionally
996
+ * return results back to the model using `tool_result` content blocks.
997
+ *
998
+ * Each tool definition includes:
999
+ *
1000
+ * - `name`: Name of the tool.
1001
+ * - `description`: Optional, but strongly-recommended description of the tool.
1002
+ * - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
1003
+ * shape that the model will produce in `tool_use` output content blocks.
1004
+ *
1005
+ * For example, if you defined `tools` as:
1006
+ *
1007
+ * ```json
1008
+ * [
1009
+ * {
1010
+ * "name": "get_stock_price",
1011
+ * "description": "Get the current stock price for a given ticker symbol.",
1012
+ * "input_schema": {
1013
+ * "type": "object",
1014
+ * "properties": {
1015
+ * "ticker": {
1016
+ * "type": "string",
1017
+ * "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
1018
+ * }
1019
+ * },
1020
+ * "required": ["ticker"]
1021
+ * }
1022
+ * }
1023
+ * ]
1024
+ * ```
1025
+ *
1026
+ * And then asked the model "What's the S&P 500 at today?", the model might produce
1027
+ * `tool_use` content blocks in the response like this:
1028
+ *
1029
+ * ```json
1030
+ * [
1031
+ * {
1032
+ * "type": "tool_use",
1033
+ * "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
1034
+ * "name": "get_stock_price",
1035
+ * "input": { "ticker": "^GSPC" }
1036
+ * }
1037
+ * ]
1038
+ * ```
1039
+ *
1040
+ * You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
1041
+ * input, and return the following back to the model in a subsequent `user`
1042
+ * message:
1043
+ *
1044
+ * ```json
1045
+ * [
1046
+ * {
1047
+ * "type": "tool_result",
1048
+ * "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
1049
+ * "content": "259.75 USD"
1050
+ * }
1051
+ * ]
1052
+ * ```
1053
+ *
1054
+ * Tools can be used for workflows that include running client-side tools and
1055
+ * functions, or more generally whenever you want the model to produce a particular
1056
+ * JSON structure of output.
1057
+ *
1058
+ * See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
1059
+ */
1060
+ tools?: Array<Tool>;
1061
+ }
1062
+
1063
+ Messages.Batches = Batches;
1064
+ Messages.MessageBatchesPage = MessageBatchesPage;
1065
+
793
1066
  export declare namespace Messages {
794
1067
  export {
1068
+ type Base64PDFSource as Base64PDFSource,
1069
+ type CacheControlEphemeral as CacheControlEphemeral,
795
1070
  type ContentBlock as ContentBlock,
796
1071
  type ContentBlockDeltaEvent as ContentBlockDeltaEvent,
1072
+ type ContentBlockParam as ContentBlockParam,
797
1073
  type ContentBlockStartEvent as ContentBlockStartEvent,
798
1074
  type ContentBlockStopEvent as ContentBlockStopEvent,
1075
+ type DocumentBlockParam as DocumentBlockParam,
799
1076
  type ImageBlockParam as ImageBlockParam,
800
1077
  type InputJsonDelta as InputJsonDelta,
801
1078
  type InputJSONDelta as InputJSONDelta,
@@ -806,6 +1083,7 @@ export declare namespace Messages {
806
1083
  type MessageStartEvent as MessageStartEvent,
807
1084
  type MessageStopEvent as MessageStopEvent,
808
1085
  type MessageStreamEvent as MessageStreamEvent,
1086
+ type MessageTokensCount as MessageTokensCount,
809
1087
  type Metadata as Metadata,
810
1088
  type Model as Model,
811
1089
  type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent,
@@ -831,5 +1109,21 @@ export declare namespace Messages {
831
1109
  type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
832
1110
  type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
833
1111
  type MessageStreamParams as MessageStreamParams,
1112
+ type MessageCountTokensParams as MessageCountTokensParams,
1113
+ };
1114
+
1115
+ export {
1116
+ Batches as Batches,
1117
+ type MessageBatch as MessageBatch,
1118
+ type MessageBatchCanceledResult as MessageBatchCanceledResult,
1119
+ type MessageBatchErroredResult as MessageBatchErroredResult,
1120
+ type MessageBatchExpiredResult as MessageBatchExpiredResult,
1121
+ type MessageBatchIndividualResponse as MessageBatchIndividualResponse,
1122
+ type MessageBatchRequestCounts as MessageBatchRequestCounts,
1123
+ type MessageBatchResult as MessageBatchResult,
1124
+ type MessageBatchSucceededResult as MessageBatchSucceededResult,
1125
+ MessageBatchesPage as MessageBatchesPage,
1126
+ type BatchCreateParams as BatchCreateParams,
1127
+ type BatchListParams as BatchListParams,
834
1128
  };
835
1129
  }
@@ -0,0 +1,75 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../resource.js";
4
+ import { isRequestOptions } from "../core.js";
5
+ import * as Core from "../core.js";
6
+ import { Page, type PageParams } from "../pagination.js";
7
+
8
+ export class Models extends APIResource {
9
+ /**
10
+ * Get a specific model.
11
+ *
12
+ * The Models API response can be used to determine information about a specific
13
+ * model or resolve a model alias to a model ID.
14
+ */
15
+ retrieve(modelId: string, options?: Core.RequestOptions): Core.APIPromise<ModelInfo> {
16
+ return this._client.get(`/v1/models/${modelId}`, options);
17
+ }
18
+
19
+ /**
20
+ * List available models.
21
+ *
22
+ * The Models API response can be used to determine which models are available for
23
+ * use in the API. More recently released models are listed first.
24
+ */
25
+ list(query?: ModelListParams, options?: Core.RequestOptions): Core.PagePromise<ModelInfosPage, ModelInfo>;
26
+ list(options?: Core.RequestOptions): Core.PagePromise<ModelInfosPage, ModelInfo>;
27
+ list(
28
+ query: ModelListParams | Core.RequestOptions = {},
29
+ options?: Core.RequestOptions,
30
+ ): Core.PagePromise<ModelInfosPage, ModelInfo> {
31
+ if (isRequestOptions(query)) {
32
+ return this.list({}, query);
33
+ }
34
+ return this._client.getAPIList('/v1/models', ModelInfosPage, { query, ...options });
35
+ }
36
+ }
37
+
38
+ export class ModelInfosPage extends Page<ModelInfo> {}
39
+
40
+ export interface ModelInfo {
41
+ /**
42
+ * Unique model identifier.
43
+ */
44
+ id: string;
45
+
46
+ /**
47
+ * RFC 3339 datetime string representing the time at which the model was released.
48
+ * May be set to an epoch value if the release date is unknown.
49
+ */
50
+ created_at: string;
51
+
52
+ /**
53
+ * A human-readable name for the model.
54
+ */
55
+ display_name: string;
56
+
57
+ /**
58
+ * Object type.
59
+ *
60
+ * For Models, this is always `"model"`.
61
+ */
62
+ type: 'model';
63
+ }
64
+
65
+ export interface ModelListParams extends PageParams {}
66
+
67
+ Models.ModelInfosPage = ModelInfosPage;
68
+
69
+ export declare namespace Models {
70
+ export {
71
+ type ModelInfo as ModelInfo,
72
+ ModelInfosPage as ModelInfosPage,
73
+ type ModelListParams as ModelListParams,
74
+ };
75
+ }
@@ -0,0 +1,72 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export interface APIErrorObject {
4
+ message: string;
5
+
6
+ type: 'api_error';
7
+ }
8
+
9
+ export interface AuthenticationError {
10
+ message: string;
11
+
12
+ type: 'authentication_error';
13
+ }
14
+
15
+ export interface BillingError {
16
+ message: string;
17
+
18
+ type: 'billing_error';
19
+ }
20
+
21
+ export type ErrorObject =
22
+ | InvalidRequestError
23
+ | AuthenticationError
24
+ | BillingError
25
+ | PermissionError
26
+ | NotFoundError
27
+ | RateLimitError
28
+ | GatewayTimeoutError
29
+ | APIErrorObject
30
+ | OverloadedError;
31
+
32
+ export interface ErrorResponse {
33
+ error: ErrorObject;
34
+
35
+ type: 'error';
36
+ }
37
+
38
+ export interface GatewayTimeoutError {
39
+ message: string;
40
+
41
+ type: 'timeout_error';
42
+ }
43
+
44
+ export interface InvalidRequestError {
45
+ message: string;
46
+
47
+ type: 'invalid_request_error';
48
+ }
49
+
50
+ export interface NotFoundError {
51
+ message: string;
52
+
53
+ type: 'not_found_error';
54
+ }
55
+
56
+ export interface OverloadedError {
57
+ message: string;
58
+
59
+ type: 'overloaded_error';
60
+ }
61
+
62
+ export interface PermissionError {
63
+ message: string;
64
+
65
+ type: 'permission_error';
66
+ }
67
+
68
+ export interface RateLimitError {
69
+ message: string;
70
+
71
+ type: 'rate_limit_error';
72
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.32.1'; // x-release-please-version
1
+ export const VERSION = '0.33.0'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.32.1";
1
+ export declare const VERSION = "0.33.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.32.1'; // x-release-please-version
4
+ exports.VERSION = '0.33.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.32.1'; // x-release-please-version
1
+ export const VERSION = '0.33.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map
@@ -1,96 +0,0 @@
1
-
2
- import * as Core from '@anthropic-ai/sdk/core';
3
- import { AnthropicError, APIUserAbortError } from '@anthropic-ai/sdk/error';
4
- import { type ContentBlock } from '@anthropic-ai/sdk/resources/messages';
5
- import { Messages, type PromptCachingBetaMessage, type RawPromptCachingBetaMessageStreamEvent, type PromptCachingBetaMessageParam, type MessageCreateParams, type MessageCreateParamsBase } from '@anthropic-ai/sdk/resources/beta/prompt-caching/messages';
6
- import { type ReadableStream } from '@anthropic-ai/sdk/_shims/index';
7
- export interface PromptCachingBetaMessageStreamEvents {
8
- connect: () => void;
9
- streamEvent: (event: RawPromptCachingBetaMessageStreamEvent, snapshot: PromptCachingBetaMessage) => void;
10
- text: (textDelta: string, textSnapshot: string) => void;
11
- inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
12
- message: (message: PromptCachingBetaMessage) => void;
13
- contentBlock: (content: ContentBlock) => void;
14
- finalPromptCachingBetaMessage: (message: PromptCachingBetaMessage) => void;
15
- error: (error: AnthropicError) => void;
16
- abort: (error: APIUserAbortError) => void;
17
- end: () => void;
18
- }
19
- export declare class PromptCachingBetaMessageStream implements AsyncIterable<RawPromptCachingBetaMessageStreamEvent> {
20
- #private;
21
- messages: PromptCachingBetaMessageParam[];
22
- receivedMessages: PromptCachingBetaMessage[];
23
- controller: AbortController;
24
- constructor();
25
- /**
26
- * Intended for use on the frontend, consuming a stream produced with
27
- * `.toReadableStream()` on the backend.
28
- *
29
- * Note that messages sent to the model do not appear in `.on('message')`
30
- * in this context.
31
- */
32
- static fromReadableStream(stream: ReadableStream): PromptCachingBetaMessageStream;
33
- static createMessage(messages: Messages, params: MessageCreateParamsBase, options?: Core.RequestOptions): PromptCachingBetaMessageStream;
34
- protected _run(executor: () => Promise<any>): void;
35
- protected _addPromptCachingBetaMessageParam(message: PromptCachingBetaMessageParam): void;
36
- protected _addPromptCachingBetaMessage(message: PromptCachingBetaMessage, emit?: boolean): void;
37
- protected _createPromptCachingBetaMessage(messages: Messages, params: MessageCreateParams, options?: Core.RequestOptions): Promise<void>;
38
- protected _connected(): void;
39
- get ended(): boolean;
40
- get errored(): boolean;
41
- get aborted(): boolean;
42
- abort(): void;
43
- /**
44
- * Adds the listener function to the end of the listeners array for the event.
45
- * No checks are made to see if the listener has already been added. Multiple calls passing
46
- * the same combination of event and listener will result in the listener being added, and
47
- * called, multiple times.
48
- * @returns this PromptCachingBetaMessageStream, so that calls can be chained
49
- */
50
- on<Event extends keyof PromptCachingBetaMessageStreamEvents>(event: Event, listener: PromptCachingBetaMessageStreamEvents[Event]): this;
51
- /**
52
- * Removes the specified listener from the listener array for the event.
53
- * off() will remove, at most, one instance of a listener from the listener array. If any single
54
- * listener has been added multiple times to the listener array for the specified event, then
55
- * off() must be called multiple times to remove each instance.
56
- * @returns this PromptCachingBetaMessageStream, so that calls can be chained
57
- */
58
- off<Event extends keyof PromptCachingBetaMessageStreamEvents>(event: Event, listener: PromptCachingBetaMessageStreamEvents[Event]): this;
59
- /**
60
- * Adds a one-time listener function for the event. The next time the event is triggered,
61
- * this listener is removed and then invoked.
62
- * @returns this PromptCachingBetaMessageStream, so that calls can be chained
63
- */
64
- once<Event extends keyof PromptCachingBetaMessageStreamEvents>(event: Event, listener: PromptCachingBetaMessageStreamEvents[Event]): this;
65
- /**
66
- * This is similar to `.once()`, but returns a Promise that resolves the next time
67
- * the event is triggered, instead of calling a listener callback.
68
- * @returns a Promise that resolves the next time given event is triggered,
69
- * or rejects if an error is emitted. (If you request the 'error' event,
70
- * returns a promise that resolves with the error).
71
- *
72
- * Example:
73
- *
74
- * const message = await stream.emitted('message') // rejects if the stream errors
75
- */
76
- emitted<Event extends keyof PromptCachingBetaMessageStreamEvents>(event: Event): Promise<Parameters<PromptCachingBetaMessageStreamEvents[Event]> extends [infer Param] ? Param : Parameters<PromptCachingBetaMessageStreamEvents[Event]> extends [] ? void : Parameters<PromptCachingBetaMessageStreamEvents[Event]>>;
77
- done(): Promise<void>;
78
- get currentMessage(): PromptCachingBetaMessage | undefined;
79
- /**
80
- * @returns a promise that resolves with the the final assistant PromptCachingBetaMessage response,
81
- * or rejects if an error occurred or the stream ended prematurely without producing a PromptCachingBetaMessage.
82
- */
83
- finalMessage(): Promise<PromptCachingBetaMessage>;
84
- /**
85
- * @returns a promise that resolves with the the final assistant PromptCachingBetaMessage's text response, concatenated
86
- * together if there are more than one text blocks.
87
- * Rejects if an error occurred or the stream ended prematurely without producing a PromptCachingBetaMessage.
88
- */
89
- finalText(): Promise<string>;
90
- protected _emit<Event extends keyof PromptCachingBetaMessageStreamEvents>(event: Event, ...args: Parameters<PromptCachingBetaMessageStreamEvents[Event]>): void;
91
- protected _emitFinal(): void;
92
- protected _fromReadableStream(readableStream: ReadableStream, options?: Core.RequestOptions): Promise<void>;
93
- [Symbol.asyncIterator](): AsyncIterator<RawPromptCachingBetaMessageStreamEvent>;
94
- toReadableStream(): ReadableStream;
95
- }
96
- //# sourceMappingURL=PromptCachingBetaMessageStream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromptCachingBetaMessageStream.d.ts","sourceRoot":"","sources":["../src/lib/PromptCachingBetaMessageStream.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,sCAAsC,CAAC;AACzF,OAAO,EACL,QAAQ,EACR,KAAK,wBAAwB,EAC7B,KAAK,sCAAsC,EAC3C,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC7B,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIrE,MAAM,WAAW,oCAAoC;IACnD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,EAAE,CAAC,KAAK,EAAE,sCAAsC,EAAE,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACzG,IAAI,EAAE,CAAC,SAAS,EAAE,M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