@anthropic-ai/sdk 0.114.0 → 0.116.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 (204) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/client.d.mts +3 -3
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.d.ts.map +1 -1
  6. package/client.js +9 -2
  7. package/client.js.map +1 -1
  8. package/client.mjs +9 -2
  9. package/client.mjs.map +1 -1
  10. package/core/streaming.d.mts.map +1 -1
  11. package/core/streaming.d.ts.map +1 -1
  12. package/core/streaming.js +3 -0
  13. package/core/streaming.js.map +1 -1
  14. package/core/streaming.mjs +3 -0
  15. package/core/streaming.mjs.map +1 -1
  16. package/internal/constants.d.mts.map +1 -1
  17. package/internal/constants.d.ts.map +1 -1
  18. package/internal/constants.js +0 -5
  19. package/internal/constants.js.map +1 -1
  20. package/internal/constants.mjs +0 -5
  21. package/internal/constants.mjs.map +1 -1
  22. package/internal/parse.d.mts.map +1 -1
  23. package/internal/parse.d.ts.map +1 -1
  24. package/internal/parse.js +10 -1
  25. package/internal/parse.js.map +1 -1
  26. package/internal/parse.mjs +10 -1
  27. package/internal/parse.mjs.map +1 -1
  28. package/internal/request-signal.d.mts +4 -0
  29. package/internal/request-signal.d.mts.map +1 -0
  30. package/internal/request-signal.d.ts +4 -0
  31. package/internal/request-signal.d.ts.map +1 -0
  32. package/internal/request-signal.js +50 -0
  33. package/internal/request-signal.js.map +1 -0
  34. package/internal/request-signal.mjs +45 -0
  35. package/internal/request-signal.mjs.map +1 -0
  36. package/lib/BetaMessageStream.d.mts.map +1 -1
  37. package/lib/BetaMessageStream.d.ts.map +1 -1
  38. package/lib/BetaMessageStream.js +3 -0
  39. package/lib/BetaMessageStream.js.map +1 -1
  40. package/lib/BetaMessageStream.mjs +3 -0
  41. package/lib/BetaMessageStream.mjs.map +1 -1
  42. package/lib/middleware.d.mts +5 -3
  43. package/lib/middleware.d.mts.map +1 -1
  44. package/lib/middleware.d.ts +5 -3
  45. package/lib/middleware.d.ts.map +1 -1
  46. package/lib/middleware.js +58 -15
  47. package/lib/middleware.js.map +1 -1
  48. package/lib/middleware.mjs +58 -15
  49. package/lib/middleware.mjs.map +1 -1
  50. package/lib/sessions/accumulate.js +1 -0
  51. package/lib/sessions/accumulate.js.map +1 -1
  52. package/lib/sessions/accumulate.mjs +1 -0
  53. package/lib/sessions/accumulate.mjs.map +1 -1
  54. package/lib/tools/BetaToolRunner.d.mts.map +1 -1
  55. package/lib/tools/BetaToolRunner.d.ts.map +1 -1
  56. package/lib/tools/BetaToolRunner.js +80 -7
  57. package/lib/tools/BetaToolRunner.js.map +1 -1
  58. package/lib/tools/BetaToolRunner.mjs +80 -7
  59. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  60. package/package.json +1 -1
  61. package/resources/beta/agents/agents.d.mts +26 -4
  62. package/resources/beta/agents/agents.d.mts.map +1 -1
  63. package/resources/beta/agents/agents.d.ts +26 -4
  64. package/resources/beta/agents/agents.d.ts.map +1 -1
  65. package/resources/beta/agents/agents.js.map +1 -1
  66. package/resources/beta/agents/agents.mjs.map +1 -1
  67. package/resources/beta/agents/index.d.mts +1 -1
  68. package/resources/beta/agents/index.d.mts.map +1 -1
  69. package/resources/beta/agents/index.d.ts +1 -1
  70. package/resources/beta/agents/index.d.ts.map +1 -1
  71. package/resources/beta/agents/index.js.map +1 -1
  72. package/resources/beta/agents/index.mjs.map +1 -1
  73. package/resources/beta/beta.d.mts +28 -10
  74. package/resources/beta/beta.d.mts.map +1 -1
  75. package/resources/beta/beta.d.ts +28 -10
  76. package/resources/beta/beta.d.ts.map +1 -1
  77. package/resources/beta/beta.js.map +1 -1
  78. package/resources/beta/beta.mjs.map +1 -1
  79. package/resources/beta/deployments.d.mts +16 -1
  80. package/resources/beta/deployments.d.mts.map +1 -1
  81. package/resources/beta/deployments.d.ts +16 -1
  82. package/resources/beta/deployments.d.ts.map +1 -1
  83. package/resources/beta/index.d.mts +5 -5
  84. package/resources/beta/index.d.mts.map +1 -1
  85. package/resources/beta/index.d.ts +5 -5
  86. package/resources/beta/index.d.ts.map +1 -1
  87. package/resources/beta/index.js.map +1 -1
  88. package/resources/beta/index.mjs.map +1 -1
  89. package/resources/beta/messages/batches.d.mts +4 -3
  90. package/resources/beta/messages/batches.d.mts.map +1 -1
  91. package/resources/beta/messages/batches.d.ts +4 -3
  92. package/resources/beta/messages/batches.d.ts.map +1 -1
  93. package/resources/beta/messages/index.d.mts +1 -1
  94. package/resources/beta/messages/index.d.mts.map +1 -1
  95. package/resources/beta/messages/index.d.ts +1 -1
  96. package/resources/beta/messages/index.d.ts.map +1 -1
  97. package/resources/beta/messages/index.js.map +1 -1
  98. package/resources/beta/messages/index.mjs.map +1 -1
  99. package/resources/beta/messages/messages.d.mts +205 -6
  100. package/resources/beta/messages/messages.d.mts.map +1 -1
  101. package/resources/beta/messages/messages.d.ts +205 -6
  102. package/resources/beta/messages/messages.d.ts.map +1 -1
  103. package/resources/beta/messages/messages.js +1 -22
  104. package/resources/beta/messages/messages.js.map +1 -1
  105. package/resources/beta/messages/messages.mjs +1 -22
  106. package/resources/beta/messages/messages.mjs.map +1 -1
  107. package/resources/beta/sessions/events.d.mts +60 -10
  108. package/resources/beta/sessions/events.d.mts.map +1 -1
  109. package/resources/beta/sessions/events.d.ts +60 -10
  110. package/resources/beta/sessions/events.d.ts.map +1 -1
  111. package/resources/beta/sessions/events.js.map +1 -1
  112. package/resources/beta/sessions/events.mjs.map +1 -1
  113. package/resources/beta/sessions/index.d.mts +2 -2
  114. package/resources/beta/sessions/index.d.mts.map +1 -1
  115. package/resources/beta/sessions/index.d.ts +2 -2
  116. package/resources/beta/sessions/index.d.ts.map +1 -1
  117. package/resources/beta/sessions/index.js.map +1 -1
  118. package/resources/beta/sessions/index.mjs.map +1 -1
  119. package/resources/beta/sessions/sessions.d.mts +101 -6
  120. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  121. package/resources/beta/sessions/sessions.d.ts +101 -6
  122. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  123. package/resources/beta/sessions/sessions.js.map +1 -1
  124. package/resources/beta/sessions/sessions.mjs.map +1 -1
  125. package/resources/beta/sessions/threads/threads.d.mts +17 -5
  126. package/resources/beta/sessions/threads/threads.d.mts.map +1 -1
  127. package/resources/beta/sessions/threads/threads.d.ts +17 -5
  128. package/resources/beta/sessions/threads/threads.d.ts.map +1 -1
  129. package/resources/beta/sessions/threads/threads.js.map +1 -1
  130. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  131. package/resources/beta/webhooks.d.mts +11 -2
  132. package/resources/beta/webhooks.d.mts.map +1 -1
  133. package/resources/beta/webhooks.d.ts +11 -2
  134. package/resources/beta/webhooks.d.ts.map +1 -1
  135. package/resources/index.d.mts +1 -1
  136. package/resources/index.d.mts.map +1 -1
  137. package/resources/index.d.ts +1 -1
  138. package/resources/index.d.ts.map +1 -1
  139. package/resources/index.js.map +1 -1
  140. package/resources/index.mjs.map +1 -1
  141. package/resources/messages/messages.d.mts +52 -1
  142. package/resources/messages/messages.d.mts.map +1 -1
  143. package/resources/messages/messages.d.ts +52 -1
  144. package/resources/messages/messages.d.ts.map +1 -1
  145. package/resources/messages/messages.js +1 -22
  146. package/resources/messages/messages.js.map +1 -1
  147. package/resources/messages/messages.mjs +1 -22
  148. package/resources/messages/messages.mjs.map +1 -1
  149. package/src/client.ts +19 -3
  150. package/src/core/streaming.ts +3 -0
  151. package/src/internal/constants.ts +0 -5
  152. package/src/internal/parse.ts +10 -1
  153. package/src/internal/request-signal.ts +68 -0
  154. package/src/lib/BetaMessageStream.ts +4 -0
  155. package/src/lib/middleware.ts +61 -16
  156. package/src/lib/sessions/accumulate.ts +1 -0
  157. package/src/lib/tools/BetaToolRunner.ts +101 -8
  158. package/src/resources/beta/agents/agents.ts +30 -2
  159. package/src/resources/beta/agents/index.ts +1 -0
  160. package/src/resources/beta/beta.ts +59 -1
  161. package/src/resources/beta/deployments.ts +19 -0
  162. package/src/resources/beta/index.ts +18 -0
  163. package/src/resources/beta/messages/batches.ts +4 -3
  164. package/src/resources/beta/messages/index.ts +10 -0
  165. package/src/resources/beta/messages/messages.ts +251 -26
  166. package/src/resources/beta/sessions/events.ts +95 -9
  167. package/src/resources/beta/sessions/index.ts +7 -0
  168. package/src/resources/beta/sessions/sessions.ts +127 -3
  169. package/src/resources/beta/sessions/threads/threads.ts +21 -5
  170. package/src/resources/beta/webhooks.ts +16 -1
  171. package/src/resources/index.ts +2 -0
  172. package/src/resources/messages/messages.ts +53 -24
  173. package/src/tools/agent-toolset/node.browser.ts +14 -0
  174. package/src/tools/agent-toolset/node.ts +19 -8
  175. package/src/version.ts +1 -1
  176. package/tools/agent-toolset/node.browser.d.mts +9 -0
  177. package/tools/agent-toolset/node.browser.d.mts.map +1 -1
  178. package/tools/agent-toolset/node.browser.d.ts +9 -0
  179. package/tools/agent-toolset/node.browser.d.ts.map +1 -1
  180. package/tools/agent-toolset/node.browser.js +13 -1
  181. package/tools/agent-toolset/node.browser.js.map +1 -1
  182. package/tools/agent-toolset/node.browser.mjs +11 -0
  183. package/tools/agent-toolset/node.browser.mjs.map +1 -1
  184. package/tools/agent-toolset/node.d.mts +9 -0
  185. package/tools/agent-toolset/node.d.mts.map +1 -1
  186. package/tools/agent-toolset/node.d.ts +9 -0
  187. package/tools/agent-toolset/node.d.ts.map +1 -1
  188. package/tools/agent-toolset/node.js +18 -6
  189. package/tools/agent-toolset/node.js.map +1 -1
  190. package/tools/agent-toolset/node.mjs +16 -5
  191. package/tools/agent-toolset/node.mjs.map +1 -1
  192. package/version.d.mts +1 -1
  193. package/version.d.ts +1 -1
  194. package/version.js +1 -1
  195. package/version.mjs +1 -1
  196. package/lib/tools/ToolRunner.d.mts +0 -132
  197. package/lib/tools/ToolRunner.d.mts.map +0 -1
  198. package/lib/tools/ToolRunner.d.ts +0 -132
  199. package/lib/tools/ToolRunner.d.ts.map +0 -1
  200. package/lib/tools/ToolRunner.js +0 -294
  201. package/lib/tools/ToolRunner.js.map +0 -1
  202. package/lib/tools/ToolRunner.mjs +0 -290
  203. package/lib/tools/ToolRunner.mjs.map +0 -1
  204. package/src/lib/tools/ToolRunner.ts +0 -381
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;AAGtF,qDAAkD;AAElD,uDAAsD;AAEtD,uFAA+E;AAC/E,8DAAwD;AACxD,gDAK0B;AAC1B,iEAAwC;AACxC,0CAcmB;AAGnB,2DAAqE;AAErE,MAAa,QAAS,SAAQ,sBAAW;IAAzC;;QACE,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAkKrE,CAAC;IApIC,MAAM,CACJ,MAA2B,EAC3B,OAAwB;QAExB,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC5C,IAAI,IAAI,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CACV,cAAc,IAAI,CAAC,KAAK,iDACtB,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAC9B,gIAAgI,CACjI,CAAC;QACJ,CAAC;QACD,IACE,oCAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;YACzD,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAChC,CAAC;YACD,OAAO,CAAC,IAAI,CACV,qBAAqB,IAAI,CAAC,KAAK,oNAAoN,CACpP,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,GAAI,IAAI,CAAC,OAAe,CAAC,QAAQ,CAAC,OAAwB,CAAC;QACtE,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,qBAAqB,GAAG,qCAAyB,CAAC,IAAI,CAAC,KAAK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AI,CAAC,2BAA2B,EAAE;YACpD,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,2BAA2B,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE;gBAC/F,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF;AAnKD,4BAmKC;AAglCD,MAAM,iBAAiB,GAEnB,EAAE,CAAC;AAEP,MAAM,oCAAoC,GAAY,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC;AA4wEnG,QAAQ,CAAC,OAAO,GAAG,iBAAO,CAAC"}
@@ -116,28 +116,7 @@ export class Messages extends APIResource {
116
116
  });
