@anthropic-ai/sdk 0.32.0 → 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 +52 -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.mjs","sourceRoot":"","sources":["../src/resources/shared.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
package/src/core.ts CHANGED
@@ -37,7 +37,7 @@ type APIResponseProps = {
37
37
  controller: AbortController;
38
38
  };
39
39
 
40
- async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
40
+ async function defaultParseResponse<T>(props: APIResponseProps): Promise<WithRequestID<T>> {
41
41
  const { response } = props;
42
42
  if (props.options.stream) {
43
43
  debug('response', response.status, response.url, response.headers, response.body);
@@ -54,11 +54,11 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
54
54
 
55
55
  // fetch refuses to read the body when the status code is 204.
56
56
  if (response.status === 204) {
57
- return null as T;
57
+ return null as WithRequestID<T>;
58
58
  }
59
59
 
60
60
  if (props.options.__binaryResponse) {
61
- return response as unknown as T;
61
+ return response as unknown as WithRequestID<T>;
62
62
  }
63
63
 
64
64
  const contentType = response.headers.get('content-type');
@@ -69,26 +69,44 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
69
69
 
70
70
  debug('response', response.status, response.url, response.headers, json);
71
71
 
72
- return json as T;
72
+ return _addRequestID(json as T, response);
73
73
  }
74
74
 
75
75
  const text = await response.text();
76
76
  debug('response', response.status, response.url, response.headers, text);
77
77
 
78
78
  // TODO handle blob, arraybuffer, other content types, etc.
79
- return text as unknown as T;
79
+ return text as unknown as WithRequestID<T>;
80
+ }
81
+
82
+ type WithRequestID<T> =
83
+ T extends Array<any> | Response | AbstractPage<any> ? T
84
+ : T extends Record<string, any> ? T & { _request_id?: string | null }
85
+ : T;
86
+
87
+ function _addRequestID<T>(value: T, response: Response): WithRequestID<T> {
88
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
89
+ return value as WithRequestID<T>;
90
+ }
91
+
92
+ return Object.defineProperty(value, '_request_id', {
93
+ value: response.headers.get('request-id'),
94
+ enumerable: false,
95
+ }) as WithRequestID<T>;
80
96
  }
81
97
 
82
98
  /**
83
99
  * A subclass of `Promise` providing additional helper methods
84
100
  * for interacting with the SDK.
85
101
  */
