@anthropic-ai/sdk 0.6.2 → 0.6.8

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 (265) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +16 -6
  3. package/_shims/MultipartBody.d.ts +9 -0
  4. package/_shims/MultipartBody.d.ts.map +1 -0
  5. package/_shims/MultipartBody.js +16 -0
  6. package/_shims/MultipartBody.js.map +1 -0
  7. package/_shims/MultipartBody.mjs +12 -0
  8. package/_shims/MultipartBody.mjs.map +1 -0
  9. package/_shims/README.md +46 -0
  10. package/{src/_shims/ReadableStream.node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
  11. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  12. package/_shims/auto/runtime-bun.js +21 -0
  13. package/_shims/auto/runtime-bun.js.map +1 -0
  14. package/_shims/auto/runtime-bun.mjs +2 -0
  15. package/_shims/auto/runtime-bun.mjs.map +1 -0
  16. package/_shims/auto/runtime-node.d.ts +5 -0
  17. package/_shims/auto/runtime-node.d.ts.map +1 -0
  18. package/_shims/auto/runtime-node.js +21 -0
  19. package/_shims/auto/runtime-node.js.map +1 -0
  20. package/_shims/auto/runtime-node.mjs +2 -0
  21. package/_shims/auto/runtime-node.mjs.map +1 -0
  22. package/_shims/auto/runtime.d.ts +5 -0
  23. package/_shims/auto/runtime.d.ts.map +1 -0
  24. package/_shims/auto/runtime.js +21 -0
  25. package/_shims/auto/runtime.js.map +1 -0
  26. package/_shims/auto/runtime.mjs +2 -0
  27. package/_shims/auto/runtime.mjs.map +1 -0
  28. package/_shims/auto/types-node.d.ts +5 -0
  29. package/_shims/auto/types-node.d.ts.map +1 -0
  30. package/_shims/auto/types-node.js +21 -0
  31. package/_shims/auto/types-node.js.map +1 -0
  32. package/_shims/auto/types-node.mjs +2 -0
  33. package/_shims/auto/types-node.mjs.map +1 -0
  34. package/_shims/auto/types.d.ts +101 -0
  35. package/{src/_shims/ReadableStream.js → _shims/auto/types.js} +0 -2
  36. package/_shims/{ReadableStream.js → auto/types.mjs} +0 -2
  37. package/_shims/bun-runtime.d.ts +6 -0
  38. package/_shims/bun-runtime.d.ts.map +1 -0
  39. package/_shims/bun-runtime.js +14 -0
  40. package/_shims/bun-runtime.js.map +1 -0
  41. package/_shims/bun-runtime.mjs +10 -0
  42. package/_shims/bun-runtime.mjs.map +1 -0
  43. package/_shims/index.d.ts +81 -0
  44. package/_shims/index.js +13 -0
  45. package/_shims/index.mjs +7 -0
  46. package/_shims/manual-types.d.ts +12 -0
  47. package/_shims/manual-types.js +3 -0
  48. package/_shims/manual-types.mjs +3 -0
  49. package/_shims/node-runtime.d.ts +3 -0
  50. package/_shims/node-runtime.d.ts.map +1 -0
  51. package/_shims/node-runtime.js +90 -0
  52. package/_shims/node-runtime.js.map +1 -0
  53. package/_shims/node-runtime.mjs +56 -0
  54. package/_shims/node-runtime.mjs.map +1 -0
  55. package/_shims/node-types.d.ts +42 -0
  56. package/_shims/node-types.js +3 -0
  57. package/_shims/node-types.mjs +3 -0
  58. package/_shims/registry.d.ts +37 -0
  59. package/_shims/registry.d.ts.map +1 -0
  60. package/_shims/registry.js +41 -0
  61. package/_shims/registry.js.map +1 -0
  62. package/_shims/registry.mjs +37 -0
  63. package/_shims/registry.mjs.map +1 -0
  64. package/_shims/web-runtime.d.ts +5 -0
  65. package/_shims/web-runtime.d.ts.map +1 -0
  66. package/_shims/web-runtime.js +78 -0
  67. package/_shims/web-runtime.js.map +1 -0
  68. package/_shims/web-runtime.mjs +71 -0
  69. package/_shims/web-runtime.mjs.map +1 -0
  70. package/_shims/web-types.d.ts +83 -0
  71. package/_shims/web-types.js +3 -0
  72. package/_shims/web-types.mjs +3 -0
  73. package/core.d.ts +172 -224
  74. package/core.d.ts.map +1 -1
  75. package/core.js +701 -736
  76. package/core.js.map +1 -1
  77. package/core.mjs +694 -688
  78. package/core.mjs.map +1 -1
  79. package/error.d.ts +32 -32
  80. package/error.d.ts.map +1 -1
  81. package/error.js +105 -106
  82. package/error.js.map +1 -1
  83. package/error.mjs +101 -91
  84. package/error.mjs.map +1 -1
  85. package/index.d.mts +110 -117
  86. package/index.d.ts +110 -117
  87. package/index.d.ts.map +1 -1
  88. package/index.js +107 -159
  89. package/index.js.map +1 -1
  90. package/index.mjs +84 -104
  91. package/index.mjs.map +1 -1
  92. package/package.json +36 -21
  93. package/resource.d.ts +10 -10
  94. package/resource.js +12 -12
  95. package/resource.mjs +10 -10
  96. package/resources/completions.d.ts +136 -142
  97. package/resources/completions.d.ts.map +1 -1
  98. package/resources/completions.js +9 -14
  99. package/resources/completions.js.map +1 -1
  100. package/resources/completions.mjs +6 -11
  101. package/resources/completions.mjs.map +1 -1
  102. package/resources/index.d.ts +2 -9
  103. package/resources/index.d.ts.map +1 -1
  104. package/resources/index.js +5 -10
  105. package/resources/index.js.map +1 -1
  106. package/resources/index.mjs +2 -2
  107. package/resources/index.mjs.map +1 -1
  108. package/resources/top-level.d.ts +1 -1
  109. package/resources/top-level.js +3 -3
  110. package/resources/top-level.mjs +1 -1
  111. package/shims/node.d.ts +29 -0
  112. package/shims/node.d.ts.map +1 -0
  113. package/shims/node.js +31 -0
  114. package/shims/node.js.map +1 -0
  115. package/shims/node.mjs +5 -0
  116. package/shims/node.mjs.map +1 -0
  117. package/shims/web.d.ts +26 -0
  118. package/shims/web.d.ts.map +1 -0
  119. package/shims/web.js +31 -0
  120. package/shims/web.js.map +1 -0
  121. package/shims/web.mjs +5 -0
  122. package/shims/web.mjs.map +1 -0
  123. package/src/_shims/MultipartBody.ts +9 -0
  124. package/src/_shims/README.md +46 -0
  125. package/src/_shims/auto/runtime-bun.ts +4 -0
  126. package/src/_shims/auto/runtime-node.ts +4 -0
  127. package/src/_shims/auto/runtime.ts +4 -0
  128. package/src/_shims/auto/types-node.ts +4 -0
  129. package/src/_shims/auto/types.d.ts +101 -0
  130. package/src/_shims/auto/types.js +3 -0
  131. package/src/_shims/auto/types.mjs +3 -0
  132. package/src/_shims/bun-runtime.ts +14 -0
  133. package/src/_shims/index.d.ts +81 -0
  134. package/src/_shims/index.js +13 -0
  135. package/src/_shims/index.mjs +7 -0
  136. package/src/_shims/manual-types.d.ts +12 -0
  137. package/src/_shims/manual-types.js +3 -0
  138. package/src/_shims/manual-types.mjs +3 -0
  139. package/src/_shims/node-runtime.ts +83 -0
  140. package/src/_shims/node-types.d.ts +42 -0
  141. package/src/_shims/node-types.js +3 -0
  142. package/src/_shims/node-types.mjs +3 -0
  143. package/src/_shims/registry.ts +67 -0
  144. package/src/_shims/web-runtime.ts +103 -0
  145. package/src/_shims/web-types.d.ts +83 -0
  146. package/src/_shims/web-types.js +3 -0
  147. package/src/_shims/web-types.mjs +3 -0
  148. package/src/core.ts +107 -56
  149. package/src/error.ts +20 -8
  150. package/src/index.ts +24 -17
  151. package/src/resources/completions.ts +11 -11
  152. package/src/resources/index.ts +0 -1
  153. package/src/shims/node.ts +50 -0
  154. package/src/shims/web.ts +50 -0
  155. package/src/streaming.ts +164 -59
  156. package/src/tsconfig.json +11 -0
  157. package/src/uploads.ts +11 -15
  158. package/src/version.ts +1 -1
  159. package/streaming.d.ts +11 -8
  160. package/streaming.d.ts.map +1 -1
  161. package/streaming.js +300 -192
  162. package/streaming.js.map +1 -1
  163. package/streaming.mjs +296 -188
  164. package/streaming.mjs.map +1 -1
  165. package/uploads.d.ts +23 -39
  166. package/uploads.d.ts.map +1 -1
  167. package/uploads.js +111 -157
  168. package/uploads.js.map +1 -1
  169. package/uploads.mjs +107 -133
  170. package/uploads.mjs.map +1 -1
  171. package/version.d.ts +2 -2
  172. package/version.js +4 -4
  173. package/version.mjs +2 -2
  174. package/_shims/ReadableStream.d.ts +0 -38
  175. package/_shims/ReadableStream.mjs +0 -7
  176. package/_shims/ReadableStream.node.d.ts +0 -6
  177. package/_shims/ReadableStream.node.d.ts.map +0 -1
  178. package/_shims/ReadableStream.node.js +0 -14
  179. package/_shims/ReadableStream.node.js.map +0 -1
  180. package/_shims/ReadableStream.node.mjs +0 -3
  181. package/_shims/ReadableStream.node.mjs.map +0 -1
  182. package/_shims/agent.d.ts +0 -9
  183. package/_shims/agent.d.ts.map +0 -1
  184. package/_shims/agent.js +0 -14
  185. package/_shims/agent.js.map +0 -1
  186. package/_shims/agent.mjs +0 -10
  187. package/_shims/agent.mjs.map +0 -1
  188. package/_shims/agent.node.d.ts +0 -7
  189. package/_shims/agent.node.d.ts.map +0 -1
  190. package/_shims/agent.node.js +0 -28
  191. package/_shims/agent.node.js.map +0 -1
  192. package/_shims/agent.node.mjs +0 -16
  193. package/_shims/agent.node.mjs.map +0 -1
  194. package/_shims/fetch.d.ts +0 -60
  195. package/_shims/fetch.js +0 -13
  196. package/_shims/fetch.mjs +0 -15
  197. package/_shims/fetch.node.d.ts +0 -64
  198. package/_shims/fetch.node.js +0 -12
  199. package/_shims/fetch.node.mjs +0 -14
  200. package/_shims/fileFromPath.d.ts +0 -22
  201. package/_shims/fileFromPath.d.ts.map +0 -1
  202. package/_shims/fileFromPath.js +0 -16
  203. package/_shims/fileFromPath.js.map +0 -1
  204. package/_shims/fileFromPath.mjs +0 -12
  205. package/_shims/fileFromPath.mjs.map +0 -1
  206. package/_shims/fileFromPath.node.d.ts +0 -17
  207. package/_shims/fileFromPath.node.d.ts.map +0 -1
  208. package/_shims/fileFromPath.node.js +0 -17
  209. package/_shims/fileFromPath.node.js.map +0 -1
  210. package/_shims/fileFromPath.node.mjs +0 -13
  211. package/_shims/fileFromPath.node.mjs.map +0 -1
  212. package/_shims/formdata.d.ts +0 -43
  213. package/_shims/formdata.js +0 -17
  214. package/_shims/formdata.mjs +0 -20
  215. package/_shims/formdata.node.d.ts +0 -45
  216. package/_shims/formdata.node.js +0 -11
  217. package/_shims/formdata.node.mjs +0 -9
  218. package/_shims/getMultipartRequestOptions.d.ts +0 -10
  219. package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
  220. package/_shims/getMultipartRequestOptions.js +0 -12
  221. package/_shims/getMultipartRequestOptions.js.map +0 -1
  222. package/_shims/getMultipartRequestOptions.mjs +0 -8
  223. package/_shims/getMultipartRequestOptions.mjs.map +0 -1
  224. package/_shims/getMultipartRequestOptions.node.d.ts +0 -10
  225. package/_shims/getMultipartRequestOptions.node.d.ts.map +0 -1
  226. package/_shims/getMultipartRequestOptions.node.js +0 -22
  227. package/_shims/getMultipartRequestOptions.node.js.map +0 -1
  228. package/_shims/getMultipartRequestOptions.node.mjs +0 -18
  229. package/_shims/getMultipartRequestOptions.node.mjs.map +0 -1
  230. package/_shims/node-readable.d.ts +0 -23
  231. package/_shims/node-readable.d.ts.map +0 -1
  232. package/_shims/node-readable.js +0 -11
  233. package/_shims/node-readable.js.map +0 -1
  234. package/_shims/node-readable.mjs +0 -7
  235. package/_shims/node-readable.mjs.map +0 -1
  236. package/_shims/node-readable.node.d.ts +0 -8
  237. package/_shims/node-readable.node.d.ts.map +0 -1
  238. package/_shims/node-readable.node.js +0 -9
  239. package/_shims/node-readable.node.js.map +0 -1
  240. package/_shims/node-readable.node.mjs +0 -5
  241. package/_shims/node-readable.node.mjs.map +0 -1
  242. package/src/_shims/ReadableStream.d.ts +0 -38
  243. package/src/_shims/ReadableStream.mjs +0 -7
  244. package/src/_shims/agent.node.ts +0 -22
  245. package/src/_shims/agent.ts +0 -12
  246. package/src/_shims/fetch.d.ts +0 -60
  247. package/src/_shims/fetch.deno.ts +0 -23
  248. package/src/_shims/fetch.js +0 -13
  249. package/src/_shims/fetch.mjs +0 -15
  250. package/src/_shims/fetch.node.d.ts +0 -64
  251. package/src/_shims/fetch.node.js +0 -12
  252. package/src/_shims/fetch.node.mjs +0 -14
  253. package/src/_shims/fileFromPath.node.ts +0 -29
  254. package/src/_shims/fileFromPath.ts +0 -29
  255. package/src/_shims/formdata.d.ts +0 -43
  256. package/src/_shims/formdata.deno.ts +0 -16
  257. package/src/_shims/formdata.js +0 -17
  258. package/src/_shims/formdata.mjs +0 -20
  259. package/src/_shims/formdata.node.d.ts +0 -45
  260. package/src/_shims/formdata.node.js +0 -11
  261. package/src/_shims/formdata.node.mjs +0 -9
  262. package/src/_shims/getMultipartRequestOptions.node.ts +0 -25
  263. package/src/_shims/getMultipartRequestOptions.ts +0 -14
  264. package/src/_shims/node-readable.node.ts +0 -10
  265. package/src/_shims/node-readable.ts +0 -30
package/index.d.ts CHANGED
@@ -1,128 +1,121 @@
1
- import * as Core from './core.js';
2
- import * as API from './resources/index.js';
3
- import * as Errors from './error.js';
4
- import type { Agent } from '@anthropic-ai/sdk/_shims/agent';
5
- import * as Uploads from './uploads.js';
1
+ import * as Core from "./core.js";
2
+ import * as Errors from "./error.js";
3
+ import { type Agent } from "./_shims/index.js";
4
+ import * as Uploads from "./uploads.js";
5
+ import * as API from '@anthropic-ai/sdk/resources/index';
6
6
  export interface ClientOptions {
7
- /**
8
- * Defaults to process.env["ANTHROPIC_API_KEY"]. Set it to null if you want to send unauthenticated requests.
9
- */
10
- apiKey?: string | null;
11
- /**
12
- * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
13
- */
14
- baseURL?: string;
15
- /**
16
- * The maximum amount of time (in milliseconds) that the client should wait for a response
17
- * from the server before timing out a single request.
18
- *
19
- * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
20
- * much longer than this timeout before the promise succeeds or fails.
21
- */
22
- timeout?: number;
23
- /**
24
- * An HTTP agent used to manage HTTP(S) connections.
25
- *
26
- * If not provided, an agent will be constructed by default in the Node.js environment,
27
- * otherwise no agent is used.
28
- */
29
- httpAgent?: Agent;
30
- /**
31
- * Specify a custom `fetch` function implementation.
32
- *
33
- * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
34
- * defined globally.
35
- */
36
- fetch?: Core.Fetch | undefined;
37
- /**
38
- * The maximum number of times that the client will retry a request in case of a
39
- * temporary failure, like a network error or a 5XX error from the server.
40
- *
41
- * @default 2
42
- */
43
- maxRetries?: number;
44
- /**
45
- * Default headers to include with every request to the API.
46
- *
47
- * These can be removed in individual requests by explicitly setting the
48
- * header to `undefined` or `null` in request options.
49
- */
50
- defaultHeaders?: Core.Headers;
51
- /**
52
- * Default query parameters to include with every request to the API.
53
- *
54
- * These can be removed in individual requests by explicitly setting the
55
- * param to `undefined` in request options.
56
- */
57
- defaultQuery?: Core.DefaultQuery;
58
- authToken?: string | null;
7
+ /**
8
+ * Defaults to process.env['ANTHROPIC_API_KEY'].
9
+ */
10
+ apiKey?: string | null;
11
+ /**
12
+ * Defaults to process.env['ANTHROPIC_AUTH_TOKEN'].
13
+ */
14
+ authToken?: string | null;
15
+ /**
16
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
17
+ */
18
+ baseURL?: string;
19
+ /**
20
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
21
+ * from the server before timing out a single request.
22
+ *
23
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
24
+ * much longer than this timeout before the promise succeeds or fails.
25
+ */
26
+ timeout?: number;
27
+ /**
28
+ * An HTTP agent used to manage HTTP(S) connections.
29
+ *
30
+ * If not provided, an agent will be constructed by default in the Node.js environment,
31
+ * otherwise no agent is used.
32
+ */
33
+ httpAgent?: Agent;
34
+ /**
35
+ * Specify a custom `fetch` function implementation.
36
+ *
37
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
38
+ * defined globally.
39
+ */
40
+ fetch?: Core.Fetch | undefined;
41
+ /**
42
+ * The maximum number of times that the client will retry a request in case of a
43
+ * temporary failure, like a network error or a 5XX error from the server.
44
+ *
45
+ * @default 2
46
+ */
47
+ maxRetries?: number;
48
+ /**
49
+ * Default headers to include with every request to the API.
50
+ *
51
+ * These can be removed in individual requests by explicitly setting the
52
+ * header to `undefined` or `null` in request options.
53
+ */
54
+ defaultHeaders?: Core.Headers;
55
+ /**
56
+ * Default query parameters to include with every request to the API.
57
+ *
58
+ * These can be removed in individual requests by explicitly setting the
59
+ * param to `undefined` in request options.
60
+ */
61
+ defaultQuery?: Core.DefaultQuery;
59
62
  }
60
63
  /** API Client for interfacing with the Anthropic API. */
61
64
  export declare class Anthropic extends Core.APIClient {
62
- apiKey: string | null;
63
- authToken?: string | null;
64
- private _options;
65
- /**
66
- * API Client for interfacing with the Anthropic API.
67
- *
68
- * @param {string | null} [opts.apiKey=process.env['ANTHROPIC_API_KEY']] - The API Key to send to the API.
69
- * @param {string} [opts.baseURL] - Override the default base URL for the API.
70
- * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
71
- * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
72
- * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
73
- * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
74
- * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
75
- * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
76
- * @param {string | null} [opts.authToken]
77
- */
78
- constructor({ apiKey, authToken, ...opts }?: ClientOptions);
79
- completions: API.Completions;
80
- protected defaultQuery(): Core.DefaultQuery | undefined;
81
- protected defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers;
82
- protected validateHeaders(headers: Core.Headers, customHeaders: Core.Headers): void;
83
- protected authHeaders(opts: Core.FinalRequestOptions): Core.Headers;
84
- protected apiKeyHeader(opts: Core.FinalRequestOptions): Core.Headers;
85
- protected authTokenBearer(opts: Core.FinalRequestOptions): Core.Headers;
86
- static Anthropic: typeof Anthropic;
87
- static HUMAN_PROMPT: string;
88
- static AI_PROMPT: string;
89
- static APIError: typeof Errors.APIError;
90
- static APIConnectionError: typeof Errors.APIConnectionError;
91
- static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
92
- static APIUserAbortError: typeof Errors.APIUserAbortError;
93
- static NotFoundError: typeof Errors.NotFoundError;
94
- static ConflictError: typeof Errors.ConflictError;
95
- static RateLimitError: typeof Errors.RateLimitError;
96
- static BadRequestError: typeof Errors.BadRequestError;
97
- static AuthenticationError: typeof Errors.AuthenticationError;
98
- static InternalServerError: typeof Errors.InternalServerError;
99
- static PermissionDeniedError: typeof Errors.PermissionDeniedError;
100
- static UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
65
+ apiKey: string | null;
66
+ authToken: string | null;
67
+ private _options;
68
+ /**
69
+ * API Client for interfacing with the Anthropic API.
70
+ *
71
+ * @param {string | null} [opts.apiKey==process.env['ANTHROPIC_API_KEY'] ?? null]
72
+ * @param {string | null} [opts.authToken==process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
73
+ * @param {string} [opts.baseURL] - Override the default base URL for the API.
74
+ * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
75
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
76
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
77
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
78
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
79
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
80
+ */
81
+ constructor({ apiKey, authToken, ...opts }?: ClientOptions);
82
+ completions: API.Completions;
83
+ protected defaultQuery(): Core.DefaultQuery | undefined;
84
+ protected defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers;
85
+ protected validateHeaders(headers: Core.Headers, customHeaders: Core.Headers): void;
86
+ protected authHeaders(opts: Core.FinalRequestOptions): Core.Headers;
87
+ protected apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers;
88
+ protected bearerAuth(opts: Core.FinalRequestOptions): Core.Headers;
89
+ static Anthropic: typeof Anthropic;
90
+ static HUMAN_PROMPT: string;
91
+ static AI_PROMPT: string;
92
+ static AnthropicError: typeof Errors.AnthropicError;
93
+ static APIError: typeof Errors.APIError;
94
+ static APIConnectionError: typeof Errors.APIConnectionError;
95
+ static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
96
+ static APIUserAbortError: typeof Errors.APIUserAbortError;
97
+ static NotFoundError: typeof Errors.NotFoundError;
98
+ static ConflictError: typeof Errors.ConflictError;
99
+ static RateLimitError: typeof Errors.RateLimitError;
100
+ static BadRequestError: typeof Errors.BadRequestError;
101
+ static AuthenticationError: typeof Errors.AuthenticationError;
102
+ static InternalServerError: typeof Errors.InternalServerError;
103
+ static PermissionDeniedError: typeof Errors.PermissionDeniedError;
104
+ static UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
101
105
  }
102
106
  export declare const HUMAN_PROMPT: string, AI_PROMPT: string;
103
- export declare const APIError: typeof Errors.APIError,
104
- APIConnectionError: typeof Errors.APIConnectionError,
105
- APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError,
106
- APIUserAbortError: typeof Errors.APIUserAbortError,
107
- NotFoundError: typeof Errors.NotFoundError,
108
- ConflictError: typeof Errors.ConflictError,
109
- RateLimitError: typeof Errors.RateLimitError,
110
- BadRequestError: typeof Errors.BadRequestError,
111
- AuthenticationError: typeof Errors.AuthenticationError,
112
- InternalServerError: typeof Errors.InternalServerError,
113
- PermissionDeniedError: typeof Errors.PermissionDeniedError,
114
- UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
107
+ export declare const AnthropicError: typeof Errors.AnthropicError, APIError: typeof Errors.APIError, APIConnectionError: typeof Errors.APIConnectionError, APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError, APIUserAbortError: typeof Errors.APIUserAbortError, NotFoundError: typeof Errors.NotFoundError, ConflictError: typeof Errors.ConflictError, RateLimitError: typeof Errors.RateLimitError, BadRequestError: typeof Errors.BadRequestError, AuthenticationError: typeof Errors.AuthenticationError, InternalServerError: typeof Errors.InternalServerError, PermissionDeniedError: typeof Errors.PermissionDeniedError, UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
115
108
  export import toFile = Uploads.toFile;
116
109
  export import fileFromPath = Uploads.fileFromPath;
117
110
  export declare namespace Anthropic {
118
- export import toFile = Uploads.toFile;
119
- export import fileFromPath = Uploads.fileFromPath;
120
- export import RequestOptions = Core.RequestOptions;
121
- export import Completions = API.Completions;
122
- export import Completion = API.Completion;
123
- export import CompletionCreateParams = API.CompletionCreateParams;
124
- export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
125
- export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
111
+ export import toFile = Uploads.toFile;
112
+ export import fileFromPath = Uploads.fileFromPath;
113
+ export import RequestOptions = Core.RequestOptions;
114
+ export import Completions = API.Completions;
115
+ export import Completion = API.Completion;
116
+ export import CompletionCreateParams = API.CompletionCreateParams;
117
+ export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
118
+ export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
126
119
  }
127
120
  export default Anthropic;
128
- //# sourceMappingURL=index.d.ts.map
121
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;IAElB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAE/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAA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D,yBAAiB,SAAS,CAAC;IAEzB,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACtC,MAAM,QAAQ,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAElD,MAAM,QAAQ,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IAEnD,MAAM,QAAQ,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IAC5C,MAAM,QAAQ,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;IAC1C,MAAM,QAAQ,sBAAsB,GAAG,GAAG,CAAC,sBAAsB,CAAC;IAClE,MAAM,QAAQ,kCAAkC,GAAG,GAAG,CAAC,kCAAkC,CAAC;IAC1F,MAAM,QAAQ,+BAA+B,GAAG,GAAG,CAAC,+BAA+B,CAAC;CACrF;AAED,eAAe,SAAS,CAAC"}
package/index.js CHANGED
@@ -1,165 +1,124 @@
1
- 'use strict';
1
+ "use strict";
2
2
  // File generated from our OpenAPI spec by Stainless.
3
- var __createBinding =
4
- (this && this.__createBinding) ||
5
- (Object.create ?
6
- function (o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = {
11
- enumerable: true,
12
- get: function () {
13
- return m[k];
14
- },
15
- };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }
19
- : function (o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- });
23
- var __setModuleDefault =
24
- (this && this.__setModuleDefault) ||
25
- (Object.create ?
26
- function (o, v) {
27
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
8
  }
29
- : function (o, v) {
30
- o['default'] = v;
31
- });
32
- var __importStar =
33
- (this && this.__importStar) ||
34
- function (mod) {
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
35
20
  if (mod && mod.__esModule) return mod;
36
21
  var result = {};
37
- if (mod != null)
38
- for (var k in mod)
39
- if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
23
  __setModuleDefault(result, mod);
41
24
  return result;
42
- };
25
+ };
43
26
  var _a;