117
117
  }
118
118
  }
119
- const DEPRECATED_MODELS = {
120
- 'claude-1.3': 'November 6th, 2024',
121
- 'claude-1.3-100k': 'November 6th, 2024',
122
- 'claude-instant-1.1': 'November 6th, 2024',
123
- 'claude-instant-1.1-100k': 'November 6th, 2024',
124
- 'claude-instant-1.2': 'November 6th, 2024',
125
- 'claude-3-sonnet-20240229': 'July 21st, 2025',
126
- 'claude-3-opus-20240229': 'January 5th, 2026',
127
- 'claude-2.1': 'July 21st, 2025',
128
- 'claude-2.0': 'July 21st, 2025',
129
- 'claude-3-7-sonnet-latest': 'February 19th, 2026',
130
- 'claude-3-7-sonnet-20250219': 'February 19th, 2026',
131
- 'claude-3-5-haiku-latest': 'February 19th, 2026',
132
- 'claude-3-5-haiku-20241022': 'February 19th, 2026',
133
- 'claude-opus-4-0': 'June 15th, 2026',
134
- 'claude-opus-4-20250514': 'June 15th, 2026',
135
- 'claude-sonnet-4-0': 'June 15th, 2026',
136
- 'claude-sonnet-4-20250514': 'June 15th, 2026',
137
- 'claude-opus-4-1': 'August 5th, 2026',
138
- 'claude-opus-4-1-20250805': 'August 5th, 2026',
139
- 'claude-mythos-preview': 'June 30th, 2026',
140
- };
119
+ const DEPRECATED_MODELS = {};
141
120
  const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-mythos-preview', 'claude-opus-4-6'];