86
- export class APIPromise<T> extends Promise<T> {
87
- private parsedPromise: Promise<T> | undefined;
102
+ export class APIPromise<T> extends Promise<WithRequestID<T>> {
103
+ private parsedPromise: Promise<WithRequestID<T>> | undefined;
88
104
 
89
105
  constructor(
90
106
  private responsePromise: Promise<APIResponseProps>,
91
- private parseResponse: (props: APIResponseProps) => PromiseOrValue<T> = defaultParseResponse,
107
+ private parseResponse: (
108
+ props: APIResponseProps,
109
+ ) => PromiseOrValue<WithRequestID<T>> = defaultParseResponse,
92
110
  ) {
93
111
  super((resolve) => {
94
112
  // this is maybe a bit weird but this has to be a no-op to not implicitly
@@ -100,7 +118,7 @@ export class APIPromise<T> extends Promise<T> {
100
118
 
101
119
  _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
102
120
  return new APIPromise(this.responsePromise, async (props) =>
103
- transform(await this.parseResponse(props), props),
121
+ _addRequestID(transform(await this.parseResponse(props), props), props.response),
104
122
  );
105
123
  }
106
124
 
@@ -120,33 +138,35 @@ export class APIPromise<T> extends Promise<T> {
120
138
  asResponse(): Promise<Response> {
121
139
  return this.responsePromise.then((p) => p.response);
122
140
  }
141
+
123
142
  /**
124
- * Gets the parsed response data and the raw `Response` instance.
143
+ * Gets the parsed response data, the raw `Response` instance and the ID of the request,
144
+ * returned vie the `request-id` header which is useful for debugging requests and resporting
145
+ * issues to Anthropic.
125
146
  *
126
147
  * If you just want to get the raw `Response` instance without parsing it,
127
148
  * you can use {@link asResponse()}.
128
149
  *
129
- *
130
150
  * 👋 Getting the wrong TypeScript type for `Response`?
131
151
  * Try setting `"moduleResolution": "NodeNext"` if you can,
132
152
  * or add one of these imports before your first `import … from '@anthropic-ai/sdk'`:
133
153
  * - `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node)
134
154
  * - `import '@anthropic-ai/sdk/shims/web'` (otherwise)
135
155
  */
136
- async withResponse(): Promise<{ data: T; response: Response }> {
156
+ async withResponse(): Promise<{ data: T; response: Response; request_id: string | null | undefined }> {
137
157
  const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
138
- return { data, response };
158
+ return { data, response, request_id: response.headers.get('request-id') };
139
159
  }
140
160
 
141
- private parse(): Promise<T> {
161
+ private parse(): Promise<WithRequestID<T>> {
142
162
  if (!this.parsedPromise) {
143
- this.parsedPromise = this.responsePromise.then(this.parseResponse);
163
+ this.parsedPromise = this.responsePromise.then(this.parseResponse) as any as Promise<WithRequestID<T>>;
144
164
  }
145
165
  return this.parsedPromise;
146
166
  }
147
167
 
148
- override then<TResult1 = T, TResult2 = never>(
149
- onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
168
+ override then<TResult1 = WithRequestID<T>, TResult2 = never>(
169
+ onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,
150
170
  onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
151
171
  ): Promise<TResult1 | TResult2> {
152
172
  return this.parse().then(onfulfilled, onrejected);
@@ -154,11 +174,11 @@ export class APIPromise<T> extends Promise<T> {
154
174
 
155
175
  override catch<TResult = never>(
156
176
  onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
157
- ): Promise<T | TResult> {
177
+ ): Promise<WithRequestID<T> | TResult> {
158
178
  return this.parse().catch(onrejected);
159
179
  }
160
180
 
161
- override finally(onfinally?: (() => void) | undefined | null): Promise<T> {
181
+ override finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>> {
162
182
  return this.parse().finally(onfinally);
163
183
  }
164
184
  }
@@ -537,19 +557,13 @@ export abstract class APIClient {
537
557
  const timeout = setTimeout(() => controller.abort(), ms);
538
558
 
539
559
  return (
540
- this.getRequestClient()
541
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
542
- .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
543
- .finally(() => {
544
- clearTimeout(timeout);
545
- })
560
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
561
+ this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
562
+ clearTimeout(timeout);
563
+ })
546
564
  );
547
565
  }
548
566
 
549
- protected getRequestClient(): RequestClient {
550
- return { fetch: this.fetch };
551
- }
552
-
553
567
  private shouldRetry(response: Response): boolean {
554
568
  // Note this is not a standard header.
555
569
  const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -724,7 +738,13 @@ export class PagePromise<
724
738
  ) {
725
739
  super(
726
740
  request,
727
- async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options),
741
+ async (props) =>
742
+ new Page(
743
+ client,
744
+ props.response,
745
+ await defaultParseResponse(props),
746
+ props.options,
747
+ ) as WithRequestID<PageClass>,
728
748
  );
729
749
  }
730
750
 
@@ -992,8 +1012,8 @@ export const safeJSON = (text: string) => {
992
1012
  }
993
1013
  };
994
1014
 
995
- // https://stackoverflow.com/a/19709846
996
- const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
1015
+ // https://url.spec.whatwg.org/#url-scheme-string
1016
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
997
1017
  const isAbsoluteURL = (url: string): boolean => {
998
1018
  return startsWithSchemeRegexp.test(url);
999
1019
  };
package/src/error.ts CHANGED
@@ -4,19 +4,21 @@ import { castToError, Headers } from "./core.js";
4
4
 
5
5
  export class AnthropicError extends Error {}
6
6
 
7
- export class APIError extends AnthropicError {
8
- readonly status: number | undefined;
9
- readonly headers: Headers | undefined;
10
- readonly error: Object | undefined;
7
+ export class APIError<
8
+ TStatus extends number | undefined = number | undefined,
9
+ THeaders extends Headers | undefined = Headers | undefined,
10
+ TError extends Object | undefined = Object | undefined,
11
+ > extends AnthropicError {
12
+ /** HTTP status for the response that caused the error */
13
+ readonly status: TStatus;
14
+ /** HTTP headers for the response that caused the error */
15
+ readonly headers: THeaders;
16
+ /** JSON body of the response that caused the error */
17
+ readonly error: TError;
11
18
 
12
19
  readonly request_id: string | null | undefined;
13
20
 
14
- constructor(
15
- status: number | undefined,
16
- error: Object | undefined,
17
- message: string | undefined,
18
- headers: Headers | undefined,
19
- ) {
21
+ constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
20
22
  super(`${APIError.makeMessage(status, error, message)}`);
21
23
  this.status = status;
22
24
  this.headers = headers;
@@ -51,7 +53,7 @@ export class APIError extends AnthropicError {
51
53
  message: string | undefined,
52
54
  headers: Headers | undefined,
53
55
  ): APIError {
54
- if (!status) {
56
+ if (!status || !headers) {
55
57
  return new APIConnectionError({ message, cause: castToError(errorResponse) });
56
58
  }
57
59
 
@@ -93,17 +95,13 @@ export class APIError extends AnthropicError {
93
95
  }
94
96
  }
95
97
 
96
- export class APIUserAbortError extends APIError {
97
- override readonly status: undefined = undefined;
98
-
98
+ export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
99
99
  constructor({ message }: { message?: string } = {}) {
100
100
  super(undefined, undefined, message || 'Request was aborted.', undefined);
101
101
  }
102
102
  }
103
103
 
104
- export class APIConnectionError extends APIError {
105
- override readonly status: undefined = undefined;
106
-
104
+ export class APIConnectionError extends APIError<undefined, undefined, undefined> {
107
105
  constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
108
106
  super(undefined, undefined, message || 'Connection error.', undefined);
109
107
  // in some environments the 'cause' property is already declared
@@ -118,32 +116,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
118
116
  }
119
117
  }
120
118
 
121
- export class BadRequestError extends APIError {
122
- override readonly status: 400 = 400;
123
- }
119
+ export class BadRequestError extends APIError<400, Headers> {}
124
120
 
125
- export class AuthenticationError extends APIError {
126
- override readonly status: 401 = 401;
127
- }
121
+ export class AuthenticationError extends APIError<401, Headers> {}
128
122
 
129
- export class PermissionDeniedError extends APIError {
130
- override readonly status: 403 = 403;
131
- }
123
+ export class PermissionDeniedError extends APIError<403, Headers> {}
132
124
 
133
- export class NotFoundError extends APIError {
134
- override readonly status: 404 = 404;
135
- }
125
+ export class NotFoundError extends APIError<404, Headers> {}
136
126
 
137
- export class ConflictError extends APIError {
138
- override readonly status: 409 = 409;
139
- }
127
+ export class ConflictError extends APIError<409, Headers> {}
140
128
 
141
- export class UnprocessableEntityError extends APIError {
142
- override readonly status: 422 = 422;
143
- }
129
+ export class UnprocessableEntityError extends APIError<422, Headers> {}
144
130
 
145
- export class RateLimitError extends APIError {
146
- override readonly status: 429 = 429;
147
- }
131
+ export class RateLimitError extends APIError<429, Headers> {}
148
132
 
149
- export class InternalServerError extends APIError {}
133
+ export class InternalServerError extends APIError<number, Headers> {}
package/src/index.ts CHANGED
@@ -14,14 +14,35 @@ import {
14
14
  CompletionCreateParamsStreaming,
15
15
  Completions,
16
16
  } from "./resources/completions.js";
17
+ import { ModelInfo, ModelInfosPage, ModelListParams, Models } from "./resources/models.js";
17
18
  import {
19
+ AnthropicBeta,
20
+ Beta,
21
+ BetaAPIError,
22
+ BetaAuthenticationError,
23
+ BetaBillingError,
24
+ BetaError,
25
+ BetaErrorResponse,
26
+ BetaGatewayTimeoutError,
27
+ BetaInvalidRequestError,
28
+ BetaNotFoundError,
29
+ BetaOverloadedError,
30
+ BetaPermissionError,
31
+ BetaRateLimitError,
32
+ } from "./resources/beta/beta.js";
33
+ import {
34
+ Base64PDFSource,
35
+ CacheControlEphemeral,
18
36
  ContentBlock,
19
37
  ContentBlockDeltaEvent,
38
+ ContentBlockParam,
20
39
  ContentBlockStartEvent,
21
40
  ContentBlockStopEvent,
41
+ DocumentBlockParam,
22
42
  ImageBlockParam,
23
43
  InputJSONDelta,
24
44
  Message,
45
+ MessageCountTokensParams,
25
46
  MessageCreateParams,
26
47
  MessageCreateParamsNonStreaming,
27
48
  MessageCreateParamsStreaming,
@@ -32,6 +53,7 @@ import {
32
53
  MessageStopEvent,
33
54
  MessageStreamEvent,
34
55
  MessageStreamParams,
56
+ MessageTokensCount,
35
57
  Messages,
36
58
  Metadata,
37
59
  Model,
@@ -54,20 +76,7 @@ import {
54
76
  ToolUseBlock,
55
77
  ToolUseBlockParam,
56
78
  Usage,
57
- } from "./resources/messages.js";
58
- import {
59
- AnthropicBeta,
60
- Beta,
61
- BetaAPIError,
62
- BetaAuthenticationError,
63
- BetaError,
64
- BetaErrorResponse,
65
- BetaInvalidRequestError,
66
- BetaNotFoundError,
67
- BetaOverloadedError,
68
- BetaPermissionError,
69
- BetaRateLimitError,
70
- } from "./resources/beta/beta.js";
79
+ } from "./resources/messages/messages.js";
71
80
 
72
81
  export interface ClientOptions {
73
82
  /**
@@ -181,7 +190,7 @@ export class Anthropic extends Core.APIClient {
181
190
 
182
191
  if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) {
183
192
  throw new Errors.AnthropicError(
184
- "It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n\nTODO: link!\n",
193
+ "It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n",
185
194
  );
186
195
  }
187
196
 
@@ -201,6 +210,7 @@ export class Anthropic extends Core.APIClient {
201
210
 
202
211
  completions: API.Completions = new API.Completions(this);
203
212
  messages: API.Messages = new API.Messages(this);
213
+ models: API.Models = new API.Models(this);
204
214
  beta: API.Beta = new API.Beta(this);
205
215
 
206
216
  protected override defaultQuery(): Core.DefaultQuery | undefined {
@@ -289,31 +299,11 @@ export class Anthropic extends Core.APIClient {
289
299
  static fileFromPath = Uploads.fileFromPath;
290
300
  }
291
301
 
292
- export const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
293
-
294
- export {
295
- AnthropicError,
296
- APIError,
297
- APIConnectionError,
298
- APIConnectionTimeoutError,
299
- APIUserAbortError,
300
- NotFoundError,
301
- ConflictError,
302
- RateLimitError,
303
- BadRequestError,
304
- AuthenticationError,
305
- InternalServerError,
306
- PermissionDeniedError,
307
- UnprocessableEntityError,
308
- } from "./error.js";
309
-
310
- export import toFile = Uploads.toFile;
311
- export import fileFromPath = Uploads.fileFromPath;
312
-
313
302
  Anthropic.Completions = Completions;
314
303
  Anthropic.Messages = Messages;
304
+ Anthropic.Models = Models;
305
+ Anthropic.ModelInfosPage = ModelInfosPage;
315
306
  Anthropic.Beta = Beta;
316
-
317
307
  export declare namespace Anthropic {
318
308
  export type RequestOptions = Core.RequestOptions;
319
309
 
@@ -330,10 +320,14 @@ export declare namespace Anthropic {
330
320
 
331
321
  export {
332
322
  Messages as Messages,
323
+ type Base64PDFSource as Base64PDFSource,
324
+ type CacheControlEphemeral as CacheControlEphemeral,
333
325
  type ContentBlock as ContentBlock,
334
326
  type ContentBlockDeltaEvent as ContentBlockDeltaEvent,
327
+ type ContentBlockParam as ContentBlockParam,
335
328
  type ContentBlockStartEvent as ContentBlockStartEvent,
336
329
  type ContentBlockStopEvent as ContentBlockStopEvent,
330
+ type DocumentBlockParam as DocumentBlockParam,
337
331
  type ImageBlockParam as ImageBlockParam,
338
332
  type InputJSONDelta as InputJSONDelta,
339
333
  type Message as Message,
@@ -343,6 +337,7 @@ export declare namespace Anthropic {
343
337
  type MessageStartEvent as MessageStartEvent,
344
338
  type MessageStopEvent as MessageStopEvent,
345
339
  type MessageStreamEvent as MessageStreamEvent,
340
+ type MessageTokensCount as MessageTokensCount,
346
341
  type Metadata as Metadata,
347
342
  type Model as Model,
348
343
  type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent,
@@ -368,6 +363,14 @@ export declare namespace Anthropic {
368
363
  type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
369
364
  type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
370
365
  type MessageStreamParams as MessageStreamParams,
366
+ type MessageCountTokensParams as MessageCountTokensParams,
367
+ };
368
+
369
+ export {
370
+ Models as Models,
371
+ type ModelInfo as ModelInfo,
372
+ ModelInfosPage as ModelInfosPage,
373
+ type ModelListParams as ModelListParams,
371
374
  };
372
375
 
373
376
  export {
@@ -375,14 +378,46 @@ export declare namespace Anthropic {
375
378
  type AnthropicBeta as AnthropicBeta,
376
379
  type BetaAPIError as BetaAPIError,
377
380
  type BetaAuthenticationError as BetaAuthenticationError,
381
+ type BetaBillingError as BetaBillingError,
378
382
  type BetaError as BetaError,
379
383
  type BetaErrorResponse as BetaErrorResponse,
384
+ type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
380
385
  type BetaInvalidRequestError as BetaInvalidRequestError,
381
386
  type BetaNotFoundError as BetaNotFoundError,
382
387
  type BetaOverloadedError as BetaOverloadedError,
383
388
  type BetaPermissionError as BetaPermissionError,
384
389
  type BetaRateLimitError as BetaRateLimitError,
385
390
  };
391
+
392
+ export type APIErrorObject = API.APIErrorObject;
393
+ export type AuthenticationError = API.AuthenticationError;
394
+ export type BillingError = API.BillingError;
395
+ export type ErrorObject = API.ErrorObject;
396
+ export type ErrorResponse = API.ErrorResponse;
397
+ export type GatewayTimeoutError = API.GatewayTimeoutError;
398
+ export type InvalidRequestError = API.InvalidRequestError;
399
+ export type NotFoundError = API.NotFoundError;
400
+ export type OverloadedError = API.OverloadedError;
401
+ export type PermissionError = API.PermissionError;
402
+ export type RateLimitError = API.RateLimitError;
386
403
  }
404
+ export const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
405
+
406
+ export { toFile, fileFromPath } from "./uploads.js";
407
+ export {
408
+ AnthropicError,
409
+ APIError,
410
+ APIConnectionError,
411
+ APIConnectionTimeoutError,
412
+ APIUserAbortError,
413
+ NotFoundError,
414
+ ConflictError,
415
+ RateLimitError,
416
+ BadRequestError,
417
+ AuthenticationError,
418
+ InternalServerError,
419
+ PermissionDeniedError,
420
+ UnprocessableEntityError,
421
+ } from "./error.js";
387
422
 
388
423
  export default Anthropic;
@@ -1,6 +1,8 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  import { APIResource } from "../../resource.js";
4
+ import * as ModelsAPI from "./models.js";
5
+ import { BetaModelInfo, BetaModelInfosPage, ModelListParams, Models } from "./models.js";
4
6
  import * as MessagesAPI from "./messages/messages.js";
5
7
  import {
6
8
  BetaBase64PDFBlock,
@@ -44,12 +46,10 @@ import {
44
46
  MessageCreateParamsStreaming,
45
47
  Messages,
46
48
  } from "./messages/messages.js";
47
- import * as PromptCachingAPI from "./prompt-caching/prompt-caching.js";
48
- import { PromptCaching } from "./prompt-caching/prompt-caching.js";
49
49
 
50
50
  export class Beta extends APIResource {
51
+ models: ModelsAPI.Models = new ModelsAPI.Models(this._client);
51
52
  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
52
- promptCaching: PromptCachingAPI.PromptCaching = new PromptCachingAPI.PromptCaching(this._client);
53
53
  }
54
54
 
55
55
  export type AnthropicBeta =
@@ -72,12 +72,20 @@ export interface BetaAuthenticationError {
72
72
  type: 'authentication_error';
73
73
  }
74
74
 
75
+ export interface BetaBillingError {
76
+ message: string;
77
+
78
+ type: 'billing_error';
79
+ }
80
+
75
81
  export type BetaError =
76
82
  | BetaInvalidRequestError
77
83
  | BetaAuthenticationError
84
+ | BetaBillingError
78
85
  | BetaPermissionError
79
86
  | BetaNotFoundError
80
87
  | BetaRateLimitError
88
+ | BetaGatewayTimeoutError
81
89
  | BetaAPIError
82
90
  | BetaOverloadedError;
83
91
 
@@ -87,6 +95,12 @@ export interface BetaErrorResponse {
87
95
  type: 'error';
88
96
  }
89
97
 
98
+ export interface BetaGatewayTimeoutError {
99
+ message: string;
100
+
101
+ type: 'timeout_error';
102
+ }
103
+
90
104
  export interface BetaInvalidRequestError {
91
105
  message: string;
92
106
 
@@ -117,16 +131,19 @@ export interface BetaRateLimitError {
117
131
  type: 'rate_limit_error';
118
132
  }
119
133
 
134
+ Beta.Models = Models;
135
+ Beta.BetaModelInfosPage = BetaModelInfosPage;
120
136
  Beta.Messages = Messages;
121
- Beta.PromptCaching = PromptCaching;
122
137
 
123
138
  export declare namespace Beta {
124
139
  export {
125
140
  type AnthropicBeta as AnthropicBeta,
126
141
  type BetaAPIError as BetaAPIError,
127
142
  type BetaAuthenticationError as BetaAuthenticationError,
143
+ type BetaBillingError as BetaBillingError,
128
144
  type BetaError as BetaError,
129
145
  type BetaErrorResponse as BetaErrorResponse,
146
+ type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
130
147
  type BetaInvalidRequestError as BetaInvalidRequestError,
131
148
  type BetaNotFoundError as BetaNotFoundError,
132
149
  type BetaOverloadedError as BetaOverloadedError,
@@ -134,6 +151,13 @@ export declare namespace Beta {
134
151
  type BetaRateLimitError as BetaRateLimitError,
135
152
  };
136
153
 
154
+ export {
155
+ Models as Models,
156
+ type BetaModelInfo as BetaModelInfo,
157
+ BetaModelInfosPage as BetaModelInfosPage,
158
+ type ModelListParams as ModelListParams,
159
+ };
160
+
137
161
  export {
138
162
  Messages as Messages,
139
163
  type BetaBase64PDFBlock as BetaBase64PDFBlock,
@@ -176,6 +200,4 @@ export declare namespace Beta {
176
200
  type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
177
201
  type MessageCountTokensParams as MessageCountTokensParams,
178
202
  };
179
-
180
- export { PromptCaching as PromptCaching };
181
203
  }
@@ -5,14 +5,17 @@ export {
5
5
  type AnthropicBeta,
6
6
  type BetaAPIError,
7
7
  type BetaAuthenticationError,
8
+ type BetaBillingError,
8
9
  type BetaError,
9
10
  type BetaErrorResponse,
11
+ type BetaGatewayTimeoutError,
10
12
  type BetaInvalidRequestError,
11
13
  type BetaNotFoundError,
12
14
  type BetaOverloadedError,
13
15
  type BetaPermissionError,
14
16
  type BetaRateLimitError,
15
17
  } from "./beta.js";
18
+ export { BetaModelInfosPage, Models, type BetaModelInfo, type ModelListParams } from "./models.js";
16
19
  export {
17
20
  Messages,
18
21
  type BetaBase64PDFBlock,
@@ -55,4 +58,3 @@ export {
55
58
  type MessageCreateParamsStreaming,
56
59
  type MessageCountTokensParams,
57
60
  } from "./messages/index.js";
58
- export { PromptCaching } from "./prompt-caching/index.js";
@@ -4,8 +4,8 @@ import { APIResource } from "../../../resource.js";
4
4
  import { APIPromise } from "../../../core.js";
5
5
  import * as Core from "../../../core.js";
6
6
  import * as MessagesMessagesAPI from "./messages.js";
7
- import * as MessagesAPI from "../../messages.js";
8
7
  import * as BetaAPI from "../beta.js";
8
+ import * as MessagesAPI from "../../messages/messages.js";
9
9
  import * as BatchesAPI from "./batches.js";
10
10
  import {
11
11
  BatchCancelParams,