44
- Object.defineProperty(exports, '__esModule', { value: true });
45
- exports.fileFromPath =
46
- exports.toFile =
47
- exports.UnprocessableEntityError =
48
- exports.PermissionDeniedError =
49
- exports.InternalServerError =
50
- exports.AuthenticationError =
51
- exports.BadRequestError =
52
- exports.RateLimitError =
53
- exports.ConflictError =
54
- exports.NotFoundError =
55
- exports.APIUserAbortError =
56
- exports.APIConnectionTimeoutError =
57
- exports.APIConnectionError =
58
- exports.APIError =
59
- exports.AI_PROMPT =
60
- exports.HUMAN_PROMPT =
61
- exports.Anthropic =
62
- void 0;
63
- const Core = __importStar(require('./core.js'));
64
- const API = __importStar(require('./resources/index.js'));
65
- const Errors = __importStar(require('./error.js'));
66
- const Uploads = __importStar(require('./uploads.js'));
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.fileFromPath = exports.toFile = exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.AnthropicError = exports.AI_PROMPT = exports.HUMAN_PROMPT = exports.Anthropic = void 0;
29
+ const Core = __importStar(require("./core.js"));
30
+ const Errors = __importStar(require("./error.js"));
31
+ const Uploads = __importStar(require("./uploads.js"));
32
+ const API = __importStar(require("@anthropic-ai/sdk/resources/index"));
67
33
  /** API Client for interfacing with the Anthropic API. */