142
121
  Messages.Batches = Batches;
143
122
  //# sourceMappingURL=messages.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.mjs","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAGtF,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAElD,OAAO,EAAE,YAAY,EAAE,mCAA+B;AAEtD,OAAO,EAAE,qBAAqB,EAAE,mDAA+C;AAC/E,OAAO,EAAE,aAAa,EAAE,oCAAgC;AACxD,OAAO,EACL,YAAY,GAIb,6BAAyB;AAC1B,OAAO,KAAK,UAAU,sBAAkB;AACxC,OAAO,EAGL,OAAO,GAWR,sBAAkB;AAGnB,OAAO,EAAE,yBAAyB,EAAE,qCAAiC;AAErE,MAAM,OAAO,QAAS,SAAQ,WAAW;IAAzC;;QACE,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAkKrE,CAAC;IApIC,MAAM,CACJ,MAA2B,EAC3B,OAAwB;QAExB,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC5C,IAAI,IAAI,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CACV,cAAc,IAAI,CAAC,KAAK,iDACtB,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAC9B,gIAAgI,CACjI,CAAC;QACJ,CAAC;QACD,IACE,oCAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;YACzD,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAChC,CAAC;YACD,OAAO,CAAC,IAAI,CACV,qBAAqB,IAAI,CAAC,KAAK,oNAAoN,CACpP,CAAC;QACJ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AExB,OAAO,aAAa,CAAC,aAAa,CAChC,IAAI,EACJ,IAA+B,EAC/B,OAAO,EACP,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,MAAgC,EAAE,OAAwB;QACpE,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE;YACpD,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,YAAY,CAAC;gBACpB,EAAE,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,2BAA2B,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE;gBAC/F,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF;AAglCD,MAAM,iBAAiB,GAEnB,EAAE,CAAC;AAEP,MAAM,oCAAoC,GAAY,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC;AA4wEnG,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC"}
