@anthropic-ai/sdk 0.124.0 → 0.126.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 (921) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/client.d.mts +2 -4
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +2 -4
  5. package/client.d.ts.map +1 -1
  6. package/client.js +846 -851
  7. package/client.js.map +1 -1
  8. package/client.mjs +846 -845
  9. package/client.mjs.map +1 -1
  10. package/core/api-promise.d.mts.map +1 -1
  11. package/core/api-promise.d.ts.map +1 -1
  12. package/core/api-promise.js +71 -69
  13. package/core/api-promise.js.map +1 -1
  14. package/core/api-promise.mjs +71 -65
  15. package/core/api-promise.mjs.map +1 -1
  16. package/core/error.d.mts.map +1 -1
  17. package/core/error.d.ts.map +1 -1
  18. package/core/error.js +5 -3
  19. package/core/error.js.map +1 -1
  20. package/core/error.mjs +5 -3
  21. package/core/error.mjs.map +1 -1
  22. package/core/pagination.d.mts.map +1 -1
  23. package/core/pagination.d.ts.map +1 -1
  24. package/core/pagination.js +56 -51
  25. package/core/pagination.js.map +1 -1
  26. package/core/pagination.mjs +56 -42
  27. package/core/pagination.mjs.map +1 -1
  28. package/core/resource.d.mts.map +1 -1
  29. package/core/resource.d.ts.map +1 -1
  30. package/core/resource.js +0 -1
  31. package/core/resource.js.map +1 -1
  32. package/core/resource.mjs +0 -1
  33. package/core/resource.mjs.map +1 -1
  34. package/core/streaming.js +212 -209
  35. package/core/streaming.js.map +1 -1
  36. package/core/streaming.mjs +212 -209
  37. package/core/streaming.mjs.map +1 -1
  38. package/helpers/beta/mcp.js +14 -19
  39. package/helpers/beta/mcp.js.map +1 -1
  40. package/helpers/beta/mcp.mjs +14 -13
  41. package/helpers/beta/mcp.mjs.map +1 -1
  42. package/index.d.mts.map +1 -1
  43. package/index.d.ts.map +1 -1
  44. package/index.js +0 -1
  45. package/index.js.map +1 -1
  46. package/index.mjs +0 -1
  47. package/index.mjs.map +1 -1
  48. package/internal/builtin-types.d.mts.map +1 -1
  49. package/internal/builtin-types.d.ts.map +1 -1
  50. package/internal/builtin-types.js +0 -1
  51. package/internal/builtin-types.js.map +1 -1
  52. package/internal/builtin-types.mjs +0 -1
  53. package/internal/builtin-types.mjs.map +1 -1
  54. package/internal/constants.js +1 -1
  55. package/internal/constants.js.map +1 -1
  56. package/internal/decoders/jsonl.js +27 -24
  57. package/internal/decoders/jsonl.js.map +1 -1
  58. package/internal/decoders/jsonl.mjs +27 -24
  59. package/internal/decoders/jsonl.mjs.map +1 -1
  60. package/internal/decoders/line.js +52 -49
  61. package/internal/decoders/line.js.map +1 -1
  62. package/internal/decoders/line.mjs +52 -43
  63. package/internal/decoders/line.mjs.map +1 -1
  64. package/internal/detect-platform.d.mts.map +1 -1
  65. package/internal/detect-platform.d.ts.map +1 -1
  66. package/internal/detect-platform.js +0 -1
  67. package/internal/detect-platform.js.map +1 -1
  68. package/internal/detect-platform.mjs +0 -1
  69. package/internal/detect-platform.mjs.map +1 -1
  70. package/internal/errors.d.mts.map +1 -1
  71. package/internal/errors.d.ts.map +1 -1
  72. package/internal/errors.js +0 -1
  73. package/internal/errors.js.map +1 -1
  74. package/internal/errors.mjs +0 -1
  75. package/internal/errors.mjs.map +1 -1
  76. package/internal/file-store.js +256 -258
  77. package/internal/file-store.js.map +1 -1
  78. package/internal/file-store.mjs +256 -243
  79. package/internal/file-store.mjs.map +1 -1
  80. package/internal/headers.d.mts.map +1 -1
  81. package/internal/headers.d.ts.map +1 -1
  82. package/internal/headers.js +0 -1
  83. package/internal/headers.js.map +1 -1
  84. package/internal/headers.mjs +0 -1
  85. package/internal/headers.mjs.map +1 -1
  86. package/internal/node.browser.d.mts.map +1 -1
  87. package/internal/node.browser.d.ts.map +1 -1
  88. package/internal/node.browser.js.map +1 -1
  89. package/internal/node.browser.mjs +7 -7
  90. package/internal/node.browser.mjs.map +1 -1
  91. package/internal/parse.d.mts.map +1 -1
  92. package/internal/parse.d.ts.map +1 -1
  93. package/internal/parse.js +0 -1
  94. package/internal/parse.js.map +1 -1
  95. package/internal/parse.mjs +0 -1
  96. package/internal/parse.mjs.map +1 -1
  97. package/internal/request-options.d.mts +1 -1
  98. package/internal/request-options.d.mts.map +1 -1
  99. package/internal/request-options.d.ts +1 -1
  100. package/internal/request-options.d.ts.map +1 -1
  101. package/internal/request-options.js +0 -1
  102. package/internal/request-options.js.map +1 -1
  103. package/internal/request-options.mjs +0 -1
  104. package/internal/request-options.mjs.map +1 -1
  105. package/internal/shim-types.d.mts.map +1 -1
  106. package/internal/shim-types.d.ts.map +1 -1
  107. package/internal/shim-types.js +0 -1
  108. package/internal/shim-types.js.map +1 -1
  109. package/internal/shim-types.mjs +0 -1
  110. package/internal/shim-types.mjs.map +1 -1
  111. package/internal/shims.d.mts.map +1 -1
  112. package/internal/shims.d.ts.map +1 -1
  113. package/internal/shims.js +0 -1
  114. package/internal/shims.js.map +1 -1
  115. package/internal/shims.mjs +0 -1
  116. package/internal/shims.mjs.map +1 -1
  117. package/internal/stainless-helper-header.js +6 -6
  118. package/internal/stainless-helper-header.js.map +1 -1
  119. package/internal/types.d.mts.map +1 -1
  120. package/internal/types.d.ts.map +1 -1
  121. package/internal/types.js +0 -1
  122. package/internal/types.js.map +1 -1
  123. package/internal/types.mjs +0 -1
  124. package/internal/types.mjs.map +1 -1
  125. package/internal/utils/async-queue.js +66 -63
  126. package/internal/utils/async-queue.js.map +1 -1
  127. package/internal/utils/async-queue.mjs +66 -56
  128. package/internal/utils/async-queue.mjs.map +1 -1
  129. package/internal/utils/base64.d.mts.map +1 -1
  130. package/internal/utils/base64.d.ts.map +1 -1
  131. package/internal/utils/base64.js +0 -1
  132. package/internal/utils/base64.js.map +1 -1
  133. package/internal/utils/base64.mjs +0 -1
  134. package/internal/utils/base64.mjs.map +1 -1
  135. package/internal/utils/bytes.d.mts +1 -1
  136. package/internal/utils/bytes.d.mts.map +1 -1
  137. package/internal/utils/bytes.d.ts +1 -1
  138. package/internal/utils/bytes.d.ts.map +1 -1
  139. package/internal/utils/env.d.mts.map +1 -1
  140. package/internal/utils/env.d.ts.map +1 -1
  141. package/internal/utils/env.js +0 -1
  142. package/internal/utils/env.js.map +1 -1
  143. package/internal/utils/env.mjs +0 -1
  144. package/internal/utils/env.mjs.map +1 -1
  145. package/internal/utils/log.d.mts.map +1 -1
  146. package/internal/utils/log.d.ts.map +1 -1
  147. package/internal/utils/log.js +0 -1
  148. package/internal/utils/log.js.map +1 -1
  149. package/internal/utils/log.mjs +0 -1
  150. package/internal/utils/log.mjs.map +1 -1
  151. package/internal/utils/query.d.mts.map +1 -1
  152. package/internal/utils/query.d.ts.map +1 -1
  153. package/internal/utils/query.js +0 -1
  154. package/internal/utils/query.js.map +1 -1
  155. package/internal/utils/query.mjs +0 -1
  156. package/internal/utils/query.mjs.map +1 -1
  157. package/internal/utils/uuid.d.mts.map +1 -1
  158. package/internal/utils/uuid.d.ts.map +1 -1
  159. package/internal/utils/uuid.js +0 -1
  160. package/internal/utils/uuid.js.map +1 -1
  161. package/internal/utils/uuid.mjs +0 -1
  162. package/internal/utils/uuid.mjs.map +1 -1
  163. package/internal/utils/values.d.mts.map +1 -1
  164. package/internal/utils/values.d.ts.map +1 -1
  165. package/internal/utils/values.js +0 -1
  166. package/internal/utils/values.js.map +1 -1
  167. package/internal/utils/values.mjs +0 -1
  168. package/internal/utils/values.mjs.map +1 -1
  169. package/internal/utils.d.mts.map +1 -1
  170. package/internal/utils.d.ts.map +1 -1
  171. package/internal/utils.js +0 -1
  172. package/internal/utils.js.map +1 -1
  173. package/internal/utils.mjs +0 -1
  174. package/internal/utils.mjs.map +1 -1
  175. package/lib/BetaMessageStream.js +593 -590
  176. package/lib/BetaMessageStream.js.map +1 -1
  177. package/lib/BetaMessageStream.mjs +593 -590
  178. package/lib/BetaMessageStream.mjs.map +1 -1
  179. package/lib/MessageStream.js +544 -541
  180. package/lib/MessageStream.js.map +1 -1
  181. package/lib/MessageStream.mjs +544 -541
  182. package/lib/MessageStream.mjs.map +1 -1
  183. package/lib/environments/poller.js +180 -174
  184. package/lib/environments/poller.js.map +1 -1
  185. package/lib/environments/poller.mjs +180 -153
  186. package/lib/environments/poller.mjs.map +1 -1
  187. package/lib/environments/worker.d.mts +14 -8
  188. package/lib/environments/worker.d.mts.map +1 -1
  189. package/lib/environments/worker.d.ts +14 -8
  190. package/lib/environments/worker.d.ts.map +1 -1
  191. package/lib/environments/worker.js +375 -359
  192. package/lib/environments/worker.js.map +1 -1
  193. package/lib/environments/worker.mjs +374 -319
  194. package/lib/environments/worker.mjs.map +1 -1
  195. package/lib/tools/BetaToolRunner.js +316 -313
  196. package/lib/tools/BetaToolRunner.js.map +1 -1
  197. package/lib/tools/BetaToolRunner.mjs +315 -306
  198. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  199. package/lib/tools/SessionToolRunner.js +241 -235
  200. package/lib/tools/SessionToolRunner.js.map +1 -1
  201. package/lib/tools/SessionToolRunner.mjs +241 -192
  202. package/lib/tools/SessionToolRunner.mjs.map +1 -1
  203. package/lib/tools/ToolError.js +39 -36
  204. package/lib/tools/ToolError.js.map +1 -1
  205. package/lib/tools/ToolError.mjs +39 -13
  206. package/lib/tools/ToolError.mjs.map +1 -1
  207. package/package.json +3 -3
  208. package/resources/beta/agents/agents.d.mts +32 -23
  209. package/resources/beta/agents/agents.d.mts.map +1 -1
  210. package/resources/beta/agents/agents.d.ts +32 -23
  211. package/resources/beta/agents/agents.d.ts.map +1 -1
  212. package/resources/beta/agents/agents.js +135 -133
  213. package/resources/beta/agents/agents.js.map +1 -1
  214. package/resources/beta/agents/agents.mjs +135 -133
  215. package/resources/beta/agents/agents.mjs.map +1 -1
  216. package/resources/beta/agents/index.d.mts +1 -1
  217. package/resources/beta/agents/index.d.mts.map +1 -1
  218. package/resources/beta/agents/index.d.ts +1 -1
  219. package/resources/beta/agents/index.d.ts.map +1 -1
  220. package/resources/beta/agents/index.js +0 -1
  221. package/resources/beta/agents/index.js.map +1 -1
  222. package/resources/beta/agents/index.mjs +0 -1
  223. package/resources/beta/agents/index.mjs.map +1 -1
  224. package/resources/beta/agents/versions.d.mts.map +1 -1
  225. package/resources/beta/agents/versions.d.ts.map +1 -1
  226. package/resources/beta/agents/versions.js +0 -1
  227. package/resources/beta/agents/versions.js.map +1 -1
  228. package/resources/beta/agents/versions.mjs +0 -1
  229. package/resources/beta/agents/versions.mjs.map +1 -1
  230. package/resources/beta/agents.d.mts.map +1 -1
  231. package/resources/beta/agents.d.ts.map +1 -1
  232. package/resources/beta/agents.js +0 -1
  233. package/resources/beta/agents.js.map +1 -1
  234. package/resources/beta/agents.mjs +0 -1
  235. package/resources/beta/agents.mjs.map +1 -1
  236. package/resources/beta/beta.d.mts +9 -9
  237. package/resources/beta/beta.d.mts.map +1 -1
  238. package/resources/beta/beta.d.ts +9 -9
  239. package/resources/beta/beta.d.ts.map +1 -1
  240. package/resources/beta/beta.js +39 -37
  241. package/resources/beta/beta.js.map +1 -1
  242. package/resources/beta/beta.mjs +39 -37
  243. package/resources/beta/beta.mjs.map +1 -1
  244. package/resources/beta/deployment-runs.d.mts.map +1 -1
  245. package/resources/beta/deployment-runs.d.ts.map +1 -1
  246. package/resources/beta/deployment-runs.js +0 -1
  247. package/resources/beta/deployment-runs.js.map +1 -1
  248. package/resources/beta/deployment-runs.mjs +0 -1
  249. package/resources/beta/deployment-runs.mjs.map +1 -1
  250. package/resources/beta/deployments.d.mts.map +1 -1
  251. package/resources/beta/deployments.d.ts.map +1 -1
  252. package/resources/beta/deployments.js +0 -1
  253. package/resources/beta/deployments.js.map +1 -1
  254. package/resources/beta/deployments.mjs +0 -1
  255. package/resources/beta/deployments.mjs.map +1 -1
  256. package/resources/beta/dreams.d.mts +2 -28
  257. package/resources/beta/dreams.d.mts.map +1 -1
  258. package/resources/beta/dreams.d.ts +2 -28
  259. package/resources/beta/dreams.d.ts.map +1 -1
  260. package/resources/beta/dreams.js +0 -1
  261. package/resources/beta/dreams.js.map +1 -1
  262. package/resources/beta/dreams.mjs +0 -1
  263. package/resources/beta/dreams.mjs.map +1 -1
  264. package/resources/beta/environments/environments.d.mts +2 -2
  265. package/resources/beta/environments/environments.d.mts.map +1 -1
  266. package/resources/beta/environments/environments.d.ts +2 -2
  267. package/resources/beta/environments/environments.d.ts.map +1 -1
  268. package/resources/beta/environments/environments.js +157 -155
  269. package/resources/beta/environments/environments.js.map +1 -1
  270. package/resources/beta/environments/environments.mjs +157 -155
  271. package/resources/beta/environments/environments.mjs.map +1 -1
  272. package/resources/beta/environments/index.d.mts.map +1 -1
  273. package/resources/beta/environments/index.d.ts.map +1 -1
  274. package/resources/beta/environments/index.js +0 -1
  275. package/resources/beta/environments/index.js.map +1 -1
  276. package/resources/beta/environments/index.mjs +0 -1
  277. package/resources/beta/environments/index.mjs.map +1 -1
  278. package/resources/beta/environments/work.d.mts.map +1 -1
  279. package/resources/beta/environments/work.d.ts.map +1 -1
  280. package/resources/beta/environments/work.js +255 -253
  281. package/resources/beta/environments/work.js.map +1 -1
  282. package/resources/beta/environments/work.mjs +255 -253
  283. package/resources/beta/environments/work.mjs.map +1 -1
  284. package/resources/beta/environments.d.mts.map +1 -1
  285. package/resources/beta/environments.d.ts.map +1 -1
  286. package/resources/beta/environments.js +0 -1
  287. package/resources/beta/environments.js.map +1 -1
  288. package/resources/beta/environments.mjs +0 -1
  289. package/resources/beta/environments.mjs.map +1 -1
  290. package/resources/beta/files.d.mts.map +1 -1
  291. package/resources/beta/files.d.ts.map +1 -1
  292. package/resources/beta/files.js +0 -1
  293. package/resources/beta/files.js.map +1 -1
  294. package/resources/beta/files.mjs +0 -1
  295. package/resources/beta/files.mjs.map +1 -1
  296. package/resources/beta/index.d.mts +4 -4
  297. package/resources/beta/index.d.mts.map +1 -1
  298. package/resources/beta/index.d.ts +4 -4
  299. package/resources/beta/index.d.ts.map +1 -1
  300. package/resources/beta/index.js +0 -1
  301. package/resources/beta/index.js.map +1 -1
  302. package/resources/beta/index.mjs +0 -1
  303. package/resources/beta/index.mjs.map +1 -1
  304. package/resources/beta/memory-stores/index.d.mts.map +1 -1
  305. package/resources/beta/memory-stores/index.d.ts.map +1 -1
  306. package/resources/beta/memory-stores/index.js +0 -1
  307. package/resources/beta/memory-stores/index.js.map +1 -1
  308. package/resources/beta/memory-stores/index.mjs +0 -1
  309. package/resources/beta/memory-stores/index.mjs.map +1 -1
  310. package/resources/beta/memory-stores/memories.d.mts.map +1 -1
  311. package/resources/beta/memory-stores/memories.d.ts.map +1 -1
  312. package/resources/beta/memory-stores/memories.js +0 -1
  313. package/resources/beta/memory-stores/memories.js.map +1 -1
  314. package/resources/beta/memory-stores/memories.mjs +0 -1
  315. package/resources/beta/memory-stores/memories.mjs.map +1 -1
  316. package/resources/beta/memory-stores/memory-stores.d.mts.map +1 -1
  317. package/resources/beta/memory-stores/memory-stores.d.ts.map +1 -1
  318. package/resources/beta/memory-stores/memory-stores.js +150 -148
  319. package/resources/beta/memory-stores/memory-stores.js.map +1 -1
  320. package/resources/beta/memory-stores/memory-stores.mjs +150 -148
  321. package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
  322. package/resources/beta/memory-stores/memory-versions.d.mts.map +1 -1
  323. package/resources/beta/memory-stores/memory-versions.d.ts.map +1 -1
  324. package/resources/beta/memory-stores/memory-versions.js +0 -1
  325. package/resources/beta/memory-stores/memory-versions.js.map +1 -1
  326. package/resources/beta/memory-stores/memory-versions.mjs +0 -1
  327. package/resources/beta/memory-stores/memory-versions.mjs.map +1 -1
  328. package/resources/beta/memory-stores.d.mts.map +1 -1
  329. package/resources/beta/memory-stores.d.ts.map +1 -1
  330. package/resources/beta/memory-stores.js +0 -1
  331. package/resources/beta/memory-stores.js.map +1 -1
  332. package/resources/beta/memory-stores.mjs +0 -1
  333. package/resources/beta/memory-stores.mjs.map +1 -1
  334. package/resources/beta/messages/batches.d.mts +12 -1
  335. package/resources/beta/messages/batches.d.mts.map +1 -1
  336. package/resources/beta/messages/batches.d.ts +12 -1
  337. package/resources/beta/messages/batches.d.ts.map +1 -1
  338. package/resources/beta/messages/batches.js +0 -1
  339. package/resources/beta/messages/batches.js.map +1 -1
  340. package/resources/beta/messages/batches.mjs +0 -1
  341. package/resources/beta/messages/batches.mjs.map +1 -1
  342. package/resources/beta/messages/index.d.mts +1 -1
  343. package/resources/beta/messages/index.d.mts.map +1 -1
  344. package/resources/beta/messages/index.d.ts +1 -1
  345. package/resources/beta/messages/index.d.ts.map +1 -1
  346. package/resources/beta/messages/index.js +0 -1
  347. package/resources/beta/messages/index.js.map +1 -1
  348. package/resources/beta/messages/index.mjs +0 -1
  349. package/resources/beta/messages/index.mjs.map +1 -1
  350. package/resources/beta/messages/messages.d.mts +239 -101
  351. package/resources/beta/messages/messages.d.mts.map +1 -1
  352. package/resources/beta/messages/messages.d.ts +239 -101
  353. package/resources/beta/messages/messages.d.ts.map +1 -1
  354. package/resources/beta/messages/messages.js +113 -111
  355. package/resources/beta/messages/messages.js.map +1 -1
  356. package/resources/beta/messages/messages.mjs +113 -111
  357. package/resources/beta/messages/messages.mjs.map +1 -1
  358. package/resources/beta/messages.d.mts.map +1 -1
  359. package/resources/beta/messages.d.ts.map +1 -1
  360. package/resources/beta/messages.js +0 -1
  361. package/resources/beta/messages.js.map +1 -1
  362. package/resources/beta/messages.mjs +0 -1
  363. package/resources/beta/messages.mjs.map +1 -1
  364. package/resources/beta/models.d.mts +22 -1
  365. package/resources/beta/models.d.mts.map +1 -1
  366. package/resources/beta/models.d.ts +22 -1
  367. package/resources/beta/models.d.ts.map +1 -1
  368. package/resources/beta/models.js +0 -1
  369. package/resources/beta/models.js.map +1 -1
  370. package/resources/beta/models.mjs +0 -1
  371. package/resources/beta/models.mjs.map +1 -1
  372. package/resources/beta/organization/api-keys.d.mts.map +1 -1
  373. package/resources/beta/organization/api-keys.d.ts.map +1 -1
  374. package/resources/beta/organization/api-keys.js +0 -1
  375. package/resources/beta/organization/api-keys.js.map +1 -1
  376. package/resources/beta/organization/api-keys.mjs +0 -1
  377. package/resources/beta/organization/api-keys.mjs.map +1 -1
  378. package/resources/beta/organization/compliance-settings.d.mts.map +1 -1
  379. package/resources/beta/organization/compliance-settings.d.ts.map +1 -1
  380. package/resources/beta/organization/compliance-settings.js +0 -1
  381. package/resources/beta/organization/compliance-settings.js.map +1 -1
  382. package/resources/beta/organization/compliance-settings.mjs +0 -1
  383. package/resources/beta/organization/compliance-settings.mjs.map +1 -1
  384. package/resources/beta/organization/external-keys.d.mts.map +1 -1
  385. package/resources/beta/organization/external-keys.d.ts.map +1 -1
  386. package/resources/beta/organization/external-keys.js +0 -1
  387. package/resources/beta/organization/external-keys.js.map +1 -1
  388. package/resources/beta/organization/external-keys.mjs +0 -1
  389. package/resources/beta/organization/external-keys.mjs.map +1 -1
  390. package/resources/beta/organization/federation/federation.d.mts.map +1 -1
  391. package/resources/beta/organization/federation/federation.d.ts.map +1 -1
  392. package/resources/beta/organization/federation/federation.js +11 -9
  393. package/resources/beta/organization/federation/federation.js.map +1 -1
  394. package/resources/beta/organization/federation/federation.mjs +11 -9
  395. package/resources/beta/organization/federation/federation.mjs.map +1 -1
  396. package/resources/beta/organization/federation/index.d.mts.map +1 -1
  397. package/resources/beta/organization/federation/index.d.ts.map +1 -1
  398. package/resources/beta/organization/federation/index.js +0 -1
  399. package/resources/beta/organization/federation/index.js.map +1 -1
  400. package/resources/beta/organization/federation/index.mjs +0 -1
  401. package/resources/beta/organization/federation/index.mjs.map +1 -1
  402. package/resources/beta/organization/federation/issuers.d.mts.map +1 -1
  403. package/resources/beta/organization/federation/issuers.d.ts.map +1 -1
  404. package/resources/beta/organization/federation/issuers.js +0 -1
  405. package/resources/beta/organization/federation/issuers.js.map +1 -1
  406. package/resources/beta/organization/federation/issuers.mjs +0 -1
  407. package/resources/beta/organization/federation/issuers.mjs.map +1 -1
  408. package/resources/beta/organization/federation/rules/index.d.mts.map +1 -1
  409. package/resources/beta/organization/federation/rules/index.d.ts.map +1 -1
  410. package/resources/beta/organization/federation/rules/index.js +0 -1
  411. package/resources/beta/organization/federation/rules/index.js.map +1 -1
  412. package/resources/beta/organization/federation/rules/index.mjs +0 -1
  413. package/resources/beta/organization/federation/rules/index.mjs.map +1 -1
  414. package/resources/beta/organization/federation/rules/rules.d.mts.map +1 -1
  415. package/resources/beta/organization/federation/rules/rules.d.ts.map +1 -1
  416. package/resources/beta/organization/federation/rules/rules.js +187 -185
  417. package/resources/beta/organization/federation/rules/rules.js.map +1 -1
  418. package/resources/beta/organization/federation/rules/rules.mjs +187 -185
  419. package/resources/beta/organization/federation/rules/rules.mjs.map +1 -1
  420. package/resources/beta/organization/federation/rules/workspaces.d.mts.map +1 -1
  421. package/resources/beta/organization/federation/rules/workspaces.d.ts.map +1 -1
  422. package/resources/beta/organization/federation/rules/workspaces.js +0 -1
  423. package/resources/beta/organization/federation/rules/workspaces.js.map +1 -1
  424. package/resources/beta/organization/federation/rules/workspaces.mjs +0 -1
  425. package/resources/beta/organization/federation/rules/workspaces.mjs.map +1 -1
  426. package/resources/beta/organization/federation/rules.d.mts.map +1 -1
  427. package/resources/beta/organization/federation/rules.d.ts.map +1 -1
  428. package/resources/beta/organization/federation/rules.js +0 -1
  429. package/resources/beta/organization/federation/rules.js.map +1 -1
  430. package/resources/beta/organization/federation/rules.mjs +0 -1
  431. package/resources/beta/organization/federation/rules.mjs.map +1 -1
  432. package/resources/beta/organization/federation.d.mts.map +1 -1
  433. package/resources/beta/organization/federation.d.ts.map +1 -1
  434. package/resources/beta/organization/federation.js +0 -1
  435. package/resources/beta/organization/federation.js.map +1 -1
  436. package/resources/beta/organization/federation.mjs +0 -1
  437. package/resources/beta/organization/federation.mjs.map +1 -1
  438. package/resources/beta/organization/index.d.mts.map +1 -1
  439. package/resources/beta/organization/index.d.ts.map +1 -1
  440. package/resources/beta/organization/index.js +0 -1
  441. package/resources/beta/organization/index.js.map +1 -1
  442. package/resources/beta/organization/index.mjs +0 -1
  443. package/resources/beta/organization/index.mjs.map +1 -1
  444. package/resources/beta/organization/invites.d.mts.map +1 -1
  445. package/resources/beta/organization/invites.d.ts.map +1 -1
  446. package/resources/beta/organization/invites.js +0 -1
  447. package/resources/beta/organization/invites.js.map +1 -1
  448. package/resources/beta/organization/invites.mjs +0 -1
  449. package/resources/beta/organization/invites.mjs.map +1 -1
  450. package/resources/beta/organization/organization.d.mts.map +1 -1
  451. package/resources/beta/organization/organization.d.ts.map +1 -1
  452. package/resources/beta/organization/organization.js +38 -36
  453. package/resources/beta/organization/organization.js.map +1 -1
  454. package/resources/beta/organization/organization.mjs +38 -36
  455. package/resources/beta/organization/organization.mjs.map +1 -1
  456. package/resources/beta/organization/rate-limits.d.mts.map +1 -1
  457. package/resources/beta/organization/rate-limits.d.ts.map +1 -1
  458. package/resources/beta/organization/rate-limits.js +0 -1
  459. package/resources/beta/organization/rate-limits.js.map +1 -1
  460. package/resources/beta/organization/rate-limits.mjs +0 -1
  461. package/resources/beta/organization/rate-limits.mjs.map +1 -1
  462. package/resources/beta/organization/service-accounts/index.d.mts.map +1 -1
  463. package/resources/beta/organization/service-accounts/index.d.ts.map +1 -1
  464. package/resources/beta/organization/service-accounts/index.js +0 -1
  465. package/resources/beta/organization/service-accounts/index.js.map +1 -1
  466. package/resources/beta/organization/service-accounts/index.mjs +0 -1
  467. package/resources/beta/organization/service-accounts/index.mjs.map +1 -1
  468. package/resources/beta/organization/service-accounts/service-accounts.d.mts.map +1 -1
  469. package/resources/beta/organization/service-accounts/service-accounts.d.ts.map +1 -1
  470. package/resources/beta/organization/service-accounts/service-accounts.js +163 -161
  471. package/resources/beta/organization/service-accounts/service-accounts.js.map +1 -1
  472. package/resources/beta/organization/service-accounts/service-accounts.mjs +163 -161
  473. package/resources/beta/organization/service-accounts/service-accounts.mjs.map +1 -1
  474. package/resources/beta/organization/service-accounts/workspaces.d.mts.map +1 -1
  475. package/resources/beta/organization/service-accounts/workspaces.d.ts.map +1 -1
  476. package/resources/beta/organization/service-accounts/workspaces.js +0 -1
  477. package/resources/beta/organization/service-accounts/workspaces.js.map +1 -1
  478. package/resources/beta/organization/service-accounts/workspaces.mjs +0 -1
  479. package/resources/beta/organization/service-accounts/workspaces.mjs.map +1 -1
  480. package/resources/beta/organization/service-accounts.d.mts.map +1 -1
  481. package/resources/beta/organization/service-accounts.d.ts.map +1 -1
  482. package/resources/beta/organization/service-accounts.js +0 -1
  483. package/resources/beta/organization/service-accounts.js.map +1 -1
  484. package/resources/beta/organization/service-accounts.mjs +0 -1
  485. package/resources/beta/organization/service-accounts.mjs.map +1 -1
  486. package/resources/beta/organization/users.d.mts.map +1 -1
  487. package/resources/beta/organization/users.d.ts.map +1 -1
  488. package/resources/beta/organization/users.js +0 -1
  489. package/resources/beta/organization/users.js.map +1 -1
  490. package/resources/beta/organization/users.mjs +0 -1
  491. package/resources/beta/organization/users.mjs.map +1 -1
  492. package/resources/beta/organization/workspaces/index.d.mts.map +1 -1
  493. package/resources/beta/organization/workspaces/index.d.ts.map +1 -1
  494. package/resources/beta/organization/workspaces/index.js +0 -1
  495. package/resources/beta/organization/workspaces/index.js.map +1 -1
  496. package/resources/beta/organization/workspaces/index.mjs +0 -1
  497. package/resources/beta/organization/workspaces/index.mjs.map +1 -1
  498. package/resources/beta/organization/workspaces/members.d.mts.map +1 -1
  499. package/resources/beta/organization/workspaces/members.d.ts.map +1 -1
  500. package/resources/beta/organization/workspaces/members.js +0 -1
  501. package/resources/beta/organization/workspaces/members.js.map +1 -1
  502. package/resources/beta/organization/workspaces/members.mjs +0 -1
  503. package/resources/beta/organization/workspaces/members.mjs.map +1 -1
  504. package/resources/beta/organization/workspaces/rate-limits.d.mts.map +1 -1
  505. package/resources/beta/organization/workspaces/rate-limits.d.ts.map +1 -1
  506. package/resources/beta/organization/workspaces/rate-limits.js +0 -1
  507. package/resources/beta/organization/workspaces/rate-limits.js.map +1 -1
  508. package/resources/beta/organization/workspaces/rate-limits.mjs +0 -1
  509. package/resources/beta/organization/workspaces/rate-limits.mjs.map +1 -1
  510. package/resources/beta/organization/workspaces/service-accounts.d.mts.map +1 -1
  511. package/resources/beta/organization/workspaces/service-accounts.d.ts.map +1 -1
  512. package/resources/beta/organization/workspaces/service-accounts.js +0 -1
  513. package/resources/beta/organization/workspaces/service-accounts.js.map +1 -1
  514. package/resources/beta/organization/workspaces/service-accounts.mjs +0 -1
  515. package/resources/beta/organization/workspaces/service-accounts.mjs.map +1 -1
  516. package/resources/beta/organization/workspaces/workspaces.d.mts +3 -3
  517. package/resources/beta/organization/workspaces/workspaces.d.mts.map +1 -1
  518. package/resources/beta/organization/workspaces/workspaces.d.ts +3 -3
  519. package/resources/beta/organization/workspaces/workspaces.d.ts.map +1 -1
  520. package/resources/beta/organization/workspaces/workspaces.js +97 -95
  521. package/resources/beta/organization/workspaces/workspaces.js.map +1 -1
  522. package/resources/beta/organization/workspaces/workspaces.mjs +97 -95
  523. package/resources/beta/organization/workspaces/workspaces.mjs.map +1 -1
  524. package/resources/beta/organization/workspaces.d.mts.map +1 -1
  525. package/resources/beta/organization/workspaces.d.ts.map +1 -1
  526. package/resources/beta/organization/workspaces.js +0 -1
  527. package/resources/beta/organization/workspaces.js.map +1 -1
  528. package/resources/beta/organization/workspaces.mjs +0 -1
  529. package/resources/beta/organization/workspaces.mjs.map +1 -1
  530. package/resources/beta/organization.d.mts.map +1 -1
  531. package/resources/beta/organization.d.ts.map +1 -1
  532. package/resources/beta/organization.js +0 -1
  533. package/resources/beta/organization.js.map +1 -1
  534. package/resources/beta/organization.mjs +0 -1
  535. package/resources/beta/organization.mjs.map +1 -1
  536. package/resources/beta/sessions/events.d.mts +95 -22
  537. package/resources/beta/sessions/events.d.mts.map +1 -1
  538. package/resources/beta/sessions/events.d.ts +95 -22
  539. package/resources/beta/sessions/events.d.ts.map +1 -1
  540. package/resources/beta/sessions/events.js +118 -116
  541. package/resources/beta/sessions/events.js.map +1 -1
  542. package/resources/beta/sessions/events.mjs +118 -116
  543. package/resources/beta/sessions/events.mjs.map +1 -1
  544. package/resources/beta/sessions/index.d.mts +1 -1
  545. package/resources/beta/sessions/index.d.mts.map +1 -1
  546. package/resources/beta/sessions/index.d.ts +1 -1
  547. package/resources/beta/sessions/index.d.ts.map +1 -1
  548. package/resources/beta/sessions/index.js +0 -1
  549. package/resources/beta/sessions/index.js.map +1 -1
  550. package/resources/beta/sessions/index.mjs +0 -1
  551. package/resources/beta/sessions/index.mjs.map +1 -1
  552. package/resources/beta/sessions/resources.d.mts +0 -3
  553. package/resources/beta/sessions/resources.d.mts.map +1 -1
  554. package/resources/beta/sessions/resources.d.ts +0 -3
  555. package/resources/beta/sessions/resources.d.ts.map +1 -1
  556. package/resources/beta/sessions/resources.js +0 -1
  557. package/resources/beta/sessions/resources.js.map +1 -1
  558. package/resources/beta/sessions/resources.mjs +0 -1
  559. package/resources/beta/sessions/resources.mjs.map +1 -1
  560. package/resources/beta/sessions/sessions.d.mts +9 -8
  561. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  562. package/resources/beta/sessions/sessions.d.ts +9 -8
  563. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  564. package/resources/beta/sessions/sessions.js +161 -159
  565. package/resources/beta/sessions/sessions.js.map +1 -1
  566. package/resources/beta/sessions/sessions.mjs +161 -159
  567. package/resources/beta/sessions/sessions.mjs.map +1 -1
  568. package/resources/beta/sessions/threads/events.d.mts.map +1 -1
  569. package/resources/beta/sessions/threads/events.d.ts.map +1 -1
  570. package/resources/beta/sessions/threads/events.js +0 -1
  571. package/resources/beta/sessions/threads/events.js.map +1 -1
  572. package/resources/beta/sessions/threads/events.mjs +0 -1
  573. package/resources/beta/sessions/threads/events.mjs.map +1 -1
  574. package/resources/beta/sessions/threads/index.d.mts.map +1 -1
  575. package/resources/beta/sessions/threads/index.d.ts.map +1 -1
  576. package/resources/beta/sessions/threads/index.js +0 -1
  577. package/resources/beta/sessions/threads/index.js.map +1 -1
  578. package/resources/beta/sessions/threads/index.mjs +0 -1
  579. package/resources/beta/sessions/threads/index.mjs.map +1 -1
  580. package/resources/beta/sessions/threads/threads.d.mts.map +1 -1
  581. package/resources/beta/sessions/threads/threads.d.ts.map +1 -1
  582. package/resources/beta/sessions/threads/threads.js +86 -84
  583. package/resources/beta/sessions/threads/threads.js.map +1 -1
  584. package/resources/beta/sessions/threads/threads.mjs +86 -84
  585. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  586. package/resources/beta/sessions/threads.d.mts.map +1 -1
  587. package/resources/beta/sessions/threads.d.ts.map +1 -1
  588. package/resources/beta/sessions/threads.js +0 -1
  589. package/resources/beta/sessions/threads.js.map +1 -1
  590. package/resources/beta/sessions/threads.mjs +0 -1
  591. package/resources/beta/sessions/threads.mjs.map +1 -1
  592. package/resources/beta/sessions.d.mts.map +1 -1
  593. package/resources/beta/sessions.d.ts.map +1 -1
  594. package/resources/beta/sessions.js +0 -1
  595. package/resources/beta/sessions.js.map +1 -1
  596. package/resources/beta/sessions.mjs +0 -1
  597. package/resources/beta/sessions.mjs.map +1 -1
  598. package/resources/beta/skills/index.d.mts.map +1 -1
  599. package/resources/beta/skills/index.d.ts.map +1 -1
  600. package/resources/beta/skills/index.js +0 -1
  601. package/resources/beta/skills/index.js.map +1 -1
  602. package/resources/beta/skills/index.mjs +0 -1
  603. package/resources/beta/skills/index.mjs.map +1 -1
  604. package/resources/beta/skills/skills.d.mts.map +1 -1
  605. package/resources/beta/skills/skills.d.ts.map +1 -1
  606. package/resources/beta/skills/skills.js +104 -102
  607. package/resources/beta/skills/skills.js.map +1 -1
  608. package/resources/beta/skills/skills.mjs +104 -102
  609. package/resources/beta/skills/skills.mjs.map +1 -1
  610. package/resources/beta/skills/versions.d.mts.map +1 -1
  611. package/resources/beta/skills/versions.d.ts.map +1 -1
  612. package/resources/beta/skills/versions.js +0 -1
  613. package/resources/beta/skills/versions.js.map +1 -1
  614. package/resources/beta/skills/versions.mjs +0 -1
  615. package/resources/beta/skills/versions.mjs.map +1 -1
  616. package/resources/beta/skills.d.mts.map +1 -1
  617. package/resources/beta/skills.d.ts.map +1 -1
  618. package/resources/beta/skills.js +0 -1
  619. package/resources/beta/skills.js.map +1 -1
  620. package/resources/beta/skills.mjs +0 -1
  621. package/resources/beta/skills.mjs.map +1 -1
  622. package/resources/beta/tunnels/certificates.d.mts.map +1 -1
  623. package/resources/beta/tunnels/certificates.d.ts.map +1 -1
  624. package/resources/beta/tunnels/certificates.js +0 -1
  625. package/resources/beta/tunnels/certificates.js.map +1 -1
  626. package/resources/beta/tunnels/certificates.mjs +0 -1
  627. package/resources/beta/tunnels/certificates.mjs.map +1 -1
  628. package/resources/beta/tunnels/index.d.mts.map +1 -1
  629. package/resources/beta/tunnels/index.d.ts.map +1 -1
  630. package/resources/beta/tunnels/index.js +0 -1
  631. package/resources/beta/tunnels/index.js.map +1 -1
  632. package/resources/beta/tunnels/index.mjs +0 -1
  633. package/resources/beta/tunnels/index.mjs.map +1 -1
  634. package/resources/beta/tunnels/tunnels.d.mts.map +1 -1
  635. package/resources/beta/tunnels/tunnels.d.ts.map +1 -1
  636. package/resources/beta/tunnels/tunnels.js +188 -186
  637. package/resources/beta/tunnels/tunnels.js.map +1 -1
  638. package/resources/beta/tunnels/tunnels.mjs +188 -186
  639. package/resources/beta/tunnels/tunnels.mjs.map +1 -1
  640. package/resources/beta/tunnels.d.mts.map +1 -1
  641. package/resources/beta/tunnels.d.ts.map +1 -1
  642. package/resources/beta/tunnels.js +0 -1
  643. package/resources/beta/tunnels.js.map +1 -1
  644. package/resources/beta/tunnels.mjs +0 -1
  645. package/resources/beta/tunnels.mjs.map +1 -1
  646. package/resources/beta/user-profiles.d.mts +160 -4
  647. package/resources/beta/user-profiles.d.mts.map +1 -1
  648. package/resources/beta/user-profiles.d.ts +160 -4
  649. package/resources/beta/user-profiles.d.ts.map +1 -1
  650. package/resources/beta/user-profiles.js +25 -11
  651. package/resources/beta/user-profiles.js.map +1 -1
  652. package/resources/beta/user-profiles.mjs +25 -11
  653. package/resources/beta/user-profiles.mjs.map +1 -1
  654. package/resources/beta/vaults/credentials.d.mts +0 -14
  655. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  656. package/resources/beta/vaults/credentials.d.ts +0 -14
  657. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  658. package/resources/beta/vaults/credentials.js +0 -1
  659. package/resources/beta/vaults/credentials.js.map +1 -1
  660. package/resources/beta/vaults/credentials.mjs +0 -1
  661. package/resources/beta/vaults/credentials.mjs.map +1 -1
  662. package/resources/beta/vaults/index.d.mts.map +1 -1
  663. package/resources/beta/vaults/index.d.ts.map +1 -1
  664. package/resources/beta/vaults/index.js +0 -1
  665. package/resources/beta/vaults/index.js.map +1 -1
  666. package/resources/beta/vaults/index.mjs +0 -1
  667. package/resources/beta/vaults/index.mjs.map +1 -1
  668. package/resources/beta/vaults/vaults.d.mts.map +1 -1
  669. package/resources/beta/vaults/vaults.d.ts.map +1 -1
  670. package/resources/beta/vaults/vaults.js +156 -154
  671. package/resources/beta/vaults/vaults.js.map +1 -1
  672. package/resources/beta/vaults/vaults.mjs +156 -154
  673. package/resources/beta/vaults/vaults.mjs.map +1 -1
  674. package/resources/beta/vaults.d.mts.map +1 -1
  675. package/resources/beta/vaults.d.ts.map +1 -1
  676. package/resources/beta/vaults.js +0 -1
  677. package/resources/beta/vaults.js.map +1 -1
  678. package/resources/beta/vaults.mjs +0 -1
  679. package/resources/beta/vaults.mjs.map +1 -1
  680. package/resources/beta/webhooks.d.mts.map +1 -1
  681. package/resources/beta/webhooks.d.ts.map +1 -1
  682. package/resources/beta/webhooks.js +0 -1
  683. package/resources/beta/webhooks.js.map +1 -1
  684. package/resources/beta/webhooks.mjs +0 -1
  685. package/resources/beta/webhooks.mjs.map +1 -1
  686. package/resources/beta.d.mts.map +1 -1
  687. package/resources/beta.d.ts.map +1 -1
  688. package/resources/beta.js +0 -1
  689. package/resources/beta.js.map +1 -1
  690. package/resources/beta.mjs +0 -1
  691. package/resources/beta.mjs.map +1 -1
  692. package/resources/completions.d.mts +1 -1
  693. package/resources/completions.d.mts.map +1 -1
  694. package/resources/completions.d.ts +1 -1
  695. package/resources/completions.d.ts.map +1 -1
  696. package/resources/completions.js +0 -1
  697. package/resources/completions.js.map +1 -1
  698. package/resources/completions.mjs +0 -1
  699. package/resources/completions.mjs.map +1 -1
  700. package/resources/files.d.mts.map +1 -1
  701. package/resources/files.d.ts.map +1 -1
  702. package/resources/files.js +0 -1
  703. package/resources/files.js.map +1 -1
  704. package/resources/files.mjs +0 -1
  705. package/resources/files.mjs.map +1 -1
  706. package/resources/index.d.mts +1 -1
  707. package/resources/index.d.mts.map +1 -1
  708. package/resources/index.d.ts +1 -1
  709. package/resources/index.d.ts.map +1 -1
  710. package/resources/index.js +0 -1
  711. package/resources/index.js.map +1 -1
  712. package/resources/index.mjs +0 -1
  713. package/resources/index.mjs.map +1 -1
  714. package/resources/messages/batches.d.mts.map +1 -1
  715. package/resources/messages/batches.d.ts.map +1 -1
  716. package/resources/messages/batches.js +0 -1
  717. package/resources/messages/batches.js.map +1 -1
  718. package/resources/messages/batches.mjs +0 -1
  719. package/resources/messages/batches.mjs.map +1 -1
  720. package/resources/messages/index.d.mts +1 -1
  721. package/resources/messages/index.d.mts.map +1 -1
  722. package/resources/messages/index.d.ts +1 -1
  723. package/resources/messages/index.d.ts.map +1 -1
  724. package/resources/messages/index.js +0 -1
  725. package/resources/messages/index.js.map +1 -1
  726. package/resources/messages/index.mjs +0 -1
  727. package/resources/messages/index.mjs.map +1 -1
  728. package/resources/messages/messages.d.mts +101 -64
  729. package/resources/messages/messages.d.mts.map +1 -1
  730. package/resources/messages/messages.d.ts +101 -64
  731. package/resources/messages/messages.d.ts.map +1 -1
  732. package/resources/messages/messages.js +115 -113
  733. package/resources/messages/messages.js.map +1 -1
  734. package/resources/messages/messages.mjs +115 -113
  735. package/resources/messages/messages.mjs.map +1 -1
  736. package/resources/messages.d.mts.map +1 -1
  737. package/resources/messages.d.ts.map +1 -1
  738. package/resources/messages.js +0 -1
  739. package/resources/messages.js.map +1 -1
  740. package/resources/messages.mjs +0 -1
  741. package/resources/messages.mjs.map +1 -1
  742. package/resources/models.d.mts.map +1 -1
  743. package/resources/models.d.ts.map +1 -1
  744. package/resources/models.js +0 -1
  745. package/resources/models.js.map +1 -1
  746. package/resources/models.mjs +0 -1
  747. package/resources/models.mjs.map +1 -1
  748. package/resources/shared.d.mts.map +1 -1
  749. package/resources/shared.d.ts.map +1 -1
  750. package/resources/shared.js +0 -1
  751. package/resources/shared.js.map +1 -1
  752. package/resources/shared.mjs +0 -1
  753. package/resources/shared.mjs.map +1 -1
  754. package/resources/skills/index.d.mts.map +1 -1
  755. package/resources/skills/index.d.ts.map +1 -1
  756. package/resources/skills/index.js +0 -1
  757. package/resources/skills/index.js.map +1 -1
  758. package/resources/skills/index.mjs +0 -1
  759. package/resources/skills/index.mjs.map +1 -1
  760. package/resources/skills/skills.d.mts.map +1 -1
  761. package/resources/skills/skills.d.ts.map +1 -1
  762. package/resources/skills/skills.js +88 -86
  763. package/resources/skills/skills.js.map +1 -1
  764. package/resources/skills/skills.mjs +88 -86
  765. package/resources/skills/skills.mjs.map +1 -1
  766. package/resources/skills/versions.d.mts.map +1 -1
  767. package/resources/skills/versions.d.ts.map +1 -1
  768. package/resources/skills/versions.js +0 -1
  769. package/resources/skills/versions.js.map +1 -1
  770. package/resources/skills/versions.mjs +0 -1
  771. package/resources/skills/versions.mjs.map +1 -1
  772. package/resources/skills.d.mts.map +1 -1
  773. package/resources/skills.d.ts.map +1 -1
  774. package/resources/skills.js +0 -1
  775. package/resources/skills.js.map +1 -1
  776. package/resources/skills.mjs +0 -1
  777. package/resources/skills.mjs.map +1 -1
  778. package/resources/top-level.js +0 -1
  779. package/resources/top-level.js.map +1 -1
  780. package/resources/top-level.mjs +0 -1
  781. package/resources/top-level.mjs.map +1 -1
  782. package/src/client.ts +19 -21
  783. package/src/core/api-promise.ts +0 -2
  784. package/src/core/error.ts +0 -2
  785. package/src/core/pagination.ts +0 -2
  786. package/src/core/resource.ts +0 -2
  787. package/src/index.ts +0 -2
  788. package/src/internal/builtin-types.ts +0 -2
  789. package/src/internal/detect-platform.ts +0 -2
  790. package/src/internal/errors.ts +0 -2
  791. package/src/internal/headers.ts +0 -2
  792. package/src/internal/node.browser.ts +7 -7
  793. package/src/internal/parse.ts +0 -2
  794. package/src/internal/request-options.ts +1 -3
  795. package/src/internal/shim-types.ts +0 -2
  796. package/src/internal/shims.ts +0 -2
  797. package/src/internal/types.ts +0 -2
  798. package/src/internal/utils/base64.ts +0 -2
  799. package/src/internal/utils/bytes.ts +1 -1
  800. package/src/internal/utils/env.ts +0 -2
  801. package/src/internal/utils/log.ts +0 -2
  802. package/src/internal/utils/query.ts +0 -2
  803. package/src/internal/utils/uuid.ts +0 -2
  804. package/src/internal/utils/values.ts +0 -2
  805. package/src/internal/utils.ts +0 -2
  806. package/src/lib/.keep +0 -2
  807. package/src/lib/environments/worker.ts +29 -15
  808. package/src/resources/beta/agents/agents.ts +110 -24
  809. package/src/resources/beta/agents/index.ts +1 -2
  810. package/src/resources/beta/agents/versions.ts +0 -2
  811. package/src/resources/beta/agents.ts +0 -2
  812. package/src/resources/beta/beta.ts +31 -3
  813. package/src/resources/beta/deployment-runs.ts +0 -2
  814. package/src/resources/beta/deployments.ts +0 -2
  815. package/src/resources/beta/dreams.ts +2 -30
  816. package/src/resources/beta/environments/environments.ts +2 -4
  817. package/src/resources/beta/environments/index.ts +0 -2
  818. package/src/resources/beta/environments/work.ts +0 -2
  819. package/src/resources/beta/environments.ts +0 -2
  820. package/src/resources/beta/files.ts +0 -2
  821. package/src/resources/beta/index.ts +14 -2
  822. package/src/resources/beta/memory-stores/index.ts +0 -2
  823. package/src/resources/beta/memory-stores/memories.ts +0 -2
  824. package/src/resources/beta/memory-stores/memory-stores.ts +0 -2
  825. package/src/resources/beta/memory-stores/memory-versions.ts +0 -2
  826. package/src/resources/beta/memory-stores.ts +0 -2
  827. package/src/resources/beta/messages/batches.ts +13 -3
  828. package/src/resources/beta/messages/index.ts +10 -2
  829. package/src/resources/beta/messages/messages.ts +290 -102
  830. package/src/resources/beta/messages.ts +0 -2
  831. package/src/resources/beta/models.ts +25 -2
  832. package/src/resources/beta/organization/api-keys.ts +0 -2
  833. package/src/resources/beta/organization/compliance-settings.ts +0 -2
  834. package/src/resources/beta/organization/external-keys.ts +0 -2
  835. package/src/resources/beta/organization/federation/federation.ts +0 -2
  836. package/src/resources/beta/organization/federation/index.ts +0 -2
  837. package/src/resources/beta/organization/federation/issuers.ts +0 -2
  838. package/src/resources/beta/organization/federation/rules/index.ts +0 -2
  839. package/src/resources/beta/organization/federation/rules/rules.ts +0 -2
  840. package/src/resources/beta/organization/federation/rules/workspaces.ts +0 -2
  841. package/src/resources/beta/organization/federation/rules.ts +0 -2
  842. package/src/resources/beta/organization/federation.ts +0 -2
  843. package/src/resources/beta/organization/index.ts +0 -2
  844. package/src/resources/beta/organization/invites.ts +0 -2
  845. package/src/resources/beta/organization/organization.ts +0 -2
  846. package/src/resources/beta/organization/rate-limits.ts +0 -2
  847. package/src/resources/beta/organization/service-accounts/index.ts +0 -2
  848. package/src/resources/beta/organization/service-accounts/service-accounts.ts +0 -2
  849. package/src/resources/beta/organization/service-accounts/workspaces.ts +0 -2
  850. package/src/resources/beta/organization/service-accounts.ts +0 -2
  851. package/src/resources/beta/organization/users.ts +0 -2
  852. package/src/resources/beta/organization/workspaces/index.ts +0 -2
  853. package/src/resources/beta/organization/workspaces/members.ts +0 -2
  854. package/src/resources/beta/organization/workspaces/rate-limits.ts +0 -2
  855. package/src/resources/beta/organization/workspaces/service-accounts.ts +0 -2
  856. package/src/resources/beta/organization/workspaces/workspaces.ts +3 -5
  857. package/src/resources/beta/organization/workspaces.ts +0 -2
  858. package/src/resources/beta/organization.ts +0 -2
  859. package/src/resources/beta/sessions/events.ts +121 -23
  860. package/src/resources/beta/sessions/index.ts +8 -2
  861. package/src/resources/beta/sessions/resources.ts +0 -5
  862. package/src/resources/beta/sessions/sessions.ts +24 -9
  863. package/src/resources/beta/sessions/threads/events.ts +0 -2
  864. package/src/resources/beta/sessions/threads/index.ts +0 -2
  865. package/src/resources/beta/sessions/threads/threads.ts +0 -2
  866. package/src/resources/beta/sessions/threads.ts +0 -2
  867. package/src/resources/beta/sessions.ts +0 -2
  868. package/src/resources/beta/skills/index.ts +0 -2
  869. package/src/resources/beta/skills/skills.ts +0 -2
  870. package/src/resources/beta/skills/versions.ts +0 -2
  871. package/src/resources/beta/skills.ts +0 -2
  872. package/src/resources/beta/tunnels/certificates.ts +0 -2
  873. package/src/resources/beta/tunnels/index.ts +0 -2
  874. package/src/resources/beta/tunnels/tunnels.ts +0 -2
  875. package/src/resources/beta/tunnels.ts +0 -2
  876. package/src/resources/beta/user-profiles.ts +208 -15
  877. package/src/resources/beta/vaults/credentials.ts +0 -16
  878. package/src/resources/beta/vaults/index.ts +0 -2
  879. package/src/resources/beta/vaults/vaults.ts +0 -2
  880. package/src/resources/beta/vaults.ts +0 -2
  881. package/src/resources/beta/webhooks.ts +0 -2
  882. package/src/resources/beta.ts +0 -2
  883. package/src/resources/completions.ts +1 -3
  884. package/src/resources/files.ts +0 -2
  885. package/src/resources/index.ts +6 -2
  886. package/src/resources/messages/batches.ts +0 -2
  887. package/src/resources/messages/index.ts +6 -2
  888. package/src/resources/messages/messages.ts +130 -65
  889. package/src/resources/messages.ts +0 -2
  890. package/src/resources/models.ts +0 -2
  891. package/src/resources/shared.ts +0 -2
  892. package/src/resources/skills/index.ts +0 -2
  893. package/src/resources/skills/skills.ts +0 -2
  894. package/src/resources/skills/versions.ts +0 -2
  895. package/src/resources/skills.ts +0 -2
  896. package/src/tsconfig.json +13 -3
  897. package/src/version.ts +1 -1
  898. package/tools/agent-toolset/fs-util.js +0 -6
  899. package/tools/agent-toolset/fs-util.js.map +1 -1
  900. package/tools/agent-toolset/fs-util.mjs +0 -6
  901. package/tools/agent-toolset/fs-util.mjs.map +1 -1
  902. package/tools/agent-toolset/memories.js +4 -4
  903. package/tools/agent-toolset/memories.js.map +1 -1
  904. package/tools/agent-toolset/memories.mjs +2 -2
  905. package/tools/agent-toolset/memories.mjs.map +1 -1
  906. package/tools/agent-toolset/node.browser.js +12 -12
  907. package/tools/agent-toolset/node.browser.js.map +1 -1
  908. package/tools/agent-toolset/node.js +142 -139
  909. package/tools/agent-toolset/node.js.map +1 -1
  910. package/tools/agent-toolset/node.mjs +132 -125
  911. package/tools/agent-toolset/node.mjs.map +1 -1
  912. package/tools/agent-toolset/skills.js +5 -5
  913. package/tools/agent-toolset/skills.js.map +1 -1
  914. package/tools/agent-toolset/sync-interval.js +3 -3
  915. package/tools/agent-toolset/sync-interval.js.map +1 -1
  916. package/tools/memory/node.browser.js +2 -2
  917. package/tools/memory/node.browser.js.map +1 -1
  918. package/version.d.mts +1 -1
  919. package/version.d.ts +1 -1
  920. package/version.js +1 -1
  921. package/version.mjs +1 -1