68
34
  class Anthropic extends Core.APIClient {
69
- /**
70
- * API Client for interfacing with the Anthropic API.
71
- *
72
- * @param {string | null} [opts.apiKey=process.env['ANTHROPIC_API_KEY']] - The API Key to send to the API.
73
- * @param {string} [opts.baseURL] - Override the default base URL for the API.
74
- * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
75
- * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
76
- * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
77
- * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
78
- * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
79
- * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
80
- * @param {string | null} [opts.authToken]
81
- */
82
- constructor(_b) {
83
- var _c, _d, _e;
84
- var {
85
- apiKey = (_c = Core.readEnv('ANTHROPIC_API_KEY')) !== null && _c !== void 0 ? _c : null,
86
- authToken = (_d = Core.readEnv('ANTHROPIC_AUTH_TOKEN')) !== null && _d !== void 0 ? _d : null,
87
- ...opts
88
- } = _b === void 0 ? {} : _b;
89
- const options = {
90
- apiKey,
91
- authToken,
92
- baseURL: `https://api.anthropic.com`,
93
- ...opts,
94
- };
95
- super({
96
- baseURL: options.baseURL,
97
- timeout: (_e = options.timeout) !== null && _e !== void 0 ? _e : 600000 /* 10 minutes */,
98
- httpAgent: options.httpAgent,
99
- maxRetries: options.maxRetries,
100
- fetch: options.fetch,
101
- });
102
- this.completions = new API.Completions(this);
103
- this._options = options;
104
- this.apiKey = apiKey;
105
- this.authToken = authToken;
106
- }
107
- defaultQuery() {
108
- return this._options.defaultQuery;
109
- }
110
- defaultHeaders(opts) {
111
- return {
112
- ...super.defaultHeaders(opts),
113
- 'anthropic-version': '2023-06-01',
114
- ...this._options.defaultHeaders,
115
- };
116
- }
117
- validateHeaders(headers, customHeaders) {
118
- if (this.apiKey && headers['X-Api-Key']) {
119
- return;
120
- }
121
- if (customHeaders['X-Api-Key'] === null) {
122
- return;
35
+ /**
36
+ * API Client for interfacing with the Anthropic API.
37
+ *
38
+ * @param {string | null} [opts.apiKey==process.env['ANTHROPIC_API_KEY'] ?? null]
39
+ * @param {string | null} [opts.authToken==process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
40
+ * @param {string} [opts.baseURL] - Override the default base URL for the API.
41
+ * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
42
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
43
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
44
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
45
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
46
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
47
+ */
48
+ constructor({ apiKey = Core.readEnv('ANTHROPIC_API_KEY') ?? null, authToken = Core.readEnv('ANTHROPIC_AUTH_TOKEN') ?? null, ...opts } = {}) {
49
+ const options = {
50
+ apiKey,
51
+ authToken,
52
+ ...opts,
53
+ baseURL: opts.baseURL ?? `https://api.anthropic.com`,
54
+ };
55
+ super({
56
+ baseURL: options.baseURL,
57
+ timeout: options.timeout ?? 600000 /* 10 minutes */,
58
+ httpAgent: options.httpAgent,
59
+ maxRetries: options.maxRetries,
60
+ fetch: options.fetch,
61
+ });
62
+ this.completions = new API.Completions(this);
63
+ this._options = options;
64
+ this.apiKey = apiKey;
65
+ this.authToken = authToken;
123
66
  }
124
- if (this.authToken && headers['Authorization']) {
125
- return;
67
+ defaultQuery() {
68
+ return this._options.defaultQuery;
126
69
  }
127
- if (customHeaders['Authorization'] === null) {
128
- return;
70
+ defaultHeaders(opts) {
71
+ return {
72
+ ...super.defaultHeaders(opts),
73
+ 'anthropic-version': '2023-06-01',
74
+ ...this._options.defaultHeaders,
75
+ };
129
76
  }
130
- throw new Error(
131
- 'Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted',
132
- );
133
- }
134
- authHeaders(opts) {
135
- const apiKeyHeader = this.apiKeyHeader(opts);
136
- if (apiKeyHeader != null && !Core.isEmptyObj(apiKeyHeader)) {
137
- return apiKeyHeader;
77
+ validateHeaders(headers, customHeaders) {
78
+ if (this.apiKey && headers['X-Api-Key']) {
79
+ return;
80
+ }
81
+ if (customHeaders['X-Api-Key'] === null) {
82
+ return;
83
+ }
84
+ if (this.authToken && headers['Authorization']) {
85
+ return;
86
+ }
87
+ if (customHeaders['Authorization'] === null) {
88
+ return;
89
+ }
90
+ throw new Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
138
91
  }
139
- const authTokenBearer = this.authTokenBearer(opts);
140
- if (authTokenBearer != null && !Core.isEmptyObj(authTokenBearer)) {
141
- return authTokenBearer;
92
+ authHeaders(opts) {
93
+ const apiKeyAuth = this.apiKeyAuth(opts);
94
+ const bearerAuth = this.bearerAuth(opts);
95
+ if (apiKeyAuth != null && !Core.isEmptyObj(apiKeyAuth)) {
96
+ return apiKeyAuth;
97
+ }
98
+ if (bearerAuth != null && !Core.isEmptyObj(bearerAuth)) {
99
+ return bearerAuth;
100
+ }
101
+ return {};
142
102
  }
143
- return {};
144
- }
145
- apiKeyHeader(opts) {
146
- if (this.apiKey == null) {
147
- return {};
103
+ apiKeyAuth(opts) {
104
+ if (this.apiKey == null) {
105
+ return {};
106
+ }
107
+ return { 'X-Api-Key': this.apiKey };
148
108
  }
149
- return { 'X-Api-Key': this.apiKey };
150
- }
151
- authTokenBearer(opts) {
152
- if (this.authToken == null) {
153
- return {};
109
+ bearerAuth(opts) {
110
+ if (this.authToken == null) {
111
+ return {};
112
+ }
113
+ return { Authorization: `Bearer ${this.authToken}` };
154
114
  }
155
- return { Authorization: `Bearer ${this.authToken}` };
156
- }
157
115
  }
158
116
  exports.Anthropic = Anthropic;
159
117
  _a = Anthropic;
160
118
  Anthropic.Anthropic = _a;
161
119
  Anthropic.HUMAN_PROMPT = '\n\nHuman:';
162
120
  Anthropic.AI_PROMPT = '\n\nAssistant:';
121
+ Anthropic.AnthropicError = Errors.AnthropicError;
163
122
  Anthropic.APIError = Errors.APIError;
164
123
  Anthropic.APIConnectionError = Errors.APIConnectionError;
165
124
  Anthropic.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
@@ -172,27 +131,16 @@ Anthropic.AuthenticationError = Errors.AuthenticationError;
172
131
  Anthropic.InternalServerError = Errors.InternalServerError;
173
132
  Anthropic.PermissionDeniedError = Errors.PermissionDeniedError;
174
133
  Anthropic.UnprocessableEntityError = Errors.UnprocessableEntityError;
175
- (exports.HUMAN_PROMPT = Anthropic.HUMAN_PROMPT), (exports.AI_PROMPT = Anthropic.AI_PROMPT);
176
- (exports.APIError = Errors.APIError),
177
- (exports.APIConnectionError = Errors.APIConnectionError),
178
- (exports.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError),
179
- (exports.APIUserAbortError = Errors.APIUserAbortError),
180
- (exports.NotFoundError = Errors.NotFoundError),
181
- (exports.ConflictError = Errors.ConflictError),
182
- (exports.RateLimitError = Errors.RateLimitError),
183
- (exports.BadRequestError = Errors.BadRequestError),
184
- (exports.AuthenticationError = Errors.AuthenticationError),
185
- (exports.InternalServerError = Errors.InternalServerError),
186
- (exports.PermissionDeniedError = Errors.PermissionDeniedError),
187
- (exports.UnprocessableEntityError = Errors.UnprocessableEntityError);
134
+ exports.HUMAN_PROMPT = Anthropic.HUMAN_PROMPT, exports.AI_PROMPT = Anthropic.AI_PROMPT;
135
+ exports.AnthropicError = Errors.AnthropicError, exports.APIError = Errors.APIError, exports.APIConnectionError = Errors.APIConnectionError, exports.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError, exports.APIUserAbortError = Errors.APIUserAbortError, exports.NotFoundError = Errors.NotFoundError, exports.ConflictError = Errors.ConflictError, exports.RateLimitError = Errors.RateLimitError, exports.BadRequestError = Errors.BadRequestError, exports.AuthenticationError = Errors.AuthenticationError, exports.InternalServerError = Errors.InternalServerError, exports.PermissionDeniedError = Errors.PermissionDeniedError, exports.UnprocessableEntityError = Errors.UnprocessableEntityError;
188
136
  exports.toFile = Uploads.toFile;
189
137
  exports.fileFromPath = Uploads.fileFromPath;
190
138
  (function (Anthropic) {
191
- // Helper functions
192
- Anthropic.toFile = Uploads.toFile;
193
- Anthropic.fileFromPath = Uploads.fileFromPath;
194
- Anthropic.Completions = API.Completions;
195
- })((Anthropic = exports.Anthropic || (exports.Anthropic = {})));
139
+ // Helper functions
140
+ Anthropic.toFile = Uploads.toFile;
141
+ Anthropic.fileFromPath = Uploads.fileFromPath;
142
+ Anthropic.Completions = API.Completions;
143
+ })(Anthropic = exports.Anthropic || (exports.Anthropic = {}));
196
144
  exports = module.exports = Anthropic;
197
145
  exports.default = Anthropic;
198
- //# sourceMappingURL=index.js.map
146
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErD,gDAA+B;AAC/B,0DAAyC;AACzC,mDAAkC;AAElC,sDAAqC;AAiErC,yDAAyD;AACzD,MAAa,SAAU,SAAQ,IAAI,CAAC,SAAS;IAM3C;;;;;;;;;;;;OAYG;IACH,YAAY,EAIS;;YA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