package/src/client.ts CHANGED
@@ -9,6 +9,11 @@ export type { Logger, LogLevel } from './internal/utils/log';
9
9
  import { castToError, isAbortError } from './internal/errors';
10
10
  import type { APIResponseProps } from './internal/parse';
11
11
  import { getPlatformHeaders } from './internal/detect-platform';
12
+ import {
13
+ armAbandonmentBackstop,
14
+ registerRequestSignalCleanup,
15
+ releaseRequestSignal,
16
+ } from './internal/request-signal';
12
17
  import * as Shims from './internal/shims';
13
18
  import * as Opts from './internal/request-options';
14
19
  import { stringifyQuery } from './internal/utils/query';
@@ -67,10 +72,12 @@ import {
67
72
  BetaAPIError,
68
73
  BetaAuthenticationError,
69
74
  BetaBillingError,
75
+ BetaCurrency,
70
76
  BetaError,
71
77
  BetaErrorResponse,
72
78
  BetaGatewayTimeoutError,
73
79
  BetaInvalidRequestError,
80
+ BetaMonetaryAmount,
74
81
  BetaNotFoundError,
75
82
  BetaOverloadedError,
76
83
  BetaPermissionError,
@@ -862,8 +869,8 @@ export class BaseAnthropic {
862
869
  return stringifyQuery(query);
863
870
  }
864
871
 
865
- private getUserAgent(): string {
866
- return `${this.constructor.name}/JS ${VERSION}`;
872
+ protected getUserAgent(): string {
873
+ return `Anthropic/JS ${VERSION}`;
867
874
  }
868
875
 
869
876
  protected defaultIdempotencyKey(): string {
@@ -1057,6 +1064,7 @@ export class BaseAnthropic {
1057
1064
  const headersTime = Date.now();
1058
1065
 
1059
1066
  if (response instanceof globalThis.Error) {
1067
+ releaseRequestSignal(controller);
1060
1068
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
1061
1069
  if (options.signal?.aborted) {
1062
1070
  throw new Errors.APIUserAbortError();
@@ -1142,6 +1150,7 @@ export class BaseAnthropic {
1142
1150
 
1143
1151
  // We don't need the body of this response.
1144
1152
  await Shims.CancelReadableStream(response.body);
1153
+ releaseRequestSignal(controller);
1145
1154
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
1146
1155
  loggerFor(this).debug(
1147
1156
  `[${requestLogID}] response error (${retryMessage})`,
@@ -1181,6 +1190,7 @@ export class BaseAnthropic {
1181
1190
  }),
1182
1191
  );
1183
1192
 
1193
+ releaseRequestSignal(controller);
1184
1194
  const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
1185
1195
  throw err;
1186
1196
  }
@@ -1197,6 +1207,7 @@ export class BaseAnthropic {
1197
1207
  }),
1198
1208
  );
1199
1209
 
1210
+ armAbandonmentBackstop(response.body ?? response, controller);
1200
1211
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
1201
1212
  }
1202
1213
 
@@ -1240,7 +1251,10 @@ export class BaseAnthropic {
1240
1251
  // the lifetime of the signal. Using `.bind()` only retains a reference to the
1241
1252
  // controller itself.
1242
1253
  const abort = this._makeAbort(controller);
1243
- if (signal) signal.addEventListener('abort', abort, { once: true });
1254
+ if (signal) {
1255
+ signal.addEventListener('abort', abort, { once: true });
1256
+ registerRequestSignalCleanup(controller, signal, abort);
1257
+ }
1244
1258
 
1245
1259
  const isReadableBody =
1246
1260
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -1817,10 +1831,12 @@ export declare namespace Anthropic {
1817
1831
  type BetaAPIError as BetaAPIError,
1818
1832
  type BetaAuthenticationError as BetaAuthenticationError,
1819
1833
  type BetaBillingError as BetaBillingError,
1834
+ type BetaCurrency as BetaCurrency,
1820
1835
  type BetaError as BetaError,
1821
1836
  type BetaErrorResponse as BetaErrorResponse,
1822
1837
  type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
1823
1838
  type BetaInvalidRequestError as BetaInvalidRequestError,
1839
+ type BetaMonetaryAmount as BetaMonetaryAmount,
1824
1840
  type BetaNotFoundError as BetaNotFoundError,
1825
1841
  type BetaOverloadedError as BetaOverloadedError,
1826
1842
  type BetaPermissionError as BetaPermissionError,
@@ -11,6 +11,7 @@ import type { BaseAnthropic } from '../client';
11
11
 
12
12
  import { APIError } from './error';
13
13
  import type { ErrorType } from '../resources/shared';
14
+ import { releaseRequestSignal } from '../internal/request-signal';
14
15
 
15
16
  type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;
16
17
 
@@ -149,6 +150,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
149
150
  } finally {
150
151
  // If the user `break`s, abort the ongoing request.
151
152
  if (!done) controller.abort();
153
+ releaseRequestSignal(controller);
152
154
  }
153
155
  }
154
156
 
@@ -200,6 +202,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
200
202
  } finally {
201
203
  // If the user `break`s, abort the ongoing request.
202
204
  if (!done) controller.abort();
205
+ releaseRequestSignal(controller);
203
206
  }
204
207
  }