package/client.mjs CHANGED
@@ -1,7 +1,5 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
1
  var _BaseAnthropic_instances, _a, _BaseAnthropic_encoder, _BaseAnthropic_baseURLOverridden;
3
2
  import { __classPrivateFieldGet, __classPrivateFieldSet } from "./internal/tslib.mjs";
4
- import { uuid4 } from "./internal/utils/uuid.mjs";
5
3
  import { validatePositiveInteger, isAbsoluteURL, safeJSON } from "./internal/utils/values.mjs";
6
4
  import { sleep } from "./internal/utils/sleep.mjs";
7
5
  import { castToError, isAbortError } from "./internal/errors.mjs";
@@ -36,900 +34,903 @@ export const AI_PROMPT = '\\n\\nAssistant:';
36
34
  /**
37
35
  * Base class for Anthropic API clients.
38
36
  */
39
- export class BaseAnthropic {
37
+ export var BaseAnthropic = /* @__PURE__ */ (() => {
40
38
  /**
41
- * The active credential provider. Default credential resolution runs once
42
- * at construction time. If it fails, the error is surfaced on every
43
- * request and the client must be reconstructed — there is no retry path.
44
- *
45
- * Clones returned by {@link withOptions} share the parent's auth state
46
- * (provider, token cache, pending resolution, and any resolution error)
47
- * unless the caller passes an explicit `apiKey`, `authToken`,
48
- * `credentials`, `config`, or `profile` override.
39
+ * Base class for Anthropic API clients.
49
40
  */
50
- get credentials() {
51
- return this._authState.provider;
52
- }
53
- /**
54
- * API Client for interfacing with the Anthropic API.
55
- *
56
- * @param {string | null | undefined} [opts.apiKey=process.env['ANTHROPIC_API_KEY'] ?? null]
57
- * @param {string | null | undefined} [opts.authToken=process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
58
- * @param {string | null | undefined} [opts.webhookKey=process.env['ANTHROPIC_WEBHOOK_SIGNING_KEY'] ?? null]
59
- * @param {string} [opts.baseURL=process.env['ANTHROPIC_BASE_URL'] ?? https://api.anthropic.com] - Override the default base URL for the API.
60
- * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
61
- * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
62
- * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
63
- * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
64
- * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
65
- * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
66
- * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
67
- */
68
- constructor({ baseURL = readEnv('ANTHROPIC_BASE_URL'), apiKey, authToken, webhookKey = readEnv('ANTHROPIC_WEBHOOK_SIGNING_KEY') ?? null, ...opts } = {}) {
69
- _BaseAnthropic_instances.add(this);
70
- this._requestAuthFlags = new WeakMap();
71
- _BaseAnthropic_encoder.set(this, void 0);
72
- // An explicit `profile` is a constructor-level credential choice; when set,
73
- // do not let env ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN shadow it.
74
- if (apiKey === undefined) {
75
- apiKey = opts.profile != null ? null : readEnv('ANTHROPIC_API_KEY') ?? null;
76
- }
77
- if (authToken === undefined) {
78
- authToken = opts.profile != null ? null : readEnv('ANTHROPIC_AUTH_TOKEN') ?? null;
79
- }
80
- if (opts.profile != null && (opts.credentials != null || opts.config != null)) {
81
- throw new TypeError('Pass at most one of `profile`, `credentials`, or `config`.');
82
- }
83
- const options = {
84
- apiKey,
85
- authToken,
86
- webhookKey,
87
- ...opts,
88
- baseURL: baseURL || `https://api.anthropic.com`,
89
- };
90
- if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {
91
- throw new Errors.AnthropicError("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");
92
- }
93
- this.baseURL = options.baseURL;
94
- // After destructuring, `baseURL` is the constructor arg or
95
- // ANTHROPIC_BASE_URL — both count as an explicit choice that a profile
96
- // base_url must not override. A falsy value means we fell through to the
97
- // hardcoded default above and a profile may supply the host. withOptions()
98
- // propagates the parent's flag via __baseURLIsExplicit so a non-overriding
99
- // clone doesn't mistake the inherited baseURL for a caller-supplied one.
100
- this._baseURLIsExplicit = opts.__baseURLIsExplicit ?? !!baseURL;
101
- this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT /* 10 minutes */;
102
- this.logger = options.logger ?? console;
103
- // Set default logLevel early so that we can log a warning in parseLogLevel.
104
- this.logLevel = defaultLogLevel;
105
- this.logLevel =
106
- parseLogLevel(options.logLevel, 'ClientOptions.logLevel', loggerFor(this)) ??
107
- parseLogLevel(readEnv('ANTHROPIC_LOG'), "process.env['ANTHROPIC_LOG']", loggerFor(this)) ??
108
- defaultLogLevel;
109
- this.fetchOptions = options.fetchOptions;
110
- this.maxRetries = options.maxRetries ?? 2;
111
- this.fetch = options.fetch ?? Shims.getDefaultFetch();
112
- __classPrivateFieldSet(this, _BaseAnthropic_encoder, Opts.FallbackEncoder, "f");
113
- this.middleware = [...(options.middleware ?? [])];
114
- const customHeadersEnv = readEnv('ANTHROPIC_CUSTOM_HEADERS');
115
- if (customHeadersEnv) {
116
- const parsed = {};
117
- for (const line of customHeadersEnv.split('\n')) {
118
- const colon = line.indexOf(':');
119
- if (colon >= 0) {
120
- parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
41
+ class BaseAnthropic {
42
+ /**
43
+ * The active credential provider. Default credential resolution runs once
44
+ * at construction time. If it fails, the error is surfaced on every
45
+ * request and the client must be reconstructed — there is no retry path.
46
+ *
47
+ * Clones returned by {@link withOptions} share the parent's auth state
48
+ * (provider, token cache, pending resolution, and any resolution error)
49
+ * unless the caller passes an explicit `apiKey`, `authToken`,
50
+ * `credentials`, `config`, or `profile` override.
51
+ */
52
+ get credentials() {
53
+ return this._authState.provider;
54
+ }
55
+ /**
56
+ * API Client for interfacing with the Anthropic API.
57
+ *
58
+ * @param {string | null | undefined} [opts.apiKey=process.env['ANTHROPIC_API_KEY'] ?? null]
59
+ * @param {string | null | undefined} [opts.authToken=process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
60
+ * @param {string | null | undefined} [opts.webhookKey=process.env['ANTHROPIC_WEBHOOK_SIGNING_KEY'] ?? null]
61
+ * @param {string} [opts.baseURL=process.env['ANTHROPIC_BASE_URL'] ?? https://api.anthropic.com] - Override the default base URL for the API.
62
+ * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
63
+ * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
64
+ * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
65
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
66
+ * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
67
+ * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
68
+ * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
69
+ */
70
+ constructor({ baseURL = readEnv('ANTHROPIC_BASE_URL'), apiKey, authToken, webhookKey = readEnv('ANTHROPIC_WEBHOOK_SIGNING_KEY') ?? null, ...opts } = {}) {
71
+ _BaseAnthropic_instances.add(this);
72
+ this._requestAuthFlags = new WeakMap();
73
+ _BaseAnthropic_encoder.set(this, void 0);
74
+ // An explicit `profile` is a constructor-level credential choice; when set,
75
+ // do not let env ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN shadow it.
76
+ if (apiKey === undefined) {
77
+ apiKey = opts.profile != null ? null : readEnv('ANTHROPIC_API_KEY') ?? null;
78
+ }
79
+ if (authToken === undefined) {
80
+ authToken = opts.profile != null ? null : readEnv('ANTHROPIC_AUTH_TOKEN') ?? null;
81
+ }
82
+ if (opts.profile != null && (opts.credentials != null || opts.config != null)) {
83
+ throw new TypeError('Pass at most one of `profile`, `credentials`, or `config`.');
84
+ }
85
+ const options = {
86
+ apiKey,
87
+ authToken,
88
+ webhookKey,
89
+ ...opts,
90
+ baseURL: baseURL || `https://api.anthropic.com`,
91
+ };
92
+ if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {
93
+ throw new Errors.AnthropicError("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");
94
+ }
95
+ this.baseURL = options.baseURL;
96
+ // After destructuring, `baseURL` is the constructor arg or
97
+ // ANTHROPIC_BASE_URL both count as an explicit choice that a profile
98
+ // base_url must not override. A falsy value means we fell through to the
99
+ // hardcoded default above and a profile may supply the host. withOptions()
100
+ // propagates the parent's flag via __baseURLIsExplicit so a non-overriding
101
+ // clone doesn't mistake the inherited baseURL for a caller-supplied one.
102
+ this._baseURLIsExplicit = opts.__baseURLIsExplicit ?? !!baseURL;
103
+ this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT /* 10 minutes */;
104
+ this.logger = options.logger ?? console;
105
+ // Set default logLevel early so that we can log a warning in parseLogLevel.
106
+ this.logLevel = defaultLogLevel;
107
+ this.logLevel =
108
+ parseLogLevel(options.logLevel, 'ClientOptions.logLevel', loggerFor(this)) ??
109
+ parseLogLevel(readEnv('ANTHROPIC_LOG'), "process.env['ANTHROPIC_LOG']", loggerFor(this)) ??
110
+ defaultLogLevel;
111
+ this.fetchOptions = options.fetchOptions;
112
+ this.maxRetries = validatePositiveInteger('maxRetries', options.maxRetries ?? 2);
113
+ this.fetch = options.fetch ?? Shims.getDefaultFetch();
114
+ __classPrivateFieldSet(this, _BaseAnthropic_encoder, Opts.FallbackEncoder, "f");
115
+ this.middleware = [...(options.middleware ?? [])];
116
+ const customHeadersEnv = readEnv('ANTHROPIC_CUSTOM_HEADERS');
117
+ if (customHeadersEnv) {
118
+ const parsed = {};
119
+ for (const line of customHeadersEnv.split('\n')) {
120
+ const colon = line.indexOf(':');
121
+ if (colon >= 0) {
122
+ parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
123
+ }
124
+ }
125
+ options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
126
+ }
127
+ const inherited = opts.__auth;
128
+ // Never persist the internal __auth handle on _options — it's a
129
+ // one-shot constructor signal, and leaking it through _options would
130
+ // cause withOptions() to spread a stale value into clones.
131
+ delete options.__auth;
132
+ delete options.__baseURLIsExplicit;
133
+ this._options = options;
134
+ this.apiKey = typeof apiKey === 'string' ? apiKey : null;
135
+ this.authToken = authToken;
136
+ this.webhookKey = webhookKey;
137
+ if (inherited) {
138
+ this._authState = inherited;
139
+ if (!this._baseURLIsExplicit && inherited.baseURL) {
140
+ this.baseURL = inherited.baseURL;
121
141
  }
122
142
  }
123
- options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
124
- }
125
- const inherited = opts.__auth;
126
- // Never persist the internal __auth handle on _options it's a
127
- // one-shot constructor signal, and leaking it through _options would
128
- // cause withOptions() to spread a stale value into clones.
129
- delete options.__auth;
130
- delete options.__baseURLIsExplicit;
131
- this._options = options;
132
- this.apiKey = typeof apiKey === 'string' ? apiKey : null;
133
- this.authToken = authToken;
134
- this.webhookKey = webhookKey;
135
- if (inherited) {
136
- this._authState = inherited;
137
- if (!this._baseURLIsExplicit && inherited.baseURL) {
138
- this.baseURL = inherited.baseURL;
139
- }
140
- }
141
- else {
142
- this._authState = { provider: null, tokenCache: null, resolution: null, error: null, extraHeaders: {} };
143
- // apiKey/authToken win over credentials/config/profile; don't build a
144
- // token cache or resolve a config that the request path will then ignore.
145
- if (this.apiKey == null && this.authToken == null) {
146
- const credentials = options.credentials ?? null;
147
- if (credentials) {
148
- this._authState.provider = credentials;
149
- this._authState.tokenCache = this._makeTokenCache(credentials);
143
+ else {
144
+ this._authState = { provider: null, tokenCache: null, resolution: null, error: null, extraHeaders: {} };
145
+ // apiKey/authToken win over credentials/config/profile; don't build a
146
+ // token cache or resolve a config that the request path will then ignore.
147
+ if (this.apiKey == null && this.authToken == null) {
148
+ const credentials = options.credentials ?? null;
149
+ if (credentials) {
150
+ this._authState.provider = credentials;
151
+ this._authState.tokenCache = this._makeTokenCache(credentials);
152
+ }
153
+ else if (options.config != null) {
154
+ const result = resolveCredentialsFromConfig(options.config, this._credentialResolverOptions());
155
+ this._authState.provider = result.provider;
156
+ this._authState.tokenCache = this._makeTokenCache(result.provider);
157
+ this._authState.extraHeaders = result.extraHeaders;
158
+ this._applyCredentialBaseURL(result.baseURL);
159
+ }
160
+ else if (options.profile != null) {
161
+ this._authState.resolution = this._resolveDefaultCredentials(options.profile);
162
+ }
163
+ else if (this._shouldResolveDefaultCredentials()) {
164
+ // No explicit auth provided lazily resolve from the credential
165
+ // chain on first request. Errors are captured into _auth.error and
166
+ // surfaced on first use rather than as an unhandled rejection.
167
+ this._authState.resolution = this._resolveDefaultCredentials();
168
+ }
150
169
  }
151
- else if (options.config != null) {
152
- const result = resolveCredentialsFromConfig(options.config, this._credentialResolverOptions());
170
+ }
171
+ }
172
+ /**
173
+ * Whether to lazily resolve auth from the default credential chain when no
174
+ * explicit auth is configured. Called once from the constructor, so
175
+ * overrides must not depend on subclass instance state. Subclasses that
176
+ * bring their own auth scheme return false so unrelated local credentials
177
+ * are never resolved or allowed to supply a base URL.
178
+ */
179
+ _shouldResolveDefaultCredentials() {
180
+ return true;
181
+ }
182
+ /**
183
+ * Stores a profile/config-supplied base URL on the shared auth state and, if
184
+ * the caller did not pin `baseURL` via constructor option or env, adopts it
185
+ * as this client's outbound API host. Precedence: ctor opt > env > profile >
186
+ * hardcoded default.
187
+ */
188
+ _applyCredentialBaseURL(baseURL) {
189
+ if (!baseURL)
190
+ return;
191
+ const normalized = baseURL.replace(/\/+$/, '');
192
+ this._authState.baseURL = normalized;
193
+ if (!this._baseURLIsExplicit) {
194
+ this.baseURL = normalized;
195
+ }
196
+ }
197
+ /**
198
+ * Options bag passed into the credential chain. `baseURL` here is only the
199
+ * fallback host for the token-exchange POST when the config itself omits
200
+ * `base_url`; the chain returns the config's own `base_url` (if any) on
201
+ * {@link CredentialResult.baseURL}, which {@link _applyCredentialBaseURL}
202
+ * then adopts for outbound API requests. The two are deliberately decoupled
203
+ * so this fallback never round-trips into precedence.
204
+ */
205
+ _credentialResolverOptions() {
206
+ return {
207
+ baseURL: this.baseURL,
208
+ fetch: this._credentialsFetch(),
209
+ userAgent: this.getUserAgent(),
210
+ onCacheWriteError: (err) => {
211
+ loggerFor(this).debug('credential cache write failed (best-effort)', err);
212
+ },
213
+ onSafetyWarning: (msg) => {
214
+ loggerFor(this).warn(msg);
215
+ },
216
+ };
217
+ }
218
+ /**
219
+ * A `Fetch` for first-party credential token-exchange requests (OIDC
220
+ * federation jwt-bearer grants, user-OAuth refresh grants) that routes
221
+ * through this client's middleware chain, so middleware observes token
222
+ * traffic like any other request. Only client-level middleware applies:
223
+ * a minted token is shared across requests, so attributing the exchange
224
+ * to any one request's per-request middleware would be arbitrary. For the
225
+ * same reason, `ctx.options` is undefined for these requests.
226
+ */
227
+ _credentialsFetch() {
228
+ return wrapFetchWithMiddleware(this.fetch, this.middleware, undefined, this);
229
+ }
230
+ _makeTokenCache(provider) {
231
+ return new TokenCache(provider, (err) => {
232
+ loggerFor(this).debug('advisory token refresh failed; serving cached token', err);
233
+ });
234
+ }
235
+ /**
236
+ * Create a new client instance re-using the same options given to the
237
+ * current client with optional overriding.
238
+ */
239
+ withOptions(options) {
240
+ // Share the auth state object unless the caller passes any auth-related
241
+ // key. The `in` check is intentional: even `apiKey: undefined` opts the
242
+ // clone out of sharing (it gets its own _auth and TokenCache, though it
243
+ // may still wrap the parent's provider via the credentials spread below).
244
+ const overridesStructuredAuth = 'credentials' in options || 'config' in options || 'profile' in options;
245
+ const overridesAuth = 'apiKey' in options || 'authToken' in options || overridesStructuredAuth;
246
+ const internal = {
247
+ ...this._options,
248
+ // Only forward baseURL when the caller (or env) explicitly chose it.
249
+ // For a non-explicit parent, this.baseURL may have been mutated to the
250
+ // profile-resolved host; pinning that as the clone's options.baseURL
251
+ // would make _options on the clone misreport caller intent and would
252
+ // leave the clone stuck on the parent's host across an auth override.
253
+ // The clone instead receives the construction-time value via
254
+ // ...this._options above and re-adopts the profile host through the
255
+ // shared _authState.baseURL + __baseURLIsExplicit=false path.
256
+ ...(this._baseURLIsExplicit ? { baseURL: this.baseURL } : {}),
257
+ maxRetries: this.maxRetries,
258
+ timeout: this.timeout,
259
+ logger: this.logger,
260
+ logLevel: this.logLevel,
261
+ fetch: this.fetch,
262
+ fetchOptions: this.fetchOptions,
263
+ middleware: this.middleware,
264
+ apiKey: this.apiKey,
265
+ authToken: this.authToken,
266
+ webhookKey: this.webhookKey,
267
+ // credentials: this.credentials is a no-op when __auth is shared (the
268
+ // ctor takes the inherited path and ignores options.credentials); when
269
+ // overridesAuth is true via apiKey/authToken only, it lets the clone
270
+ // build a fresh TokenCache around the parent's provider.
271
+ credentials: this.credentials,
272
+ // When the caller passes a structured-credential override, drop inherited
273
+ // structured-credential options so only `...options` supplies them —
274
+ // otherwise an inherited `credentials`/`config`/`profile` would trip the
275
+ // mutual-exclusion check or precedence over the override.
276
+ ...(overridesStructuredAuth ? { credentials: undefined, config: undefined, profile: undefined } : {}),
277
+ ...options,
278
+ // Always set __auth so any stale value from ...this._options is
279
+ // overwritten. undefined means "build fresh auth from these options".
280
+ __auth: overridesAuth ? undefined : this._authState,
281
+ __baseURLIsExplicit: 'baseURL' in options ? true : this._baseURLIsExplicit,
282
+ };
283
+ return new this.constructor(internal);
284
+ }
285
+ /**
286
+ * Lazily resolves credentials from config files or environment variables.
287
+ * Called once from the constructor when no explicit auth is provided, or
288
+ * when an explicit `profile` was passed (in which case a missing/unresolved
289
+ * profile is surfaced as an error instead of falling through to "no auth").
290
+ * The returned promise is stored and awaited on the first request.
291
+ */
292
+ async _resolveDefaultCredentials(profile) {
293
+ try {
294
+ const result = await defaultCredentials(this._credentialResolverOptions(), profile);
295
+ if (result) {
153
296
  this._authState.provider = result.provider;
154
297
  this._authState.tokenCache = this._makeTokenCache(result.provider);
155
298
  this._authState.extraHeaders = result.extraHeaders;
156
299
  this._applyCredentialBaseURL(result.baseURL);
157
300
  }
158
- else if (options.profile != null) {
159
- this._authState.resolution = this._resolveDefaultCredentials(options.profile);
160
- }
161
- else if (this._shouldResolveDefaultCredentials()) {
162
- // No explicit auth provided — lazily resolve from the credential
163
- // chain on first request. Errors are captured into _auth.error and
164
- // surfaced on first use rather than as an unhandled rejection.
165
- this._authState.resolution = this._resolveDefaultCredentials();
301
+ else if (profile != null) {
302
+ throw new Errors.AnthropicError(`Profile "${profile}" could not be resolved (no <config_dir>/configs/${profile}.json found).`);
166
303
  }
167
304
  }
168
- }
169
- }
170
- /**
171
- * Whether to lazily resolve auth from the default credential chain when no
172
- * explicit auth is configured. Called once from the constructor, so
173
- * overrides must not depend on subclass instance state. Subclasses that
174
- * bring their own auth scheme return false so unrelated local credentials
175
- * are never resolved or allowed to supply a base URL.
176
- */
177
- _shouldResolveDefaultCredentials() {
178
- return true;
179
- }
180
- /**
181
- * Stores a profile/config-supplied base URL on the shared auth state and, if
182
- * the caller did not pin `baseURL` via constructor option or env, adopts it
183
- * as this client's outbound API host. Precedence: ctor opt > env > profile >
184
- * hardcoded default.
185
- */
186
- _applyCredentialBaseURL(baseURL) {
187
- if (!baseURL)
188
- return;
189
- const normalized = baseURL.replace(/\/+$/, '');
190
- this._authState.baseURL = normalized;
191
- if (!this._baseURLIsExplicit) {
192
- this.baseURL = normalized;
193
- }
194
- }
195
- /**
196
- * Options bag passed into the credential chain. `baseURL` here is only the
197
- * fallback host for the token-exchange POST when the config itself omits
198
- * `base_url`; the chain returns the config's own `base_url` (if any) on
199
- * {@link CredentialResult.baseURL}, which {@link _applyCredentialBaseURL}
200
- * then adopts for outbound API requests. The two are deliberately decoupled
201
- * so this fallback never round-trips into precedence.
202
- */
203
- _credentialResolverOptions() {
204
- return {
205
- baseURL: this.baseURL,
206
- fetch: this._credentialsFetch(),
207
- userAgent: this.getUserAgent(),
208
- onCacheWriteError: (err) => {
209
- loggerFor(this).debug('credential cache write failed (best-effort)', err);
210
- },
211
- onSafetyWarning: (msg) => {
212
- loggerFor(this).warn(msg);
213
- },
214
- };
215
- }
216
- /**
217
- * A `Fetch` for first-party credential token-exchange requests (OIDC
218
- * federation jwt-bearer grants, user-OAuth refresh grants) that routes
219
- * through this client's middleware chain, so middleware observes token
220
- * traffic like any other request. Only client-level middleware applies:
221
- * a minted token is shared across requests, so attributing the exchange
222
- * to any one request's per-request middleware would be arbitrary. For the
223
- * same reason, `ctx.options` is undefined for these requests.
224
- */
225
- _credentialsFetch() {
226
- return wrapFetchWithMiddleware(this.fetch, this.middleware, undefined, this);
227
- }
228
- _makeTokenCache(provider) {
229
- return new TokenCache(provider, (err) => {
230
- loggerFor(this).debug('advisory token refresh failed; serving cached token', err);
231
- });
232
- }
233
- /**
234
- * Create a new client instance re-using the same options given to the
235
- * current client with optional overriding.
236
- */
237
- withOptions(options) {
238
- // Share the auth state object unless the caller passes any auth-related
239
- // key. The `in` check is intentional: even `apiKey: undefined` opts the
240
- // clone out of sharing (it gets its own _auth and TokenCache, though it
241
- // may still wrap the parent's provider via the credentials spread below).
242
- const overridesStructuredAuth = 'credentials' in options || 'config' in options || 'profile' in options;
243
- const overridesAuth = 'apiKey' in options || 'authToken' in options || overridesStructuredAuth;
244
- const internal = {
245
- ...this._options,
246
- // Only forward baseURL when the caller (or env) explicitly chose it.
247
- // For a non-explicit parent, this.baseURL may have been mutated to the
248
- // profile-resolved host; pinning that as the clone's options.baseURL
249
- // would make _options on the clone misreport caller intent and would
250
- // leave the clone stuck on the parent's host across an auth override.
251
- // The clone instead receives the construction-time value via
252
- // ...this._options above and re-adopts the profile host through the
253
- // shared _authState.baseURL + __baseURLIsExplicit=false path.
254
- ...(this._baseURLIsExplicit ? { baseURL: this.baseURL } : {}),
255
- maxRetries: this.maxRetries,
256
- timeout: this.timeout,
257
- logger: this.logger,
258
- logLevel: this.logLevel,
259
- fetch: this.fetch,
260
- fetchOptions: this.fetchOptions,
261
- middleware: this.middleware,
262
- apiKey: this.apiKey,
263
- authToken: this.authToken,
264
- webhookKey: this.webhookKey,
265
- // credentials: this.credentials is a no-op when __auth is shared (the
266
- // ctor takes the inherited path and ignores options.credentials); when
267
- // overridesAuth is true via apiKey/authToken only, it lets the clone
268
- // build a fresh TokenCache around the parent's provider.
269
- credentials: this.credentials,
270
- // When the caller passes a structured-credential override, drop inherited
271
- // structured-credential options so only `...options` supplies them —
272
- // otherwise an inherited `credentials`/`config`/`profile` would trip the
273
- // mutual-exclusion check or precedence over the override.
274
- ...(overridesStructuredAuth ? { credentials: undefined, config: undefined, profile: undefined } : {}),
275
- ...options,
276
- // Always set __auth so any stale value from ...this._options is
277
- // overwritten. undefined means "build fresh auth from these options".
278
- __auth: overridesAuth ? undefined : this._authState,
279
- __baseURLIsExplicit: 'baseURL' in options ? true : this._baseURLIsExplicit,
280
- };
281
- return new this.constructor(internal);
282
- }
283
- /**
284
- * Lazily resolves credentials from config files or environment variables.
285
- * Called once from the constructor when no explicit auth is provided, or
286
- * when an explicit `profile` was passed (in which case a missing/unresolved
287
- * profile is surfaced as an error instead of falling through to "no auth").
288
- * The returned promise is stored and awaited on the first request.
289
- */
290
- async _resolveDefaultCredentials(profile) {
291
- try {
292
- const result = await defaultCredentials(this._credentialResolverOptions(), profile);
293
- if (result) {
294
- this._authState.provider = result.provider;
295
- this._authState.tokenCache = this._makeTokenCache(result.provider);
296
- this._authState.extraHeaders = result.extraHeaders;
297
- this._applyCredentialBaseURL(result.baseURL);
305
+ catch (err) {
306
+ this._authState.error = err;
298
307
  }
299
- else if (profile != null) {
300
- throw new Errors.AnthropicError(`Profile "${profile}" could not be resolved (no <config_dir>/configs/${profile}.json found).`);
308
+ finally {
309
+ this._authState.resolution = null;
301
310
  }
302
311
  }
303
- catch (err) {
304
- this._authState.error = err;
305
- }
306
- finally {
307
- this._authState.resolution = null;
308
- }
309
- }
310
- defaultQuery() {
311
- return this._options.defaultQuery;
312
- }
313
- validateHeaders({ values, nulls }) {
314
- if (values.get('x-api-key') || values.get('authorization')) {
315
- return;
316
- }
317
- if (this._authState.error) {
318
- throw this._authState.error;
319
- }
320
- if (this._authState.tokenCache || this._authState.resolution) {
321
- return; // auth will be injected per-request via authHeaders
322
- }
323
- if (this.apiKey && values.get('x-api-key')) {
324
- return;
325
- }
326
- if (nulls.has('x-api-key')) {
327
- return;
328
- }
329
- if (this.authToken && values.get('authorization')) {
330
- return;
312
+ defaultQuery() {
313
+ return this._options.defaultQuery;
331
314
  }
332
- if (nulls.has('authorization')) {
333
- return;
315
+ validateHeaders({ values, nulls }) {
316
+ if (values.get('x-api-key') || values.get('authorization')) {
317
+ return;
318
+ }
319
+ if (this._authState.error) {
320
+ throw this._authState.error;
321
+ }
322
+ if (this._authState.tokenCache || this._authState.resolution) {
323
+ return; // auth will be injected per-request via authHeaders
324
+ }
325
+ if (this.apiKey && values.get('x-api-key')) {
326
+ return;
327
+ }
328
+ if (nulls.has('x-api-key')) {
329
+ return;
330
+ }
331
+ if (this.authToken && values.get('authorization')) {
332
+ return;
333
+ }
334
+ if (nulls.has('authorization')) {
335
+ return;
336
+ }
337
+ throw new Error('Could not resolve authentication method. Expected one of apiKey, authToken, credentials, config, or profile to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
334
338
  }
335
- throw new Error('Could not resolve authentication method. Expected one of apiKey, authToken, credentials, config, or profile to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
336
- }
337
- _authFlags(opts) {
338
- let flags = this._requestAuthFlags.get(opts);
339
- if (!flags) {
340
- flags = { usedTokenCache: false, didRefreshFor401: false };
341
- this._requestAuthFlags.set(opts, flags);
339
+ _authFlags(opts) {
340
+ let flags = this._requestAuthFlags.get(opts);
341
+ if (!flags) {
342
+ flags = { usedTokenCache: false, didRefreshFor401: false };
343
+ this._requestAuthFlags.set(opts, flags);
344
+ }
345
+ return flags;
346
+ }
347
+ async authHeaders(opts) {
348
+ // Wait for lazy credential resolution if it's in progress. If it failed,
349
+ // return no auth headers — validateHeaders surfaces the stored error
350
+ // after the explicit-header escape hatch has had a chance to apply.
351
+ if (this._authState.resolution) {
352
+ await this._authState.resolution;
353
+ }
354
+ if (this._authState.error) {
355
+ return undefined;
356
+ }
357
+ // If we have a token cache and no API key is set, use token auth
358
+ if (this._authState.tokenCache && this.apiKey == null) {
359
+ const token = await this._authState.tokenCache.getToken();
360
+ this._authFlags(opts).usedTokenCache = true;
361
+ return buildHeaders([{ Authorization: `Bearer ${token}` }]);
362
+ }
363
+ return buildHeaders([await this.apiKeyAuth(opts), await this.bearerAuth(opts)]);
342
364
  }
343
- return flags;
344
- }
345
- async authHeaders(opts) {
346
- // Wait for lazy credential resolution if it's in progress. If it failed,
347
- // return no auth headers — validateHeaders surfaces the stored error
348
- // after the explicit-header escape hatch has had a chance to apply.
349
- if (this._authState.resolution) {
350
- await this._authState.resolution;
351
- }
352
- if (this._authState.error) {
353
- return undefined;
354
- }
355
- // If we have a token cache and no API key is set, use token auth
356
- if (this._authState.tokenCache && this.apiKey == null) {
357
- const token = await this._authState.tokenCache.getToken();
358
- this._authFlags(opts).usedTokenCache = true;
359
- return buildHeaders([{ Authorization: `Bearer ${token}` }]);
360
- }
361
- return buildHeaders([await this.apiKeyAuth(opts), await this.bearerAuth(opts)]);
362
- }
363
- async apiKeyAuth(opts) {
364
- if (this.apiKey == null) {
365
- return undefined;
365
+ async apiKeyAuth(opts) {
366
+ if (this.apiKey == null) {
367
+ return undefined;
368
+ }
369
+ return buildHeaders([{ 'X-Api-Key': this.apiKey }]);
366
370
  }
367
- return buildHeaders([{ 'X-Api-Key': this.apiKey }]);
368
- }
369
- async bearerAuth(opts) {
370
- if (this.authToken == null) {
371
- return undefined;
371
+ async bearerAuth(opts) {
372
+ if (this.authToken == null) {
373
+ return undefined;
374
+ }
375
+ return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
376
+ }
377
+ stringifyQuery(query) {
378
+ return stringifyQuery(query);
379
+ }
380
+ getUserAgent() {
381
+ return `Anthropic/JS ${VERSION}`;
382
+ }
383
+ makeStatusError(status, error, message, headers) {
384
+ return Errors.APIError.generate(status, error, message, headers);
385
+ }
386
+ buildURL(path, query, defaultBaseURL) {
387
+ const baseURL = (!__classPrivateFieldGet(this, _BaseAnthropic_instances, "m", _BaseAnthropic_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
388
+ const url = isAbsoluteURL(path) ?
389
+ new URL(path)
390
+ : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
391
+ const defaultQuery = this.defaultQuery();
392
+ const pathQuery = Object.fromEntries(url.searchParams);
393
+ if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
394
+ query = { ...pathQuery, ...defaultQuery, ...query };
395
+ }
396
+ if (typeof query === 'object' && query && !Array.isArray(query)) {
397
+ url.search = this.stringifyQuery(query);
398
+ }
399
+ return url.toString();
400
+ }
401
+ _calculateNonstreamingTimeout(maxTokens) {
402
+ const defaultTimeout = 10 * 60;
403
+ const expectedTimeout = (60 * 60 * maxTokens) / 128000;
404
+ if (expectedTimeout > defaultTimeout) {
405
+ throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. ' +
406
+ 'See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details');
407
+ }
408
+ return defaultTimeout * 1000;
409
+ }
410
+ /**
411
+ * Used as a callback for mutating the given `FinalRequestOptions` object.
412
+ */
413
+ async prepareOptions(options) { }
414
+ /**
415
+ * Used as a callback for mutating the given `RequestInit` object.
416
+ *
417
+ * This is useful for cases where you want to add certain headers based off of
418
+ * the request properties, e.g. `method` or `url`.
419
+ *
420
+ * Runs after all middleware (including {@link backendMiddleware}),
421
+ * immediately before each underlying fetch call, so it sees exactly what
422
+ * goes over the wire. Middleware may replay a request by calling `next()`
423
+ * more than once, so this hook can run multiple times per attempt:
424
+ * overrides must be idempotent and overwrite headers from a previous
425
+ * invocation rather than append to them.
426
+ */
427
+ async prepareRequest(request, { url, options }) {
428
+ // Append auth-derived headers when using token auth. Done here (after all
429
+ // header merging) rather than in authHeaders() so we append to any existing
430
+ // anthropic-beta values instead of being overwritten by later header sources.
431
+ if (this._authState.tokenCache && this.apiKey == null) {
432
+ // Normalize to a Headers instance — custom fetch impls or polyfills can
433
+ // hand back arrays / plain objects, and silently dropping the beta
434
+ // header in that case would surface as a confusing server-side 4xx.
435
+ const headers = request.headers instanceof Headers ? request.headers : new Headers(request.headers);
436
+ for (const [k, v] of Object.entries(this._authState.extraHeaders)) {
437
+ if (!headers.has(k))
438
+ headers.set(k, v);
439
+ }
440
+ const existing = headers
441
+ .get('anthropic-beta')
442
+ ?.split(',')
443
+ .map((s) => s.trim());
444
+ if (!existing?.includes(OAUTH_API_BETA_HEADER)) {
445
+ headers.append('anthropic-beta', OAUTH_API_BETA_HEADER);
446
+ }
447
+ request.headers = headers;
448
+ }
372
449
  }
373
- return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
374
- }
375
- stringifyQuery(query) {
376
- return stringifyQuery(query);
377
- }
378
- getUserAgent() {
379
- return `Anthropic/JS ${VERSION}`;
380
- }
381
- defaultIdempotencyKey() {
382
- return `stainless-node-retry-${uuid4()}`;
383
- }
384
- makeStatusError(status, error, message, headers) {
385
- return Errors.APIError.generate(status, error, message, headers);
386
- }
387
- buildURL(path, query, defaultBaseURL) {
388
- const baseURL = (!__classPrivateFieldGet(this, _BaseAnthropic_instances, "m", _BaseAnthropic_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
389
- const url = isAbsoluteURL(path) ?
390
- new URL(path)
391
- : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
392
- const defaultQuery = this.defaultQuery();
393
- const pathQuery = Object.fromEntries(url.searchParams);
394
- if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
395
- query = { ...pathQuery, ...defaultQuery, ...query };
396
- }
397
- if (typeof query === 'object' && query && !Array.isArray(query)) {
398
- url.search = this.stringifyQuery(query);
399
- }
400
- return url.toString();
401
- }
402
- _calculateNonstreamingTimeout(maxTokens) {
403
- const defaultTimeout = 10 * 60;
404
- const expectedTimeout = (60 * 60 * maxTokens) / 128000;
405
- if (expectedTimeout > defaultTimeout) {
406
- throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. ' +
407
- 'See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details');
408
- }
409
- return defaultTimeout * 1000;
410
- }
411
- /**
412
- * Used as a callback for mutating the given `FinalRequestOptions` object.
413
- */
414
- async prepareOptions(options) { }
415
- /**
416
- * Used as a callback for mutating the given `RequestInit` object.
417
- *
418
- * This is useful for cases where you want to add certain headers based off of
419
- * the request properties, e.g. `method` or `url`.
420
- *
421
- * Runs after all middleware (including {@link backendMiddleware}),
422
- * immediately before each underlying fetch call, so it sees exactly what
423
- * goes over the wire. Middleware may replay a request by calling `next()`
424
- * more than once, so this hook can run multiple times per attempt:
425
- * overrides must be idempotent and overwrite headers from a previous
426
- * invocation rather than append to them.
427
- */
428
- async prepareRequest(request, { url, options }) {
429
- // Append auth-derived headers when using token auth. Done here (after all
430
- // header merging) rather than in authHeaders() so we append to any existing
431
- // anthropic-beta values instead of being overwritten by later header sources.
432
- if (this._authState.tokenCache && this.apiKey == null) {
433
- // Normalize to a Headers instance — custom fetch impls or polyfills can
434
- // hand back arrays / plain objects, and silently dropping the beta
435
- // header in that case would surface as a confusing server-side 4xx.
436
- const headers = request.headers instanceof Headers ? request.headers : new Headers(request.headers);
437
- for (const [k, v] of Object.entries(this._authState.extraHeaders)) {
438
- if (!headers.has(k))
439
- headers.set(k, v);
440
- }
441
- const existing = headers
442
- .get('anthropic-beta')
443
- ?.split(',')
444
- .map((s) => s.trim());
445
- if (!existing?.includes(OAUTH_API_BETA_HEADER)) {
446
- headers.append('anthropic-beta', OAUTH_API_BETA_HEADER);
447
- }
448
- request.headers = headers;
450
+ /**
451
+ * Internal {@link Middleware} composed innermost in the chain — inside both
452
+ * client-level and per-request middleware, immediately around the underlying
453
+ * `fetch`. Subclasses for third-party backends override this to adapt the
454
+ * canonical Anthropic-shaped request to the backend's wire shape (URL/body
455
+ * rewriting, request signing) and to normalize the wire response back to the
456
+ * canonical shape (e.g. AWS EventStream to SSE).
457
+ *
458
+ * Running inside the user's middleware means user middleware always observes
459
+ * canonical Anthropic-shaped traffic, and the adaptation re-runs (e.g.
460
+ * re-signs) on every `next()` invocation, covering whatever the middleware
461
+ * mutated.
462
+ *
463
+ * Errors thrown here follow the middleware error policy: they propagate to
464
+ * the caller as-is — no retries, no `APIConnectionError` wrapping — unless
465
+ * retryable (see {@link Middleware}); throw a `RetryableError` to opt into
466
+ * the retry path.
467
+ */
468
+ backendMiddleware() {
469
+ return [];
470
+ }
471
+ get(path, opts) {
472
+ return this.methodRequest('get', path, opts);
473
+ }
474
+ post(path, opts) {
475
+ return this.methodRequest('post', path, opts);
476
+ }
477
+ patch(path, opts) {
478
+ return this.methodRequest('patch', path, opts);
479
+ }
480
+ put(path, opts) {
481
+ return this.methodRequest('put', path, opts);
482
+ }
483
+ delete(path, opts) {
484
+ return this.methodRequest('delete', path, opts);
485
+ }
486
+ methodRequest(method, path, opts) {
487
+ return this.request(Promise.resolve(opts).then((opts) => {
488
+ return { method, path, ...opts };
489
+ }));
449
490
  }
450
- }
451
- /**
452
- * Internal {@link Middleware} composed innermost in the chain — inside both
453
- * client-level and per-request middleware, immediately around the underlying
454
- * `fetch`. Subclasses for third-party backends override this to adapt the
455
- * canonical Anthropic-shaped request to the backend's wire shape (URL/body
456
- * rewriting, request signing) and to normalize the wire response back to the
457
- * canonical shape (e.g. AWS EventStream to SSE).
458
- *
459
- * Running inside the user's middleware means user middleware always observes
460
- * canonical Anthropic-shaped traffic, and the adaptation re-runs (e.g.
461
- * re-signs) on every `next()` invocation, covering whatever the middleware
462
- * mutated.
463
- *
464
- * Errors thrown here follow the middleware error policy: they propagate to
465
- * the caller as-is — no retries, no `APIConnectionError` wrapping — unless
466
- * retryable (see {@link Middleware}); throw a `RetryableError` to opt into
467
- * the retry path.
468
- */
469
- backendMiddleware() {
470
- return [];
471
- }
472
- get(path, opts) {
473
- return this.methodRequest('get', path, opts);
474
- }
475
- post(path, opts) {
476
- return this.methodRequest('post', path, opts);
477
- }
478
- patch(path, opts) {
479
- return this.methodRequest('patch', path, opts);
480
- }
481
- put(path, opts) {
482
- return this.methodRequest('put', path, opts);
483
- }
484
- delete(path, opts) {
485
- return this.methodRequest('delete', path, opts);
486
- }
487
- methodRequest(method, path, opts) {
488
- return this.request(Promise.resolve(opts).then((opts) => {
489
- return { method, path, ...opts };
490
- }));
491
- }
492
- request(options, remainingRetries = null) {
493
- return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
494
- }
495
- async makeRequest(optionsInput, retriesRemaining, retryOfRequestLogID) {
496
- const options = await optionsInput;
497
- const maxRetries = options.maxRetries ?? this.maxRetries;
498
- if (retriesRemaining == null) {
499
- retriesRemaining = maxRetries;
500
- // Top-level call: reset per-request auth flags so a reused options object
501
- // (via client.request(opts)) doesn't carry stale 401-refresh state.
502
- this._requestAuthFlags.delete(options);
503
- }
504
- await this.prepareOptions(options);
505
- const { req, url, timeout } = await this.buildRequest(options, {
506
- retryCount: maxRetries - retriesRemaining,
507
- });
508
- /** Not an API request ID, just for correlating local log entries. */
509
- const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
510
- const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
511
- const startTime = Date.now();
512
- if (options.signal?.aborted) {
513
- throw new Errors.APIUserAbortError();
514
- }
515
- const controller = new AbortController();
516
- const response = await this.fetchWithTimeout(url, req, timeout, controller, options, {
517
- requestLogID,
518
- retryOfRequestLogID,
519
- }).catch(castToError);
520
- const headersTime = Date.now();
521
- if (response instanceof globalThis.Error) {
522
- releaseRequestSignal(controller);
523
- const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
491
+ request(options, remainingRetries = null) {
492
+ return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
493
+ }
494
+ async makeRequest(optionsInput, retriesRemaining, retryOfRequestLogID) {
495
+ const options = await optionsInput;
496
+ const maxRetries = validatePositiveInteger('maxRetries', options.maxRetries ?? this.maxRetries);
497
+ if (retriesRemaining == null) {
498
+ retriesRemaining = maxRetries;
499
+ // Top-level call: reset per-request auth flags so a reused options object
500
+ // (via client.request(opts)) doesn't carry stale 401-refresh state.
501
+ this._requestAuthFlags.delete(options);
502
+ }
503
+ await this.prepareOptions(options);
504
+ const { req, url, timeout } = await this.buildRequest(options, {
505
+ retryCount: maxRetries - retriesRemaining,
506
+ });
507
+ /** Not an API request ID, just for correlating local log entries. */
508
+ const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
509
+ const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
510
+ const startTime = Date.now();
524
511
  if (options.signal?.aborted) {
525
512
  throw new Errors.APIUserAbortError();
526
513
  }
527
- // detect native connection timeout errors
528
- // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
529
- // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
530
- // others do not provide enough information to distinguish timeouts from other connection errors
531
- const isTimeout = isAbortError(response) ||
532
- /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
533
- // Errors thrown by middleware (user middleware and the backend adaptation
534
- // alike) propagate to the caller as-is — no retries, no APIConnectionError
535
- // wrapping except retryable errors (timeouts/aborts, APIConnectionErrors,
536
- // and RetryableErrors, directly or in the `cause` chain), which stay on the
537
- // retry path.
538
- const hasMiddleware = this.middleware.length > 0 || !!options.middleware?.length || this.backendMiddleware().length > 0;
539
- if (hasMiddleware && !isTimeout && !isRetryableError(response)) {
540
- loggerFor(this).info(`[${requestLogID}] middleware error (not retryable)`);
541
- loggerFor(this).debug(`[${requestLogID}] middleware error (not retryable)`, formatRequestDetails({
542
- retryOfRequestLogID,
543
- url,
544
- durationMs: headersTime - startTime,
545
- message: response.message,
546
- }));
547
- throw response;
548
- }
549
- if (retriesRemaining) {
550
- loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`);
551
- loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`, formatRequestDetails({
514
+ const controller = new AbortController();
515
+ const response = await this.fetchWithTimeout(url, req, timeout, controller, options, {
516
+ requestLogID,
517
+ retryOfRequestLogID,
518
+ }).catch(castToError);
519
+ const headersTime = Date.now();
520
+ if (response instanceof globalThis.Error) {
521
+ releaseRequestSignal(controller);
522
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
523
+ if (options.signal?.aborted) {
524
+ throw new Errors.APIUserAbortError();
525
+ }
526
+ // detect native connection timeout errors
527
+ // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
528
+ // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
529
+ // others do not provide enough information to distinguish timeouts from other connection errors
530
+ const isTimeout = isAbortError(response) ||
531
+ /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
532
+ // Errors thrown by middleware (user middleware and the backend adaptation
533
+ // alike) propagate to the caller as-is — no retries, no APIConnectionError
534
+ // wrapping — except retryable errors (timeouts/aborts, APIConnectionErrors,
535
+ // and RetryableErrors, directly or in the `cause` chain), which stay on the
536
+ // retry path.
537
+ const hasMiddleware = this.middleware.length > 0 || !!options.middleware?.length || this.backendMiddleware().length > 0;
538
+ if (hasMiddleware && !isTimeout && !isRetryableError(response)) {
539
+ loggerFor(this).info(`[${requestLogID}] middleware error (not retryable)`);
540
+ loggerFor(this).debug(`[${requestLogID}] middleware error (not retryable)`, formatRequestDetails({
541
+ retryOfRequestLogID,
542
+ url,
543
+ durationMs: headersTime - startTime,
544
+ message: response.message,
545
+ }));
546
+ throw response;
547
+ }
548
+ if (retriesRemaining) {
549
+ loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`);
550
+ loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`, formatRequestDetails({
551
+ retryOfRequestLogID,
552
+ url,
553
+ durationMs: headersTime - startTime,
554
+ message: response.message,
555
+ }));
556
+ return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
557
+ }
558
+ loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`);
559
+ loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`, formatRequestDetails({
552
560
  retryOfRequestLogID,
553
561
  url,
554
562
  durationMs: headersTime - startTime,
555
563
  message: response.message,
556
564
  }));
557
- return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
565
+ if (isTimeout) {
566
+ throw new Errors.APIConnectionTimeoutError();
567
+ }
568
+ // a retryable middleware-origin error is still the caller's error: once retries are
569
+ // exhausted it propagates as-is rather than wrapped in APIConnectionError
570
+ if (hasMiddleware && !isFetchOriginError(response)) {
571
+ throw response;
572
+ }
573
+ throw new Errors.APIConnectionError({ cause: response });
558
574
  }
559
- loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`);
560
- loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`, formatRequestDetails({
561
- retryOfRequestLogID,
562
- url,
563
- durationMs: headersTime - startTime,
564
- message: response.message,
565
- }));
566
- if (isTimeout) {
567
- throw new Errors.APIConnectionTimeoutError();
568
- }
569
- // a retryable middleware-origin error is still the caller's error: once retries are
570
- // exhausted it propagates as-is rather than wrapped in APIConnectionError
571
- if (hasMiddleware && !isFetchOriginError(response)) {
572
- throw response;
573
- }
574
- throw new Errors.APIConnectionError({ cause: response });
575
- }
576
- const specialHeaders = [...response.headers.entries()]
577
- .filter(([name]) => name === 'request-id' || name === 'anthropic-workspace-id')
578
- .map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))
579
- .join('');
580
- const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
581
- if (!response.ok) {
582
- const shouldRetry = await this.shouldRetry(response, options);
583
- if (retriesRemaining && shouldRetry) {
584
- const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
585
- // We don't need the body of this response.
586
- await Shims.CancelReadableStream(response.body);
587
- releaseRequestSignal(controller);
575
+ const specialHeaders = [...response.headers.entries()]
576
+ .filter(([name]) => name === 'request-id' || name === 'anthropic-workspace-id')
577
+ .map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))
578
+ .join('');
579
+ const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
580
+ if (!response.ok) {
581
+ const shouldRetry = await this.shouldRetry(response, options);
582
+ if (retriesRemaining && shouldRetry) {
583
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
584
+ // We don't need the body of this response.
585
+ await Shims.CancelReadableStream(response.body);
586
+ releaseRequestSignal(controller);
587
+ loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
588
+ loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
589
+ retryOfRequestLogID,
590
+ url: response.url,
591
+ status: response.status,
592
+ headers: response.headers,
593
+ durationMs: headersTime - startTime,
594
+ }));
595
+ return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID, response.headers);
596
+ }
597
+ const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
588
598
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
599
+ const errText = await response.text().catch((err) => castToError(err).message);
600
+ const errJSON = safeJSON(errText);
601
+ const errMessage = errJSON ? undefined : errText;
589
602
  loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
590
603
  retryOfRequestLogID,
591
604
  url: response.url,
592
605
  status: response.status,
593
606
  headers: response.headers,
594
- durationMs: headersTime - startTime,
607
+ message: errMessage,
608
+ durationMs: Date.now() - startTime,
595
609
  }));
596
- return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID, response.headers);
597
- }
598
- const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
599
- loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
600
- const errText = await response.text().catch((err) => castToError(err).message);
601
- const errJSON = safeJSON(errText);
602
- const errMessage = errJSON ? undefined : errText;
603
- loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
610
+ releaseRequestSignal(controller);
611
+ const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
612
+ throw err;
613
+ }
614
+ loggerFor(this).info(responseInfo);
615
+ loggerFor(this).debug(`[${requestLogID}] response start`, formatRequestDetails({
604
616
  retryOfRequestLogID,
605
617
  url: response.url,
606
618
  status: response.status,
607
619
  headers: response.headers,
608
- message: errMessage,
609
- durationMs: Date.now() - startTime,
620
+ durationMs: headersTime - startTime,
610
621
  }));
611
- releaseRequestSignal(controller);
612
- const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
613
- throw err;
614
- }
615
- loggerFor(this).info(responseInfo);
616
- loggerFor(this).debug(`[${requestLogID}] response start`, formatRequestDetails({
617
- retryOfRequestLogID,
618
- url: response.url,
619
- status: response.status,
620
- headers: response.headers,
621
- durationMs: headersTime - startTime,
622
- }));
623
- armAbandonmentBackstop(response.body ?? response, controller);
624
- return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
625
- }
626
- getAPIList(path, Page, opts) {
627
- return this.requestAPIList(Page, opts && 'then' in opts ?
628
- opts.then((opts) => ({ method: 'get', path, ...opts }))
629
- : { method: 'get', path, ...opts });
630
- }
631
- requestAPIList(Page, options) {
632
- const request = this.makeRequest(options, null, undefined);
633
- return new Pagination.PagePromise(this, request, Page);
634
- }
635
- async fetchWithTimeout(url, init, ms, controller, requestOptions, logCtx) {
636
- const { signal, method, ...options } = init || {};
637
- // Avoid creating a closure over `this`, `init`, or `options` to prevent memory leaks.
638
- // An arrow function like `() => controller.abort()` captures the surrounding scope,
639
- // which includes the request body and other large objects. When the user passes a
640
- // long-lived AbortSignal, the listener prevents those objects from being GC'd for
641
- // the lifetime of the signal. Using `.bind()` only retains a reference to the
642
- // controller itself.
643
- const abort = this._makeAbort(controller);
644
- if (signal) {
645
- signal.addEventListener('abort', abort, { once: true });
646
- registerRequestSignalCleanup(controller, signal, abort);
647
- }
648
- const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
649
- (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
650
- const fetchOptions = {
651
- signal: controller.signal,
652
- ...(isReadableBody ? { duplex: 'half' } : {}),
653
- method: 'GET',
654
- ...options,
655
- };
656
- if (method) {
657
- // Custom methods like 'patch' need to be uppercased
658
- // See https://github.com/nodejs/undici/issues/2294
659
- fetchOptions.method = method.toUpperCase();
660
- }
661
- // Arm the timeout around the underlying fetch only, not the middleware
662
- // chain — middleware can take arbitrarily long (or call `next` more than
663
- // once), and each inner-fetch invocation gets its own `ms` timer.
664
- const baseFetch = this.fetch;
665
- const timedFetch = async (innerUrl, innerInit) => {
666
- const timeout = setTimeout(abort, ms);
667
- try {
668
- return await baseFetch.call(undefined, innerUrl, innerInit);
622
+ armAbandonmentBackstop(response.body ?? response, controller);
623
+ return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
624
+ }
625
+ getAPIList(path, Page, opts) {
626
+ return this.requestAPIList(Page, opts && 'then' in opts ?
627
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
628
+ : { method: 'get', path, ...opts });
629
+ }
630
+ requestAPIList(Page, options) {
631
+ const request = this.makeRequest(options, null, undefined);
632
+ return new Pagination.PagePromise(this, request, Page);
633
+ }
634
+ async fetchWithTimeout(url, init, ms, controller, requestOptions, logCtx) {
635
+ const { signal, method, ...options } = init || {};
636
+ // Avoid creating a closure over `this`, `init`, or `options` to prevent memory leaks.
637
+ // An arrow function like `() => controller.abort()` captures the surrounding scope,
638
+ // which includes the request body and other large objects. When the user passes a
639
+ // long-lived AbortSignal, the listener prevents those objects from being GC'd for
640
+ // the lifetime of the signal. Using `.bind()` only retains a reference to the
641
+ // controller itself.
642
+ const abort = this._makeAbort(controller);
643
+ if (signal) {
644
+ signal.addEventListener('abort', abort, { once: true });
645
+ registerRequestSignalCleanup(controller, signal, abort);
669
646
  }
670
- finally {
671
- clearTimeout(timeout);
672
- }
673
- };
674
- // Prepare the request (auth signing and other `prepareRequest` hooks) as
675
- // the innermost step, after any middleware — including the backend
676
- // middleware, so it sees exactly what goes over the wire. Runs per
677
- // inner-fetch invocation, so a request middleware rewrote — or replayed
678
- // via a second `next()` call — is prepared fresh each time. Preparation is
679
- // outside the timeout timer, matching its pre-middleware behavior.
680
- const innerFetch = requestOptions === undefined ? timedFetch : (async (innerUrl, innerInit = {}) => {
681
- const innerUrlStr = typeof innerUrl === 'string' ? innerUrl
682
- : innerUrl instanceof URL ? innerUrl.href
683
- : innerUrl.url;
684
- innerInit.headers =
685
- innerInit.headers instanceof Headers ? innerInit.headers : new Headers(innerInit.headers);
686
- await this.prepareRequest(innerInit, { url: innerUrlStr, options: requestOptions });
687
- if (logCtx) {
688
- loggerFor(this).debug(`[${logCtx.requestLogID}] sending request`, formatRequestDetails({
689
- retryOfRequestLogID: logCtx.retryOfRequestLogID,
690
- method: innerInit.method,
691
- url: innerUrlStr,
692
- options: requestOptions,
693
- headers: innerInit.headers,
694
- }));
647
+ const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
648
+ (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
649
+ const fetchOptions = {
650
+ signal: controller.signal,
651
+ ...(isReadableBody ? { duplex: 'half' } : {}),
652
+ method: 'GET',
653
+ ...options,
654
+ };
655
+ if (method) {
656
+ // Custom methods like 'patch' need to be uppercased
657
+ // See https://github.com/nodejs/undici/issues/2294
658
+ fetchOptions.method = method.toUpperCase();
695
659
  }
696
- return timedFetch(innerUrl, innerInit);
697
- });
698
- const requestMiddleware = requestOptions?.middleware;
699
- const backendMiddleware = this.backendMiddleware();
700
- const allMiddleware = requestMiddleware?.length || backendMiddleware.length ?
701
- [...this.middleware, ...(requestMiddleware ?? []), ...backendMiddleware]
702
- : this.middleware;
703
- return await wrapFetchWithMiddleware(innerFetch, allMiddleware, requestOptions, this)(url, fetchOptions);
704
- }
705
- async shouldRetry(response, options) {
706
- // Reactive refresh: on a 401 from a request that used the token cache,
707
- // invalidate and retry once. Only fires when this specific request was
708
- // bearer-authenticated (not when an apiKey was used) and only once per
709
- // request a second 401 after refresh falls through to the normal
710
- // retry policy below (which treats 4xx as non-retryable).
711
- const flags = this._authFlags(options);
712
- if (response.status === 401 &&
713
- this._authState.tokenCache &&
714
- flags.usedTokenCache &&
715
- !flags.didRefreshFor401) {
716
- flags.didRefreshFor401 = true;
717
- this._authState.tokenCache.invalidate();
718
- return true;
719
- }
720
- // Note this is not a standard header.
721
- const shouldRetryHeader = response.headers.get('x-should-retry');
722
- // If the server explicitly says whether or not to retry, obey.
723
- if (shouldRetryHeader === 'true')
724
- return true;
725
- if (shouldRetryHeader === 'false')
660
+ // Arm the timeout around the underlying fetch only, not the middleware
661
+ // chain — middleware can take arbitrarily long (or call `next` more than
662
+ // once), and each inner-fetch invocation gets its own `ms` timer.
663
+ const baseFetch = this.fetch;
664
+ const timedFetch = async (innerUrl, innerInit) => {
665
+ const timeout = setTimeout(abort, ms);
666
+ try {
667
+ return await baseFetch.call(undefined, innerUrl, innerInit);
668
+ }
669
+ finally {
670
+ clearTimeout(timeout);
671
+ }
672
+ };
673
+ // Prepare the request (auth signing and other `prepareRequest` hooks) as
674
+ // the innermost step, after any middleware including the backend
675
+ // middleware, so it sees exactly what goes over the wire. Runs per
676
+ // inner-fetch invocation, so a request middleware rewrote — or replayed
677
+ // via a second `next()` call — is prepared fresh each time. Preparation is
678
+ // outside the timeout timer, matching its pre-middleware behavior.
679
+ const innerFetch = requestOptions === undefined ? timedFetch : (async (innerUrl, innerInit = {}) => {
680
+ const innerUrlStr = typeof innerUrl === 'string' ? innerUrl
681
+ : innerUrl instanceof URL ? innerUrl.href
682
+ : innerUrl.url;
683
+ innerInit.headers =
684
+ innerInit.headers instanceof Headers ? innerInit.headers : new Headers(innerInit.headers);
685
+ await this.prepareRequest(innerInit, { url: innerUrlStr, options: requestOptions });
686
+ if (logCtx) {
687
+ loggerFor(this).debug(`[${logCtx.requestLogID}] sending request`, formatRequestDetails({
688
+ retryOfRequestLogID: logCtx.retryOfRequestLogID,
689
+ method: innerInit.method,
690
+ url: innerUrlStr,
691
+ options: requestOptions,
692
+ headers: innerInit.headers,
693
+ }));
694
+ }
695
+ return timedFetch(innerUrl, innerInit);
696
+ });
697
+ const requestMiddleware = requestOptions?.middleware;
698
+ const backendMiddleware = this.backendMiddleware();
699
+ const allMiddleware = requestMiddleware?.length || backendMiddleware.length ?
700
+ [...this.middleware, ...(requestMiddleware ?? []), ...backendMiddleware]
701
+ : this.middleware;
702
+ return await wrapFetchWithMiddleware(innerFetch, allMiddleware, requestOptions, this)(url, fetchOptions);
703
+ }
704
+ async shouldRetry(response, options) {
705
+ // Reactive refresh: on a 401 from a request that used the token cache,
706
+ // invalidate and retry once. Only fires when this specific request was
707
+ // bearer-authenticated (not when an apiKey was used) and only once per
708
+ // request — a second 401 after refresh falls through to the normal
709
+ // retry policy below (which treats 4xx as non-retryable).
710
+ const flags = this._authFlags(options);
711
+ if (response.status === 401 &&
712
+ this._authState.tokenCache &&
713
+ flags.usedTokenCache &&
714
+ !flags.didRefreshFor401) {
715
+ flags.didRefreshFor401 = true;
716
+ this._authState.tokenCache.invalidate();
717
+ return true;
718
+ }
719
+ // Note this is not a standard header.
720
+ const shouldRetryHeader = response.headers.get('x-should-retry');
721
+ // If the server explicitly says whether or not to retry, obey.
722
+ if (shouldRetryHeader === 'true')
723
+ return true;
724
+ if (shouldRetryHeader === 'false')
725
+ return false;
726
+ // Retry on request timeouts.
727
+ if (response.status === 408)
728
+ return true;
729
+ // Retry on lock timeouts.
730
+ if (response.status === 409)
731
+ return true;
732
+ // Retry on rate limits.
733
+ if (response.status === 429)
734
+ return true;
735
+ // Retry internal errors.
736
+ if (response.status >= 500)
737
+ return true;
726
738
  return false;
727
- // Retry on request timeouts.
728
- if (response.status === 408)
729
- return true;
730
- // Retry on lock timeouts.
731
- if (response.status === 409)
732
- return true;
733
- // Retry on rate limits.
734
- if (response.status === 429)
735
- return true;
736
- // Retry internal errors.
737
- if (response.status >= 500)
738
- return true;
739
- return false;
740
- }
741
- async retryRequest(options, retriesRemaining, requestLogID, responseHeaders) {
742
- let timeoutMillis;
743
- // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
744
- const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
745
- if (retryAfterMillisHeader) {
746
- const timeoutMs = parseFloat(retryAfterMillisHeader);
747
- if (!Number.isNaN(timeoutMs)) {
748
- timeoutMillis = timeoutMs;
749
- }
750
- }
751
- // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
752
- const retryAfterHeader = responseHeaders?.get('retry-after');
753
- if (retryAfterHeader && !timeoutMillis) {
754
- const timeoutSeconds = parseFloat(retryAfterHeader);
755
- if (!Number.isNaN(timeoutSeconds)) {
756
- timeoutMillis = timeoutSeconds * 1000;
739
+ }
740
+ async retryRequest(options, retriesRemaining, requestLogID, responseHeaders) {
741
+ let timeoutMillis;
742
+ // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
743
+ const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
744
+ if (retryAfterMillisHeader) {
745
+ const timeoutMs = parseFloat(retryAfterMillisHeader);
746
+ if (!Number.isNaN(timeoutMs)) {
747
+ timeoutMillis = timeoutMs;
748
+ }
757
749
  }
758
- else {
759
- timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
750
+ // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
751
+ const retryAfterHeader = responseHeaders?.get('retry-after');
752
+ if (retryAfterHeader && !timeoutMillis) {
753
+ const timeoutSeconds = parseFloat(retryAfterHeader);
754
+ if (!Number.isNaN(timeoutSeconds)) {
755
+ timeoutMillis = timeoutSeconds * 1000;
756
+ }
757
+ else {
758
+ timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
759
+ }
760
760
  }
761
- }
762
- // If the API asks us to wait a certain amount of time, just do what it
763
- // says, but otherwise calculate a default
764
- if (timeoutMillis === undefined) {
765
- const maxRetries = options.maxRetries ?? this.maxRetries;
766
- timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
767
- }
768
- await sleep(timeoutMillis);
769
- return this.makeRequest(options, retriesRemaining - 1, requestLogID);
770
- }
771
- calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
772
- const initialRetryDelay = 0.5;
773
- const maxRetryDelay = 8.0;
774
- const numRetries = maxRetries - retriesRemaining;
775
- // Apply exponential backoff, but not more than the max.
776
- const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
777
- // Apply some jitter, take up to at most 25 percent of the retry time.
778
- const jitter = 1 - Math.random() * 0.25;
779
- return sleepSeconds * jitter * 1000;
780
- }
781
- calculateNonstreamingTimeout(maxTokens, maxNonstreamingTokens) {
782
- const maxTime = 60 * 60 * 1000; // 60 minutes
783
- const defaultTime = 60 * 10 * 1000; // 10 minutes
784
- const expectedTime = (maxTime * maxTokens) / 128000;
785
- if (expectedTime > defaultTime || (maxNonstreamingTokens != null && maxTokens > maxNonstreamingTokens)) {
786
- throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details');
787
- }
788
- return defaultTime;
789
- }
790
- async buildRequest(inputOptions, { retryCount = 0 } = {}) {
791
- const options = { ...inputOptions };
792
- const { method, path, query, defaultBaseURL } = options;
793
- // Lazy credential resolution may carry a profile-supplied baseURL. Await
794
- // it before building the request URL so the very first request — and
795
- // requests on withOptions() clones created before resolution settled —
796
- // hit the profile's host rather than the hardcoded default.
797
- if (this._authState.resolution) {
798
- await this._authState.resolution;
799
- }
800
- if (!this._baseURLIsExplicit && this._authState.baseURL && this.baseURL !== this._authState.baseURL) {
801
- this.baseURL = this._authState.baseURL;
802
- }
803
- const url = this.buildURL(path, query, defaultBaseURL);
804
- if ('timeout' in options)
805
- validatePositiveInteger('timeout', options.timeout);
806
- options.timeout = options.timeout ?? this.timeout;
807
- const { bodyHeaders, body } = this.buildBody({ options });
808
- const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
809
- const req = {
810
- method,
811
- headers: reqHeaders,
812
- ...(options.signal && { signal: options.signal }),
813
- ...(globalThis.ReadableStream &&
814
- body instanceof globalThis.ReadableStream && { duplex: 'half' }),
815
- ...(body && { body }),
816
- ...(this.fetchOptions ?? {}),
817
- ...(options.fetchOptions ?? {}),
818
- };
819
- return { req, url, timeout: options.timeout };
820
- }
821
- async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
822
- let idempotencyHeaders = {};
823
- if (this.idempotencyHeader && method !== 'get') {
824
- if (!options.idempotencyKey)
825
- options.idempotencyKey = this.defaultIdempotencyKey();
826
- idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
827
- }
828
- const headers = buildHeaders([
829
- idempotencyHeaders,
830
- {
831
- Accept: 'application/json',
832
- 'User-Agent': this.getUserAgent(),
833
- 'X-Stainless-Retry-Count': String(retryCount),
834
- ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
835
- ...getPlatformHeaders(),
836
- ...(this._options.dangerouslyAllowBrowser ?
837
- { 'anthropic-dangerous-direct-browser-access': 'true' }
838
- : undefined),
839
- 'anthropic-version': '2023-06-01',
840
- },
841
- await this.authHeaders(options),
842
- this._options.defaultHeaders,
843
- bodyHeaders,
844
- options.headers,
845
- ]);
846
- this.validateHeaders(headers);
847
- return headers.values;
848
- }
849
- _makeAbort(controller) {
850
- // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
851
- // would capture all request options, and cause a memory leak.
852
- return () => controller.abort();
853
- }
854
- buildBody({ options: { body, headers: rawHeaders } }) {
855
- if (!body) {
856
- return { bodyHeaders: undefined, body: undefined };
857
- }
858
- const headers = buildHeaders([rawHeaders]);
859
- if (
860
- // Pass raw type verbatim
861
- ArrayBuffer.isView(body) ||
862
- body instanceof ArrayBuffer ||
863
- body instanceof DataView ||
864
- (typeof body === 'string' &&
865
- // Preserve legacy string encoding behavior for now
866
- headers.values.has('content-type')) ||
867
- // `Blob` is superset of `File`
868
- (globalThis.Blob && body instanceof globalThis.Blob) ||
869
- // `FormData` -> `multipart/form-data`
870
- body instanceof FormData ||
871
- // `URLSearchParams` -> `application/x-www-form-urlencoded`
872
- body instanceof URLSearchParams ||
873
- // Send chunked stream (each chunk has own `length`)
874
- (globalThis.ReadableStream && body instanceof globalThis.ReadableStream)) {
875
- return { bodyHeaders: undefined, body: body };
876
- }
877
- else if (typeof body === 'object' &&
878
- (Symbol.asyncIterator in body ||
879
- (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
880
- return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body) };
881
- }
882
- else if (typeof body === 'object' &&
883
- headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
884
- return {
885
- bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
886
- body: this.stringifyQuery(body),
761
+ // If the API asks us to wait a certain amount of time, do what it says, as long as it's a positive delay that
762
+ // one timer can represent (setTimeout fires after 1ms for anything above 2^31 - 1). Otherwise (no header, an
763
+ // unparseable value, zero/negative, a date in the past) calculate a default.
764
+ if (timeoutMillis === undefined || !(timeoutMillis > 0 && timeoutMillis <= 2 ** 31 - 1)) {
765
+ const maxRetries = options.maxRetries ?? this.maxRetries;
766
+ timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
767
+ }
768
+ await sleep(timeoutMillis, options.signal ?? undefined);
769
+ return this.makeRequest(options, retriesRemaining - 1, requestLogID);
770
+ }
771
+ calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
772
+ const initialRetryDelay = 0.5;
773
+ const maxRetryDelay = 8.0;
774
+ const numRetries = maxRetries - retriesRemaining;
775
+ // Apply exponential backoff, but not more than the max.
776
+ const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
777
+ // Apply some jitter, take up to at most 25 percent of the retry time.
778
+ const jitter = 1 - Math.random() * 0.25;
779
+ return sleepSeconds * jitter * 1000;
780
+ }
781
+ calculateNonstreamingTimeout(maxTokens, maxNonstreamingTokens) {
782
+ const maxTime = 60 * 60 * 1000; // 60 minutes
783
+ const defaultTime = 60 * 10 * 1000; // 10 minutes
784
+ const expectedTime = (maxTime * maxTokens) / 128000;
785
+ if (expectedTime > defaultTime || (maxNonstreamingTokens != null && maxTokens > maxNonstreamingTokens)) {
786
+ throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details');
787
+ }
788
+ return defaultTime;
789
+ }
790
+ async buildRequest(inputOptions, { retryCount = 0 } = {}) {
791
+ const options = { ...inputOptions };
792
+ const { method, path, query, defaultBaseURL } = options;
793
+ // Lazy credential resolution may carry a profile-supplied baseURL. Await
794
+ // it before building the request URL so the very first request — and
795
+ // requests on withOptions() clones created before resolution settled —
796
+ // hit the profile's host rather than the hardcoded default.
797
+ if (this._authState.resolution) {
798
+ await this._authState.resolution;
799
+ }
800
+ if (!this._baseURLIsExplicit && this._authState.baseURL && this.baseURL !== this._authState.baseURL) {
801
+ this.baseURL = this._authState.baseURL;
802
+ }
803
+ const url = this.buildURL(path, query, defaultBaseURL);
804
+ if ('timeout' in options)
805
+ validatePositiveInteger('timeout', options.timeout);
806
+ options.timeout = options.timeout ?? this.timeout;
807
+ const { bodyHeaders, body } = this.buildBody({ options });
808
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
809
+ const req = {
810
+ method,
811
+ headers: reqHeaders,
812
+ ...(options.signal && { signal: options.signal }),
813
+ ...(globalThis.ReadableStream &&
814
+ body instanceof globalThis.ReadableStream && { duplex: 'half' }),
815
+ ...(body && { body }),
816
+ ...(this.fetchOptions ?? {}),
817
+ ...(options.fetchOptions ?? {}),
887
818
  };
888
- }
889
- else {
890
- return __classPrivateFieldGet(this, _BaseAnthropic_encoder, "f").call(this, { body, headers });
819
+ return { req, url, timeout: options.timeout };
820
+ }
821
+ async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
822
+ const headers = buildHeaders([
823
+ {
824
+ Accept: 'application/json',
825
+ 'User-Agent': this.getUserAgent(),
826
+ 'X-Stainless-Retry-Count': String(retryCount),
827
+ ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
828
+ ...getPlatformHeaders(),
829
+ ...(this._options.dangerouslyAllowBrowser ?
830
+ { 'anthropic-dangerous-direct-browser-access': 'true' }
831
+ : undefined),
832
+ 'anthropic-version': '2023-06-01',
833
+ },
834
+ await this.authHeaders(options),
835
+ this._options.defaultHeaders,
836
+ bodyHeaders,
837
+ options.headers,
838
+ ]);
839
+ this.validateHeaders(headers);
840
+ return headers.values;
841
+ }
842
+ _makeAbort(controller) {
843
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
844
+ // would capture all request options, and cause a memory leak.
845
+ return () => controller.abort();
846
+ }
847
+ buildBody({ options: { body, headers: rawHeaders } }) {
848
+ if (!body) {
849
+ return { bodyHeaders: undefined, body: undefined };
850
+ }
851
+ const headers = buildHeaders([rawHeaders]);
852
+ if (
853
+ // Pass raw type verbatim
854
+ ArrayBuffer.isView(body) ||
855
+ body instanceof ArrayBuffer ||
856
+ body instanceof DataView ||
857
+ (typeof body === 'string' &&
858
+ // Preserve legacy string encoding behavior for now
859
+ headers.values.has('content-type')) ||
860
+ // `Blob` is superset of `File`
861
+ (globalThis.Blob && body instanceof globalThis.Blob) ||
862
+ // `FormData` -> `multipart/form-data`
863
+ body instanceof FormData ||
864
+ // `URLSearchParams` -> `application/x-www-form-urlencoded`
865
+ body instanceof URLSearchParams ||
866
+ // Send chunked stream (each chunk has own `length`)
867
+ (globalThis.ReadableStream && body instanceof globalThis.ReadableStream)) {
868
+ return { bodyHeaders: undefined, body: body };
869
+ }
870
+ else if (typeof body === 'object' &&
871
+ (Symbol.asyncIterator in body ||
872
+ (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
873
+ return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body) };
874
+ }
875
+ else if (typeof body === 'object' &&
876
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
877
+ return {
878
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
879
+ body: this.stringifyQuery(body),
880
+ };
881
+ }
882
+ else {
883
+ return __classPrivateFieldGet(this, _BaseAnthropic_encoder, "f").call(this, { body, headers });
884
+ }
891
885
  }
892
886
  }
893
- }
894
- _a = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap(), _BaseAnthropic_instances = new WeakSet(), _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden() {
895
- return this.baseURL !== 'https://api.anthropic.com';
896
- };
897
- BaseAnthropic.Anthropic = _a;
898
- BaseAnthropic.HUMAN_PROMPT = HUMAN_PROMPT;
899
- BaseAnthropic.AI_PROMPT = AI_PROMPT;
900
- BaseAnthropic.DEFAULT_TIMEOUT = 600000; // 10 minutes
901
- BaseAnthropic.AnthropicError = Errors.AnthropicError;
902
- BaseAnthropic.APIError = Errors.APIError;
903
- BaseAnthropic.APIConnectionError = Errors.APIConnectionError;
904
- BaseAnthropic.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
905
- BaseAnthropic.APIUserAbortError = Errors.APIUserAbortError;
906
- BaseAnthropic.NotFoundError = Errors.NotFoundError;
907
- BaseAnthropic.ConflictError = Errors.ConflictError;
908
- BaseAnthropic.RateLimitError = Errors.RateLimitError;
909
- BaseAnthropic.BadRequestError = Errors.BadRequestError;
910
- BaseAnthropic.AuthenticationError = Errors.AuthenticationError;
911
- BaseAnthropic.InternalServerError = Errors.InternalServerError;
912
- BaseAnthropic.PermissionDeniedError = Errors.PermissionDeniedError;
913
- BaseAnthropic.UnprocessableEntityError = Errors.UnprocessableEntityError;
914
- BaseAnthropic.toFile = Uploads.toFile;
887
+ _a = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap(), _BaseAnthropic_instances = new WeakSet(), _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden() {
888
+ return this.baseURL !== 'https://api.anthropic.com';
889
+ };
890
+ BaseAnthropic.Anthropic = _a;
891
+ BaseAnthropic.HUMAN_PROMPT = HUMAN_PROMPT;
892
+ BaseAnthropic.AI_PROMPT = AI_PROMPT;
893
+ BaseAnthropic.DEFAULT_TIMEOUT = 600000; // 10 minutes
894
+ BaseAnthropic.AnthropicError = Errors.AnthropicError;
895
+ BaseAnthropic.APIError = Errors.APIError;
896
+ BaseAnthropic.APIConnectionError = Errors.APIConnectionError;
897
+ BaseAnthropic.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
898
+ BaseAnthropic.APIUserAbortError = Errors.APIUserAbortError;
899
+ BaseAnthropic.NotFoundError = Errors.NotFoundError;
900
+ BaseAnthropic.ConflictError = Errors.ConflictError;
901
+ BaseAnthropic.RateLimitError = Errors.RateLimitError;
902
+ BaseAnthropic.BadRequestError = Errors.BadRequestError;
903
+ BaseAnthropic.AuthenticationError = Errors.AuthenticationError;
904
+ BaseAnthropic.InternalServerError = Errors.InternalServerError;
905
+ BaseAnthropic.PermissionDeniedError = Errors.PermissionDeniedError;
906
+ BaseAnthropic.UnprocessableEntityError = Errors.UnprocessableEntityError;
907
+ BaseAnthropic.toFile = Uploads.toFile;
908
+ return BaseAnthropic;
909
+ })();
915
910
  /**
916
911
  * API Client for interfacing with the Anthropic API.
917
912
  */
918
- export class Anthropic extends BaseAnthropic {
919
- constructor() {
920
- super(...arguments);
921
- this.completions = new API.Completions(this);
922
- this.messages = new API.Messages(this);
923
- this.models = new API.Models(this);
924
- this.files = new API.Files(this);
925
- this.skills = new API.Skills(this);
926
- this.beta = new API.Beta(this);
927
- }
928
- }
929
- Anthropic.Completions = Completions;
930
- Anthropic.Messages = Messages;
931
- Anthropic.Models = Models;
932
- Anthropic.Files = Files;
933
- Anthropic.Skills = Skills;
934
- Anthropic.Beta = Beta;
913
+ export var Anthropic = /* @__PURE__ */ (() => {
914
+ /**
915
+ * API Client for interfacing with the Anthropic API.
916
+ */
917
+ class Anthropic extends BaseAnthropic {
918
+ constructor() {
919
+ super(...arguments);
920
+ this.completions = new API.Completions(this);
921
+ this.messages = new API.Messages(this);
922
+ this.models = new API.Models(this);
923
+ this.files = new API.Files(this);
924
+ this.skills = new API.Skills(this);
925
+ this.beta = new API.Beta(this);
926
+ }
927
+ }
928
+ Anthropic.Completions = Completions;
929
+ Anthropic.Messages = Messages;
930
+ Anthropic.Models = Models;
931
+ Anthropic.Files = Files;
932
+ Anthropic.Skills = Skills;
933
+ Anthropic.Beta = Beta;
934
+ return Anthropic;
935
+ })();
935
936
  //# sourceMappingURL=client.mjs.map