205
208
 
@@ -4,12 +4,7 @@
4
4
  * Model-specific timeout constraints for non-streaming requests
5
5
  */
6
6
  export const MODEL_NONSTREAMING_TOKENS: Record<string, number> = {
7
- 'claude-opus-4-20250514': 8192,
8
- 'claude-opus-4-0': 8192,
9
- 'claude-4-opus-20250514': 8192,
10
- 'anthropic.claude-opus-4-20250514-v1:0': 8192,
11
7
  'claude-opus-4@20250514': 8192,
12
- 'claude-opus-4-1-20250805': 8192,
13
8
  'anthropic.claude-opus-4-1-20250805-v1:0': 8192,
14
9
  'claude-opus-4-1@20250805': 8192,
15
10
  };
@@ -4,6 +4,7 @@ import type { FinalRequestOptions } from './request-options';
4
4
  import { Stream } from '../core/streaming';
5
5
  import { type BaseAnthropic } from '../client';
6
6
  import { formatRequestDetails, loggerFor } from './utils/log';
7
+ import { releaseRequestSignal } from './request-signal';
7
8
  import type { AbstractPage } from '../core/pagination';
8
9
 
9
10
  export type APIResponseProps = {
@@ -55,7 +56,15 @@ export async function defaultParseResponse<T>(
55
56
 
56
57
  const text = await response.text();
57
58
  return text as unknown as T;
58
- })();
59
+ })().finally(() => {
60
+ // The body is settled (or parsing threw), so the caller-signal abort
61
+ // listener has nothing left to cancel. Streams release in their own
62
+ // teardown; a raw Response (`__binaryResponse`) keeps the listener so
63
+ // aborting an in-flight download still works.
64
+ if (!props.options.stream && !props.options.__binaryResponse) {
65
+ releaseRequestSignal(props.controller);
66
+ }
67
+ });
59
68
  loggerFor(client).debug(
60
69
  `[${requestLogID}] response parsed`,
61
70
  formatRequestDetails({
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Tracks the removal of the per-request abort listener that
3
+ * `fetchWithTimeout` attaches to a caller-provided signal, so the listener's
4
+ * lifetime matches the request instead of the signal.
5
+ *
6
+ * Without removal, a long-lived signal (e.g. one AbortController reused for
7
+ * a whole session) accumulates one `{ once: true }` listener plus its bound
8
+ * AbortController per HTTP attempt until the signal fires or is collected,
9
+ * and Node warns at the 11th listener. The listener must survive until the
10
+ * response body is settled - removing it when fetch resolves (headers) would
11
+ * break aborting an in-flight body read - so the code that finishes the body
12
+ * (response parsing, stream teardown, retry/error handling) calls
13
+ * `releaseRequestSignal` with the request's controller.
14
+ */
15
+ const cleanups = new WeakMap<AbortController, () => void>();
16
+
17
+ // Backstop for requests that never reach an explicit release point: a caller
18
+ // that partially iterates a stream (or receives a raw binary Response) and
19
+ // drops the reference never completes, errors, or cancels it, so the only
20
+ // remaining lifecycle event is the response being collected. Finalization
21
+ // timing is GC-driven and not guaranteed, so this only bounds abandonment -
22
+ // the explicit release calls stay the primary cleanup. The held value must
23
+ // not reference the response, or it could never be collected. Typed
24
+ // structurally because the compiler lib is es2020.
25
+ type AbandonmentRegistry = {
26
+ register(target: object, heldValue: AbortController, token: object): void;
27
+ unregister(token: object): void;
28
+ };
29
+
30
+ const registry: AbandonmentRegistry | null =
31
+ typeof (globalThis as any).FinalizationRegistry === 'function' ?
32
+ new (globalThis as any).FinalizationRegistry((controller: AbortController) =>
33
+ releaseRequestSignal(controller),
34
+ )
35
+ : null;
36
+
37
+ // Module-scope factory so the cleanup closure captures exactly the signal and
38
+ // the listener - built at the `fetchWithTimeout` call site it would share that
39
+ // scope's context and retain the request body for as long as the cleanup is
40
+ // held (same reason `_makeAbort` exists in client.ts).
41
+ function makeCleanup(signal: AbortSignal, listener: () => void): () => void {
42
+ return () => signal.removeEventListener('abort', listener);
43
+ }
44
+
45
+ export function registerRequestSignalCleanup(
46
+ controller: AbortController,
47
+ signal: AbortSignal,
48
+ listener: () => void,
49
+ ): void {
50
+ cleanups.set(controller, makeCleanup(signal, listener));
51
+ }
52
+
53
+ // The registered target is the response BODY, not the Response: a caller can
54
+ // keep a reader on the body and drop the Response wrapper (`.asResponse()`),
55
+ // and the listener must survive for as long as anything can still read - the
56
+ // body is what a live read keeps alive.
57
+ export function armAbandonmentBackstop(body: object, controller: AbortController): void {
58
+ if (cleanups.has(controller)) registry?.register(body, controller, controller);
59
+ }
60
+
61
+ export function releaseRequestSignal(controller: AbortController): void {
62
+ const cleanup = cleanups.get(controller);
63
+ if (cleanup) {
64
+ cleanups.delete(controller);
65
+ registry?.unregister(controller);
66
+ cleanup();
67
+ }
68
+ }
@@ -610,6 +610,10 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
610
610
  snapshot.usage.iterations = event.usage.iterations;
611
611
  }
612
612
 
613
+ if (event.usage.fallback_credit != null) {
614
+ snapshot.usage.fallback_credit = event.usage.fallback_credit;
615
+ }
616
+
613
617
  return snapshot;
614
618
  case 'content_block_start':
615
619
  snapshot.content.push(event.content_block);
@@ -10,6 +10,7 @@ import type { AnthropicBeta } from '../resources/beta/beta';
10
10
  import type {
11
11
  BetaContentBlockParam,
12
12
  BetaFallbackBlock,
13
+ BetaFallbackCreditTokenParam,
13
14
  BetaFallbackMessageIterationUsage,
14
15
  BetaFallbackParam,
15
16
  BetaMessage,
@@ -31,7 +32,7 @@ export { BetaFallbackState } from '../internal/request-options';
31
32
  const encoder = new TextEncoder();
32
33
 
33
34
  /** Betas sent by default; override with {@link BetaRefusalFallbackOptions.betas}. */
34
- const DEFAULT_BETAS: readonly AnthropicBeta[] = ['fallback-credit-2026-06-01'];
35
+ const DEFAULT_BETAS: readonly AnthropicBeta[] = ['fallback-credit-2026-07-01'];
35
36
 
36
37
  /**
37
38
  * Remove `fallback` blocks replayed in history. They only parse under the
@@ -50,6 +51,42 @@ function stripFallbackBlocks(body: MessageCreateParams): MessageCreateParams {
50
51
  return { ...body, messages };
51
52
  }
52
53
 
54
+ /**
55
+ * Apply one chain entry to the original request params as a patch: a field
56
+ * set to a value overrides the original, a field explicitly `null` removes
57
+ * the field from the retried request, and an absent (or `undefined`) field
58
+ * keeps the original value. `output_config` patches one level deep — its
59
+ * subfields follow the same set/`null`/absent rules against the original
60
+ * `output_config` (created if the entry sets any subfield). Every hop patches
61
+ * the original params — never a previous hop's patched body — and `body` is
62
+ * never mutated.
63
+ */
64
+ function applyFallbackPatch(body: MessageCreateParams, entry: BetaFallbackParam): MessageCreateParams {
65
+ const patched = { ...body } as Record<string, unknown>;
66
+ for (const [key, value] of Object.entries(entry)) {
67
+ if (key === 'output_config' && value != null) {
68
+ const merged = { ...((patched[key] as Record<string, unknown> | undefined) ?? {}) };
69
+ for (const [subKey, subValue] of Object.entries(value)) {
70
+ patchField(merged, subKey, subValue);
71
+ }
72
+ patchField(patched, key, Object.keys(merged).length ? merged : null);
73
+ } else {
74
+ patchField(patched, key, value);
75
+ }
76
+ }
77
+ return patched as unknown as MessageCreateParams;
78
+ }
79
+
80
+ /** Set/`null`-unset/absent-keep one field on `target` (mutated). */
81
+ function patchField(target: Record<string, unknown>, key: string, value: unknown): void {
82
+ if (value === undefined) return;
83
+ if (value === null) {
84
+ delete target[key];
85
+ } else {
86
+ target[key] = value;
87
+ }
88
+ }
89
+
53
90
  /** Why {@link BetaRefusalFallbackOptions.onError} fired. */
54
91
  export type BetaRefusalFallbackError =
55
92
  | {
@@ -83,7 +120,7 @@ export interface BetaRefusalFallbackOptions {
83
120
  * Betas added to the `anthropic-beta` header of every `/v1/messages`
84
121
  * request this middleware handles — the original request included, since
85
122
  * refusals only carry a `fallback_credit_token` when the beta is enabled.
86
- * Defaults to `['fallback-credit-2026-06-01']`; pass `[]` to send none.
123
+ * Defaults to `['fallback-credit-2026-07-01']`; pass `[]` to send none.
87
124
  */
88
125
  betas?: readonly AnthropicBeta[] | undefined;
89
126
 
@@ -100,8 +137,10 @@ export interface BetaRefusalFallbackOptions {
100
137
  * Middleware that retries refused `/v1/messages` requests down a fallback chain.
101
138
  *
102
139
  * Non-streaming: when a response comes back with `stop_reason: 'refusal'`, the
103
- * request is retried with each entry of `fallbacks` merged over the original
104
- * params passing along the refusal's `fallback_credit_token` until a model
140
+ * request is retried with each entry of `fallbacks` applied as a patch to the
141
+ * original params (a set field overrides, an explicit `null` unsets, an absent
142
+ * field keeps the original value; entries never patch each other's requests)
143
+ * — passing along the refusal's `fallback_credit_token` — until a model
105
144
  * accepts or the chain is exhausted. A message served by a fallback carries a
106
145
  * `fallback` content block prepended at each model boundary — the same seam
107
146
  * block shape the server-side `fallbacks` param places in `content`, though
@@ -171,7 +210,7 @@ export function betaRefusalFallbackMiddleware(
171
210
  if ((ctx.options.body as MessageCreateParams).fallbacks != null) {
172
211
  throw new AnthropicError(
173
212
  'Sending the `fallbacks:` request param is not supported when using the `betaRefusalFallbackMiddleware`. ' +
174
- 'You should either remove the middleware and send `fallbacks:` with the `server-side-fallback-2026-06-01` beta header to let the API handle refusal fallbacks, ' +
213
+ 'You should either remove the middleware and send `fallbacks:` with the `server-side-fallback-2026-07-01` beta header to let the API handle refusal fallbacks, ' +
175
214
  "or omit the `fallbacks:` param if you'd like `betaRefusalFallbackMiddleware` to handle fallbacks on the client side.",
176
215
  );
177
216
  }
@@ -208,15 +247,12 @@ export function betaRefusalFallbackMiddleware(
208
247
  }
209
248
  };
210
249
 
250
+ const initialBody = startIndex === -1 ? body : applyFallbackPatch(body, fallbacks[startIndex]!);
251
+
211
252
  // a non-string body can't be respliced or redeemed against — leave the
212
253
  // request untouched (the streaming path stands down on it below too)
213
254
  const initialRequest =
214
- typeof request.body !== 'string' ?
215
- request
216
- : {
217
- ...request,
218
- body: JSON.stringify(startIndex === -1 ? body : { ...body, ...fallbacks[startIndex] }),
219
- };
255
+ typeof request.body !== 'string' ? request : { ...request, body: JSON.stringify(initialBody) };
220
256
 
221
257
  const response = await next(initialRequest);
222
258
  if (!response.ok) {
@@ -248,7 +284,7 @@ export function betaRefusalFallbackMiddleware(
248
284
  let res = response;
249
285
  // The model the current hop was requested as — the caller's spelling, not
250
286
  // the server's `message.model` echo; the seam block's `from` carries it.
251
- let requestedModel = (startIndex === -1 ? body : { ...body, ...fallbacks[startIndex] }).model;
287
+ let requestedModel = initialBody.model;
252
288
  const fallbackBlocks: BetaFallbackBlock[] = [];
253
289
  while (index < fallbacks.length - 1) {
254
290
  const message = await ctx.parse<BetaMessage | null>(res);
@@ -274,10 +310,9 @@ export function betaRefusalFallbackMiddleware(
274
310
  res = await next({
275
311
  ...request,
276
312
  body: JSON.stringify({
277
- ...body,
278
- ...entry,
313
+ ...applyFallbackPatch(body, entry),
279
314
  ...(message.stop_details?.fallback_credit_token ?
280
- { fallback_credit_token: message.stop_details.fallback_credit_token }
315
+ { fallback_credit_token: creditTokenParam(message.stop_details.fallback_credit_token) }
281
316
  : undefined),
282
317
  }),
283
318
  });
@@ -759,6 +794,16 @@ class BlockTracker {
759
794
 
760
795
  // --- fallback request construction (appended-assistant continuation) -------
761
796
 
797
+ /**
798
+ * Object form of the redeemed credit token. `best_effort` keeps the retry
799
+ * served if the token layer rejects it — the retry then proceeds at normal
800
+ * price and the outcome lands on `usage.fallback_credit` — where the
801
+ * bare-string (`strict`) form would 400 the whole request.
802
+ */
803
+ function creditTokenParam(token: string): BetaFallbackCreditTokenParam {
804
+ return { token, mode: 'best_effort' };
805
+ }
806
+
762
807
  function buildFallbackRequest(
763
808
  orig: APIRequest,
764
809
  {
@@ -775,7 +820,7 @@ function buildFallbackRequest(
775
820
  const body = JSON.parse(orig.body as string);
776
821
 
777
822
  body.model = model;
778
- body.fallback_credit_token = creditToken;
823
+ body.fallback_credit_token = creditTokenParam(creditToken);
779
824
 
780
825
  // Append the continuation (decided by the chain loop) as a trailing
781
826
  // assistant turn; everything else must stay identical to the refused
@@ -103,6 +103,7 @@ export function accumulateManagedAgentsEvent(
103
103
  case 'session.error':
104
104
  case 'session.updated':
105
105
  case 'session.deleted':
106
+ case 'session.usage':
106
107
  case 'session.status_running':
107
108
  case 'session.status_idle':
108
109
  case 'session.status_rescheduled':
@@ -2,7 +2,18 @@ import { BetaRunnableTool } from './BetaRunnableTool';
2
2
  import { ToolError } from './ToolError';
3
3
  import { Anthropic } from '../..';
4
4
  import { AnthropicError } from '../../core/error';
5
- import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from '../../resources/beta';
5
+ import {
6
+ BetaContentBlockParam,
7
+ BetaMessage,
8
+ BetaMessageParam,
9
+ BetaRequestToolAdditionBlock,
10
+ BetaRequestToolRemovalBlock,
11
+ BetaToolChangeMCPToolReference,
12
+ BetaToolChangeMCPToolsetReference,
13
+ BetaToolChangeToolReference,
14
+ BetaToolUnion,
15
+ MessageCreateParams,
16
+ } from '../../resources/beta';
6
17
  import { BetaMessageStream } from '../BetaMessageStream';
7
18
  import { RequestOptions } from '../../internal/request-options';
8
19
  import { buildHeaders } from '../../internal/headers';
@@ -467,16 +478,14 @@ async function generateToolResponse(
467
478
  return null;
468
479
  }
469
480
 
481
+ const available = availableToolNames(params);
470
482
  const toolResults = await Promise.all(
471
483
  toolUseBlocks.map(async (toolUse) => {
472
484
  const tool = params.tools.find((t) => ('name' in t ? t.name : t.mcp_server_name) === toolUse.name);
473
- if (!tool || !('run' in tool)) {
474
- return {
475
- type: 'tool_result' as const,
476
- tool_use_id: toolUse.id,
477
- content: `Error: Tool '${toolUse.name}' not found`,
478
- is_error: true,
479
- };
485
+ // A `tool_removal` is only a hint to the model, which may still emit a tool_use for a
486
+ // withdrawn tool — treat those exactly like a tool that was never defined.
487
+ if (!tool || !('run' in tool) || !available.has(toolUse.name)) {
488
+ return toolNotFoundResult(toolUse);
480
489
  }
481
490
 
482
491
  try {
@@ -515,6 +524,90 @@ async function generateToolResponse(
515
524
  };
516
525
  }
517
526
 
527
+ function toolNotFoundResult(toolUse: { id: string; name: string }) {
528
+ return {
529
+ type: 'tool_result' as const,
530
+ tool_use_id: toolUse.id,
531
+ content: `Error: Tool '${toolUse.name}' not found`,
532
+ is_error: true,
533
+ };
534
+ }
535
+
536
+ /**
537
+ * Computes the names of locally runnable tools that are still available for the assistant
538
+ * turn being answered, by folding `tool_removal` / `tool_addition` blocks from the
539
+ * `role: "system"` messages over the runnable tools. The assistant turn being answered is
540
+ * terminal-or-absent and only `system` messages are inspected, so folding the whole current
541
+ * history is exactly folding the messages preceding that turn — call this before appending
542
+ * anything after it. MCP references are ignored — those tools are executed server-side and
543
+ * never dispatched by this runner.
544
+ */
545
+ function availableToolNames(params: BetaToolRunnerParams): Set<string> {
546
+ const available = new Set<string>();
547
+ for (const tool of params.tools) {
548
+ if ('run' in tool) {
549
+ available.add(tool.name);
550
+ }
551
+ }
552
+
553
+ for (const message of params.messages) {
554
+ if (message.role !== 'system' || typeof message.content === 'string') {
555
+ continue;
556
+ }
557
+ for (const block of message.content) {
558
+ applyToolChange(block, available);
559
+ }
560
+ }
561
+ return available;
562
+ }
563
+
564
+ function applyToolChange(block: BetaContentBlockParam, available: Set<string>): void {
565
+ switch (block.type) {
566
+ case 'tool_removal':
567
+ case 'tool_addition':
568
+ applyToolReference(block, available);
569
+ break;
570
+ case 'mid_conv_system':
571
+ // A `mid_conv_system` block's content is limited by the API schema to
572
+ // text / tool_addition / tool_removal, so we walk exactly one level — no recursion.
573
+ for (const inner of block.content) {
574
+ if (inner.type === 'tool_removal' || inner.type === 'tool_addition') {
575
+ applyToolReference(inner, available);
576
+ }
577
+ }
578
+ break;
579
+ default:
580
+ // Other and unknown/newer block types leave the set untouched (forward compatibility).
581
+ break;
582
+ }
583
+ }
584
+
585
+ function applyToolReference(
586
+ block: BetaRequestToolAdditionBlock | BetaRequestToolRemovalBlock,
587
+ available: Set<string>,
588
+ ): void {
589
+ const name = referencedToolName(block.tool);
590
+ if (name === undefined) return;
591
+ if (block.type === 'tool_removal') {
592
+ available.delete(name);
593
+ } else {
594
+ available.add(name);
595
+ }
596
+ }
597
+
598
+ function referencedToolName(
599
+ ref: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference,
600
+ ): string | undefined {
601
+ switch (ref.type) {
602
+ case 'tool_reference':
603
+ return ref.name;
604
+ default:
605
+ // mcp_tool_reference / mcp_toolset_reference run server-side; unknown reference
606
+ // types are ignored rather than rejected.
607
+ return undefined;
608
+ }
609
+ }
610
+
518
611
  // vendored from typefest just to make things look a bit nicer on hover
519
612
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
520
613