@anthropic-ai/sdk 0.102.0 → 0.104.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 (241) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/client.d.mts +30 -7
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +30 -7
  5. package/client.d.ts.map +1 -1
  6. package/client.js +48 -25
  7. package/client.js.map +1 -1
  8. package/client.mjs +47 -24
  9. package/client.mjs.map +1 -1
  10. package/core/middleware.d.mts +42 -5
  11. package/core/middleware.d.mts.map +1 -1
  12. package/core/middleware.d.ts +42 -5
  13. package/core/middleware.d.ts.map +1 -1
  14. package/core/middleware.js +14 -7
  15. package/core/middleware.js.map +1 -1
  16. package/core/middleware.mjs +14 -7
  17. package/core/middleware.mjs.map +1 -1
  18. package/core/streaming.d.mts +9 -0
  19. package/core/streaming.d.mts.map +1 -1
  20. package/core/streaming.d.ts +9 -0
  21. package/core/streaming.d.ts.map +1 -1
  22. package/core/streaming.js +11 -0
  23. package/core/streaming.js.map +1 -1
  24. package/core/streaming.mjs +11 -0
  25. package/core/streaming.mjs.map +1 -1
  26. package/index.d.mts +1 -0
  27. package/index.d.mts.map +1 -1
  28. package/index.d.ts +1 -0
  29. package/index.d.ts.map +1 -1
  30. package/index.js +4 -1
  31. package/index.js.map +1 -1
  32. package/index.mjs +1 -0
  33. package/index.mjs.map +1 -1
  34. package/internal/parse.d.mts.map +1 -1
  35. package/internal/parse.d.ts.map +1 -1
  36. package/internal/parse.js +0 -3
  37. package/internal/parse.js.map +1 -1
  38. package/internal/parse.mjs +0 -3
  39. package/internal/parse.mjs.map +1 -1
  40. package/internal/request-options.d.mts +46 -3
  41. package/internal/request-options.d.mts.map +1 -1
  42. package/internal/request-options.d.ts +46 -3
  43. package/internal/request-options.d.ts.map +1 -1
  44. package/internal/request-options.js +12 -1
  45. package/internal/request-options.js.map +1 -1
  46. package/internal/request-options.mjs +10 -0
  47. package/internal/request-options.mjs.map +1 -1
  48. package/internal/utils/log.d.mts +11 -1
  49. package/internal/utils/log.d.mts.map +1 -1
  50. package/internal/utils/log.d.ts +11 -1
  51. package/internal/utils/log.d.ts.map +1 -1
  52. package/internal/utils/log.js +34 -9
  53. package/internal/utils/log.js.map +1 -1
  54. package/internal/utils/log.mjs +32 -8
  55. package/internal/utils/log.mjs.map +1 -1
  56. package/lib/BetaMessageStream.d.mts.map +1 -1
  57. package/lib/BetaMessageStream.d.ts.map +1 -1
  58. package/lib/BetaMessageStream.js +5 -0
  59. package/lib/BetaMessageStream.js.map +1 -1
  60. package/lib/BetaMessageStream.mjs +5 -0
  61. package/lib/BetaMessageStream.mjs.map +1 -1
  62. package/lib/middleware.d.mts +96 -0
  63. package/lib/middleware.d.mts.map +1 -0
  64. package/lib/middleware.d.ts +96 -0
  65. package/lib/middleware.d.ts.map +1 -0
  66. package/lib/middleware.js +703 -0
  67. package/lib/middleware.js.map +1 -0
  68. package/lib/middleware.mjs +698 -0
  69. package/lib/middleware.mjs.map +1 -0
  70. package/lib/tools/BetaToolRunner.d.mts +1 -1
  71. package/lib/tools/BetaToolRunner.d.mts.map +1 -1
  72. package/lib/tools/BetaToolRunner.d.ts +1 -1
  73. package/lib/tools/BetaToolRunner.d.ts.map +1 -1
  74. package/lib/tools/BetaToolRunner.js +10 -2
  75. package/lib/tools/BetaToolRunner.js.map +1 -1
  76. package/lib/tools/BetaToolRunner.mjs +10 -2
  77. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  78. package/package.json +23 -1
  79. package/resources/beta/agents/agents.d.mts +1 -1
  80. package/resources/beta/agents/agents.d.mts.map +1 -1
  81. package/resources/beta/agents/agents.d.ts +1 -1
  82. package/resources/beta/agents/agents.d.ts.map +1 -1
  83. package/resources/beta/agents/agents.js.map +1 -1
  84. package/resources/beta/agents/agents.mjs.map +1 -1
  85. package/resources/beta/beta.d.mts +13 -5
  86. package/resources/beta/beta.d.mts.map +1 -1
  87. package/resources/beta/beta.d.ts +13 -5
  88. package/resources/beta/beta.d.ts.map +1 -1
  89. package/resources/beta/beta.js +8 -0
  90. package/resources/beta/beta.js.map +1 -1
  91. package/resources/beta/beta.mjs +8 -0
  92. package/resources/beta/beta.mjs.map +1 -1
  93. package/resources/beta/deployment-runs.d.mts +306 -0
  94. package/resources/beta/deployment-runs.d.mts.map +1 -0
  95. package/resources/beta/deployment-runs.d.ts +306 -0
  96. package/resources/beta/deployment-runs.d.ts.map +1 -0
  97. package/resources/beta/deployment-runs.js +55 -0
  98. package/resources/beta/deployment-runs.js.map +1 -0
  99. package/resources/beta/deployment-runs.mjs +51 -0
  100. package/resources/beta/deployment-runs.mjs.map +1 -0
  101. package/resources/beta/deployments.d.mts +671 -0
  102. package/resources/beta/deployments.d.mts.map +1 -0
  103. package/resources/beta/deployments.d.ts +671 -0
  104. package/resources/beta/deployments.d.ts.map +1 -0
  105. package/resources/beta/deployments.js +184 -0
  106. package/resources/beta/deployments.js.map +1 -0
  107. package/resources/beta/deployments.mjs +180 -0
  108. package/resources/beta/deployments.mjs.map +1 -0
  109. package/resources/beta/index.d.mts +4 -2
  110. package/resources/beta/index.d.mts.map +1 -1
  111. package/resources/beta/index.d.ts +4 -2
  112. package/resources/beta/index.d.ts.map +1 -1
  113. package/resources/beta/index.js +5 -1
  114. package/resources/beta/index.js.map +1 -1
  115. package/resources/beta/index.mjs +2 -0
  116. package/resources/beta/index.mjs.map +1 -1
  117. package/resources/beta/messages/batches.d.mts +28 -0
  118. package/resources/beta/messages/batches.d.mts.map +1 -1
  119. package/resources/beta/messages/batches.d.ts +28 -0
  120. package/resources/beta/messages/batches.d.ts.map +1 -1
  121. package/resources/beta/messages/index.d.mts +1 -1
  122. package/resources/beta/messages/index.d.mts.map +1 -1
  123. package/resources/beta/messages/index.d.ts +1 -1
  124. package/resources/beta/messages/index.d.ts.map +1 -1
  125. package/resources/beta/messages/index.js.map +1 -1
  126. package/resources/beta/messages/index.mjs.map +1 -1
  127. package/resources/beta/messages/messages.d.mts +234 -6
  128. package/resources/beta/messages/messages.d.mts.map +1 -1
  129. package/resources/beta/messages/messages.d.ts +234 -6
  130. package/resources/beta/messages/messages.d.ts.map +1 -1
  131. package/resources/beta/messages/messages.js +7 -0
  132. package/resources/beta/messages/messages.js.map +1 -1
  133. package/resources/beta/messages/messages.mjs +7 -0
  134. package/resources/beta/messages/messages.mjs.map +1 -1
  135. package/resources/beta/models.d.mts +6 -0
  136. package/resources/beta/models.d.mts.map +1 -1
  137. package/resources/beta/models.d.ts +6 -0
  138. package/resources/beta/models.d.ts.map +1 -1
  139. package/resources/beta/sessions/events.d.mts +44 -6
  140. package/resources/beta/sessions/events.d.mts.map +1 -1
  141. package/resources/beta/sessions/events.d.ts +44 -6
  142. package/resources/beta/sessions/events.d.ts.map +1 -1
  143. package/resources/beta/sessions/events.js.map +1 -1
  144. package/resources/beta/sessions/events.mjs.map +1 -1
  145. package/resources/beta/sessions/index.d.mts +2 -2
  146. package/resources/beta/sessions/index.d.mts.map +1 -1
  147. package/resources/beta/sessions/index.d.ts +2 -2
  148. package/resources/beta/sessions/index.d.ts.map +1 -1
  149. package/resources/beta/sessions/index.js.map +1 -1
  150. package/resources/beta/sessions/index.mjs.map +1 -1
  151. package/resources/beta/sessions/sessions.d.mts +41 -3
  152. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  153. package/resources/beta/sessions/sessions.d.ts +41 -3
  154. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  155. package/resources/beta/sessions/sessions.js.map +1 -1
  156. package/resources/beta/sessions/sessions.mjs.map +1 -1
  157. package/resources/beta/sessions/threads/threads.d.mts +1 -1
  158. package/resources/beta/sessions/threads/threads.d.mts.map +1 -1
  159. package/resources/beta/sessions/threads/threads.d.ts +1 -1
  160. package/resources/beta/sessions/threads/threads.d.ts.map +1 -1
  161. package/resources/beta/sessions/threads/threads.js.map +1 -1
  162. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  163. package/resources/beta/vaults/credentials.d.mts +97 -4
  164. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  165. package/resources/beta/vaults/credentials.d.ts +97 -4
  166. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  167. package/resources/beta/vaults/index.d.mts +1 -1
  168. package/resources/beta/vaults/index.d.mts.map +1 -1
  169. package/resources/beta/vaults/index.d.ts +1 -1
  170. package/resources/beta/vaults/index.d.ts.map +1 -1
  171. package/resources/beta/vaults/index.js.map +1 -1
  172. package/resources/beta/vaults/index.mjs.map +1 -1
  173. package/resources/beta/vaults/vaults.d.mts +2 -2
  174. package/resources/beta/vaults/vaults.d.mts.map +1 -1
  175. package/resources/beta/vaults/vaults.d.ts +2 -2
  176. package/resources/beta/vaults/vaults.d.ts.map +1 -1
  177. package/resources/beta/vaults/vaults.js.map +1 -1
  178. package/resources/beta/vaults/vaults.mjs.map +1 -1
  179. package/resources/beta/webhooks.d.mts +12 -0
  180. package/resources/beta/webhooks.d.mts.map +1 -1
  181. package/resources/beta/webhooks.d.ts +12 -0
  182. package/resources/beta/webhooks.d.ts.map +1 -1
  183. package/resources/messages/messages.d.mts +2 -2
  184. package/resources/messages/messages.d.mts.map +1 -1
  185. package/resources/messages/messages.d.ts +2 -2
  186. package/resources/messages/messages.d.ts.map +1 -1
  187. package/resources/messages/messages.js +1 -0
  188. package/resources/messages/messages.js.map +1 -1
  189. package/resources/messages/messages.mjs +1 -0
  190. package/resources/messages/messages.mjs.map +1 -1
  191. package/src/client.ts +55 -24
  192. package/src/core/middleware.ts +53 -7
  193. package/src/core/streaming.ts +15 -0
  194. package/src/index.ts +6 -0
  195. package/src/internal/parse.ts +0 -4
  196. package/src/internal/request-options.ts +48 -3
  197. package/src/internal/utils/log.ts +39 -9
  198. package/src/lib/BetaMessageStream.ts +5 -0
  199. package/src/lib/middleware.ts +937 -0
  200. package/src/lib/tools/BetaToolRunner.ts +12 -3
  201. package/src/resources/beta/agents/agents.ts +1 -0
  202. package/src/resources/beta/beta.ts +171 -1
  203. package/src/resources/beta/deployment-runs.ts +441 -0
  204. package/src/resources/beta/deployments.ts +965 -0
  205. package/src/resources/beta/index.ts +80 -0
  206. package/src/resources/beta/messages/batches.ts +30 -0
  207. package/src/resources/beta/messages/index.ts +6 -0
  208. package/src/resources/beta/messages/messages.ts +279 -5
  209. package/src/resources/beta/models.ts +7 -0
  210. package/src/resources/beta/sessions/events.ts +59 -4
  211. package/src/resources/beta/sessions/index.ts +4 -0
  212. package/src/resources/beta/sessions/sessions.ts +52 -0
  213. package/src/resources/beta/sessions/threads/threads.ts +2 -1
  214. package/src/resources/beta/vaults/credentials.ts +134 -3
  215. package/src/resources/beta/vaults/index.ts +8 -0
  216. package/src/resources/beta/vaults/vaults.ts +16 -0
  217. package/src/resources/beta/webhooks.ts +15 -0
  218. package/src/resources/messages/messages.ts +4 -1
  219. package/src/tools/agent-toolset/node.browser.ts +90 -0
  220. package/src/tools/memory/node.browser.ts +64 -0
  221. package/src/version.ts +1 -1
  222. package/tools/agent-toolset/node.browser.d.mts +42 -0
  223. package/tools/agent-toolset/node.browser.d.mts.map +1 -0
  224. package/tools/agent-toolset/node.browser.d.ts +42 -0
  225. package/tools/agent-toolset/node.browser.d.ts.map +1 -0
  226. package/tools/agent-toolset/node.browser.js +81 -0
  227. package/tools/agent-toolset/node.browser.js.map +1 -0
  228. package/tools/agent-toolset/node.browser.mjs +66 -0
  229. package/tools/agent-toolset/node.browser.mjs.map +1 -0
  230. package/tools/memory/node.browser.d.mts +27 -0
  231. package/tools/memory/node.browser.d.mts.map +1 -0
  232. package/tools/memory/node.browser.d.ts +27 -0
  233. package/tools/memory/node.browser.d.ts.map +1 -0
  234. package/tools/memory/node.browser.js +49 -0
  235. package/tools/memory/node.browser.js.map +1 -0
  236. package/tools/memory/node.browser.mjs +44 -0
  237. package/tools/memory/node.browser.mjs.map +1 -0
  238. package/version.d.mts +1 -1
  239. package/version.d.ts +1 -1
  240. package/version.js +1 -1
  241. package/version.mjs +1 -1
@@ -63,6 +63,78 @@ export {
63
63
  type BetaPermissionError,
64
64
  type BetaRateLimitError,
65
65
  } from './beta';
66
+ export {
67
+ DeploymentRuns,
68
+ type BetaManagedAgentsAgentArchivedRunError,
69
+ type BetaManagedAgentsDeploymentRun,
70
+ type BetaManagedAgentsEnvironmentArchivedRunError,
71
+ type BetaManagedAgentsEnvironmentNotFoundRunError,
72
+ type BetaManagedAgentsFileNotFoundRunError,
73
+ type BetaManagedAgentsManualTriggerContext,
74
+ type BetaManagedAgentsMCPEgressBlockedRunError,
75
+ type BetaManagedAgentsMemoryStoreArchivedRunError,
76
+ type BetaManagedAgentsOrganizationDisabledRunError,
77
+ type BetaManagedAgentsScheduleTriggerContext,
78
+ type BetaManagedAgentsSelfHostedResourcesUnsupportedRunError,
79
+ type BetaManagedAgentsSessionCreationRejectedRunError,
80
+ type BetaManagedAgentsSessionRateLimitedRunError,
81
+ type BetaManagedAgentsSessionResourceNotFoundRunError,
82
+ type BetaManagedAgentsSkillNotFoundRunError,
83
+ type BetaManagedAgentsTriggerContext,
84
+ type BetaManagedAgentsTriggerType,
85
+ type BetaManagedAgentsUnknownRunError,
86
+ type BetaManagedAgentsVaultArchivedRunError,
87
+ type BetaManagedAgentsVaultNotFoundRunError,
88
+ type BetaManagedAgentsWorkspaceArchivedRunError,
89
+ type DeploymentRunRetrieveParams,
90
+ type DeploymentRunListParams,
91
+ type BetaManagedAgentsDeploymentRunsPageCursor,
92
+ } from './deployment-runs';
93
+ export {
94
+ Deployments,
95
+ type BetaManagedAgentsAgentArchivedDeploymentPausedReasonError,
96
+ type BetaManagedAgentsCronSchedule,
97
+ type BetaManagedAgentsCronScheduleParams,
98
+ type BetaManagedAgentsDeployment,
99
+ type BetaManagedAgentsDeploymentInitialEvent,
100
+ type BetaManagedAgentsDeploymentInitialEventParams,
101
+ type BetaManagedAgentsDeploymentPausedReason,
102
+ type BetaManagedAgentsDeploymentPausedReasonError,
103
+ type BetaManagedAgentsDeploymentStatus,
104
+ type BetaManagedAgentsDeploymentSystemMessageEvent,
105
+ type BetaManagedAgentsDeploymentUserDefineOutcomeEvent,
106
+ type BetaManagedAgentsDeploymentUserMessageEvent,
107
+ type BetaManagedAgentsEnvironmentArchivedDeploymentPausedReasonError,
108
+ type BetaManagedAgentsEnvironmentNotFoundDeploymentPausedReasonError,
109
+ type BetaManagedAgentsErrorDeploymentPausedReason,
110
+ type BetaManagedAgentsFileNotFoundDeploymentPausedReasonError,
111
+ type BetaManagedAgentsFileResourceConfig,
112
+ type BetaManagedAgentsGitHubRepositoryResourceConfig,
113
+ type BetaManagedAgentsManualDeploymentPausedReason,
114
+ type BetaManagedAgentsMCPEgressBlockedDeploymentPausedReasonError,
115
+ type BetaManagedAgentsMemoryStoreArchivedDeploymentPausedReasonError,
116
+ type BetaManagedAgentsMemoryStoreResourceConfig,
117
+ type BetaManagedAgentsOrganizationDisabledDeploymentPausedReasonError,
118
+ type BetaManagedAgentsSchedule,
119
+ type BetaManagedAgentsScheduleParams,
120
+ type BetaManagedAgentsSelfHostedResourcesUnsupportedDeploymentPausedReasonError,
121
+ type BetaManagedAgentsSessionResourceConfig,
122
+ type BetaManagedAgentsSessionResourceNotFoundDeploymentPausedReasonError,
123
+ type BetaManagedAgentsSkillNotFoundDeploymentPausedReasonError,
124
+ type BetaManagedAgentsUnknownDeploymentPausedReasonError,
125
+ type BetaManagedAgentsVaultArchivedDeploymentPausedReasonError,
126
+ type BetaManagedAgentsVaultNotFoundDeploymentPausedReasonError,
127
+ type BetaManagedAgentsWorkspaceArchivedDeploymentPausedReasonError,
128
+ type DeploymentCreateParams,
129
+ type DeploymentRetrieveParams,
130
+ type DeploymentUpdateParams,
131
+ type DeploymentListParams,
132
+ type DeploymentArchiveParams,
133
+ type DeploymentPauseParams,
134
+ type DeploymentRunParams,
135
+ type DeploymentUnpauseParams,
136
+ type BetaManagedAgentsDeploymentsPageCursor,
137
+ } from './deployments';
66
138
  export {
67
139
  Environments,
68
140
  type BetaCloudConfig,
@@ -192,6 +264,12 @@ export {
192
264
  type BetaDocumentBlock,
193
265
  type BetaEncryptedCodeExecutionResultBlock,
194
266
  type BetaEncryptedCodeExecutionResultBlockParam,
267
+ type BetaFallbackBlock,
268
+ type BetaFallbackBlockParam,
269
+ type BetaFallbackInfo,
270
+ type BetaFallbackInfoParam,
271
+ type BetaFallbackMessageIterationUsage,
272
+ type BetaFallbackParam,
195
273
  type BetaFileDocumentSource,
196
274
  type BetaFileImageSource,
197
275
  type BetaImageBlockParam,
@@ -370,6 +448,8 @@ export {
370
448
  type BetaManagedAgentsSessionStats,
371
449
  type BetaManagedAgentsSessionUpdatedEvent,
372
450
  type BetaManagedAgentsSessionUsage,
451
+ type BetaManagedAgentsSystemContentBlock,
452
+ type BetaManagedAgentsSystemMessageEvent,
373
453
  type BetaManagedAgentsUserToolResultEvent,
374
454
  type SessionCreateParams,
375
455
  type SessionRetrieveParams,
@@ -570,6 +570,36 @@ export namespace BatchCreateParams {
570
570
  */
571
571
  diagnostics?: BetaMessagesAPI.BetaDiagnosticsParam | null;
572
572
 
573
+ /**
574
+ * The `fallback_credit_token` from a prior refusal's `stop_details`.
575
+ *
576
+ * When a preceding request was refused and returned a `fallback_credit_token`,
577
+ * pass that code here on the retry to have the retry's cache-creation tokens for
578
+ * the prefix that was warm on the refused model billed at the cache-read rate.
579
+ * Must be redeemed by the same organization and workspace, with the same request
580
+ * body (optionally extended by one appended `assistant` message whose content is
581
+ * the partial text — with any trailing whitespace stripped from the final text
582
+ * block — and paired server-tool blocks streamed before the refusal; the
583
+ * appended-assistant form is not available for requests with `output_format` set
584
+ * or forced `tool_choice`), on an eligible fallback model, on the same platform,
585
+ * and within 5 minutes of the refusal; a mismatch is a 400. A token minted
586
+ * mid-server-tool-loop whose partial content was continuable may only be redeemed
587
+ * with the appended-assistant form — if an exact-body retry is rejected with a 400
588
+ * saying the token must be redeemed by continuing the partial response, retry with
589
+ * the appended-assistant form instead.
590
+ *
591
+ * When the appended-assistant form is used on a model that otherwise disallows
592
+ * assistant-turn prefill, this token also authorizes that one prefill.
593
+ */
594
+ fallback_credit_token?: string | null;
595
+
596
+ /**
597
+ * Opt-in server-side retry on one or more substitute models when the requested
598
+ * model declines for policy reasons. Tried in order: if the first entry also
599
+ * declines, the second is tried, and so on.
600
+ */
601
+ fallbacks?: Array<BetaMessagesAPI.BetaFallbackParam> | null;
602
+
573
603
  /**
574
604
  * Specifies the geographic region for inference processing. If not specified, the
575
605
  * workspace's `default_inference_geo` is used.
@@ -103,6 +103,12 @@ export {
103
103
  type BetaDocumentBlock,
104
104
  type BetaEncryptedCodeExecutionResultBlock,
105
105
  type BetaEncryptedCodeExecutionResultBlockParam,
106
+ type BetaFallbackBlock,
107
+ type BetaFallbackBlockParam,
108
+ type BetaFallbackInfo,
109
+ type BetaFallbackInfoParam,
110
+ type BetaFallbackMessageIterationUsage,
111
+ type BetaFallbackParam,
106
112
  type BetaFileDocumentSource,
107
113
  type BetaFileImageSource,
108
114
  type BetaImageBlockParam,
@@ -60,8 +60,15 @@ const DEPRECATED_MODELS: {
60
60
  'claude-2.0': 'July 21st, 2025',
61
61
  'claude-3-7-sonnet-latest': 'February 19th, 2026',
62
62
  'claude-3-7-sonnet-20250219': 'February 19th, 2026',
63
+ 'claude-3-5-haiku-latest': 'February 19th, 2026',
64
+ 'claude-3-5-haiku-20241022': 'February 19th, 2026',
65
+ 'claude-opus-4-0': 'June 15th, 2026',
66
+ 'claude-opus-4-20250514': 'June 15th, 2026',
67
+ 'claude-sonnet-4-0': 'June 15th, 2026',
68
+ 'claude-sonnet-4-20250514': 'June 15th, 2026',
63
69
  'claude-opus-4-1': 'August 5th, 2026',
64
70
  'claude-opus-4-1-20250805': 'August 5th, 2026',
71
+ 'claude-mythos-preview': 'June 30th, 2026',
65
72
  };
66
73
 
67
74
  const MODELS_TO_WARN_WITH_THINKING_ENABLED: Model[] = ['claude-mythos-preview', 'claude-opus-4-6'];
@@ -1356,7 +1363,8 @@ export type BetaContentBlock =
1356
1363
  | BetaMCPToolUseBlock
1357
1364
  | BetaMCPToolResultBlock
1358
1365
  | BetaContainerUploadBlock
1359
- | BetaCompactionBlock;
1366
+ | BetaCompactionBlock
1367
+ | BetaFallbackBlock;
1360
1368
 
1361
1369
  /**
1362
1370
  * Regular text content.
@@ -1382,7 +1390,8 @@ export type BetaContentBlockParam =
1382
1390
  | BetaRequestMCPToolResultBlockParam
1383
1391
  | BetaContainerUploadBlockParam
1384
1392
  | BetaCompactionBlockParam
1385
- | BetaMidConversationSystemBlockParam;
1393
+ | BetaMidConversationSystemBlockParam
1394
+ | BetaFallbackBlockParam;
1386
1395
 
1387
1396
  export interface BetaContentBlockSource {
1388
1397
  content: string | Array<BetaContentBlockSourceContent>;
@@ -1502,6 +1511,170 @@ export interface BetaEncryptedCodeExecutionResultBlockParam {
1502
1511
  type: 'encrypted_code_execution_result';
1503
1512
  }
1504
1513
 
1514
+ /**
1515
+ * Marks the point in `content` where one model's output gives way to the next.
1516
+ *
1517
+ * One block appears per hop where a preceding model actually ran this turn and
1518
+ * declined. A turn routed directly by the sticky decision has no such boundary and
1519
+ * carries no block — the signal for whether a fallback model served the response
1520
+ * is the presence of a `fallback_message` entry in `usage.iterations`, not this
1521
+ * block.
1522
+ *
1523
+ * The block is treated like a server-tool content block for streaming: it arrives
1524
+ * via the standard `content_block_start` / `content_block_stop` pair and carries
1525
+ * no deltas.
1526
+ */
1527
+ export interface BetaFallbackBlock {
1528
+ /**
1529
+ * The model whose output ends at this point — the model that declined at this hop.
1530
+ * When the declining hop is the requested model, its `model` echoes the top-level
1531
+ * `model` string the caller sent (alias or canonical); when the declining hop is a
1532
+ * fallback model, its `model` is that model's canonical id.
1533
+ */
1534
+ from: BetaFallbackInfo;
1535
+
1536
+ /**
1537
+ * The fallback model producing the content that follows this block. Its `model` is
1538
+ * always the canonical id.
1539
+ */
1540
+ to: BetaFallbackInfo;
1541
+
1542
+ type: 'fallback';
1543
+ }
1544
+
1545
+ /**
1546
+ * A `fallback` block echoed back from a prior response.
1547
+ *
1548
+ * Accepted in `messages[].content` and never rendered into the prompt, not
1549
+ * validated against the request's `fallbacks` chain or top-level `model`, and
1550
+ * stripped before the sticky-routing cache key is computed.
1551
+ *
1552
+ * Callers should echo the assistant turn verbatim — block included. The block's
1553
+ * position is load-bearing for thinking verification: the thinking runs on either
1554
+ * side of a fallback hop carry independently-rooted verification hash chains, and
1555
+ * this block is the only record of where one chain ends and the next begins. When
1556
+ * thinking runs flank the boundary, omitting the block merges the runs into one
1557
+ * contiguous span whose hashes cannot verify (the request is rejected), and moving
1558
+ * it into the middle of a single run splits that run's chain and is likewise
1559
+ * rejected; between non-thinking blocks the block's placement has no verification
1560
+ * effect.
1561
+ */
1562
+ export interface BetaFallbackBlockParam {
1563
+ /**
1564
+ * Identifies one hop of a fallback transition.
1565
+ */
1566
+ from: BetaFallbackInfoParam;
1567
+
1568
+ /**
1569
+ * Identifies one hop of a fallback transition.
1570
+ */
1571
+ to: BetaFallbackInfoParam;
1572
+
1573
+ type: 'fallback';
1574
+ }
1575
+
1576
+ /**
1577
+ * Identifies one hop of a fallback transition.
1578
+ */
1579
+ export interface BetaFallbackInfo {
1580
+ /**
1581
+ * The model that will complete your prompt.
1582
+ *
1583
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
1584
+ * details and options.
1585
+ */
1586
+ model: MessagesAPI.Model;
1587
+ }
1588
+
1589
+ /**
1590
+ * Identifies one hop of a fallback transition.
1591
+ */
1592
+ export interface BetaFallbackInfoParam {
1593
+ /**
1594
+ * The model that will complete your prompt.
1595
+ *
1596
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
1597
+ * details and options.
1598
+ */
1599
+ model: MessagesAPI.Model;
1600
+ }
1601
+
1602
+ /**
1603
+ * Token usage for the fallback-model attempt of a server-side fallback request.
1604
+ *
1605
+ * Produced in place of a `message` entry for whichever hop served the response. A
1606
+ * declined hop produces the existing `message` entry. Whether a fallback model
1607
+ * served the response is signalled by the presence of this entry in
1608
+ * `usage.iterations`.
1609
+ */
1610
+ export interface BetaFallbackMessageIterationUsage {
1611
+ /**
1612
+ * Breakdown of cached tokens by TTL
1613
+ */
1614
+ cache_creation: BetaCacheCreation | null;
1615
+
1616
+ /**
1617
+ * The number of input tokens used to create the cache entry.
1618
+ */
1619
+ cache_creation_input_tokens: number;
1620
+
1621
+ /**
1622
+ * The number of input tokens read from the cache.
1623
+ */
1624
+ cache_read_input_tokens: number;
1625
+
1626
+ /**
1627
+ * The number of input tokens which were used.
1628
+ */
1629
+ input_tokens: number;
1630
+
1631
+ /**
1632
+ * The model that will complete your prompt.
1633
+ *
1634
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
1635
+ * details and options.
1636
+ */
1637
+ model: MessagesAPI.Model;
1638
+
1639
+ /**
1640
+ * The number of output tokens which were used.
1641
+ */
1642
+ output_tokens: number;
1643
+
1644
+ /**
1645
+ * Usage for the fallback-model attempt that served the response
1646
+ */
1647
+ type: 'fallback_message';
1648
+ }
1649
+
1650
+ /**
1651
+ * One entry in the `fallbacks` chain on a `/v1/messages` request.
1652
+ *
1653
+ * `model` is required. The four override fields (`max_tokens`, `thinking`,
1654
+ * `output_config`, and `speed`) replace the corresponding top-level field for this
1655
+ * attempt only and are validated as if the request were made to `model`. Any other
1656
+ * key is rejected at parse time.
1657
+ */
1658
+ export interface BetaFallbackParam {
1659
+ /**
1660
+ * The model that will complete your prompt.
1661
+ *
1662
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
1663
+ * details and options.
1664
+ */
1665
+ model: MessagesAPI.Model;
1666
+
1667
+ max_tokens?: number | null;
1668
+
1669
+ output_config?: BetaOutputConfig | null;
1670
+
1671
+ speed?: 'standard' | 'fast' | null;
1672
+
1673
+ thinking?: BetaThinkingConfigEnabled | BetaThinkingConfigDisabled | BetaThinkingConfigAdaptive | null;
1674
+
1675
+ [k: string]: unknown;
1676
+ }
1677
+
1505
1678
  export interface BetaFileDocumentSource {
1506
1679
  file_id: string;
1507
1680
 
@@ -1554,7 +1727,10 @@ export interface BetaInputTokensTrigger {
1554
1727
  * - Understand token accumulation across server-side tool use loops
1555
1728
  */
1556
1729
  export type BetaIterationsUsage = Array<
1557
- BetaMessageIterationUsage | BetaCompactionIterationUsage | BetaAdvisorMessageIterationUsage
1730
+ | BetaMessageIterationUsage
1731
+ | BetaCompactionIterationUsage
1732
+ | BetaAdvisorMessageIterationUsage
1733
+ | BetaFallbackMessageIterationUsage
1558
1734
  >;
1559
1735
 
1560
1736
  export interface BetaJSONOutputFormat {
@@ -2018,6 +2194,14 @@ export interface BetaMessageIterationUsage {
2018
2194
  */
2019
2195
  input_tokens: number;
2020
2196
 
2197
+ /**
2198
+ * The model that will complete your prompt.
2199
+ *
2200
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
2201
+ * details and options.
2202
+ */
2203
+ model: MessagesAPI.Model;
2204
+
2021
2205
  /**
2022
2206
  * The number of output tokens which were used.
2023
2207
  */
@@ -2156,7 +2340,8 @@ export interface BetaRawContentBlockStartEvent {
2156
2340
  | BetaMCPToolUseBlock
2157
2341
  | BetaMCPToolResultBlock
2158
2342
  | BetaContainerUploadBlock
2159
- | BetaCompactionBlock;
2343
+ | BetaCompactionBlock
2344
+ | BetaFallbackBlock;
2160
2345
 
2161
2346
  index: number;
2162
2347
 
@@ -2257,7 +2442,7 @@ export interface BetaRefusalStopDetails {
2257
2442
  *
2258
2443
  * `null` when the refusal doesn't map to a named category.
2259
2444
  */
2260
- category: 'cyber' | 'bio' | null;
2445
+ category: 'cyber' | 'bio' | 'reasoning_extraction' | null;
2261
2446
 
2262
2447
  /**
2263
2448
  * Human-readable explanation of the refusal.
@@ -2267,6 +2452,59 @@ export interface BetaRefusalStopDetails {
2267
2452
  */
2268
2453
  explanation: string | null;
2269
2454
 
2455
+ /**
2456
+ * Opaque code that refunds the cache-miss cost when retrying this refused request
2457
+ * on the fallback model. Pass it as `fallback_credit_token` on the retry request.
2458
+ * Expires 5 minutes after the refusal.
2459
+ *
2460
+ * The retry is sent either with the same request body (`system`, `messages`,
2461
+ * `tools`, and other render-shaping fields), or with the same body plus one
2462
+ * appended `assistant` message whose content is the partial text (with any
2463
+ * trailing whitespace stripped from the final text block) and paired server-tool
2464
+ * blocks from this refusal — which also authorizes that appended turn as an
2465
+ * assistant-prefill continuation on models that otherwise disallow prefill. A
2466
+ * token minted mid-server-tool-loop whose partial content was continuable may only
2467
+ * be redeemed the second way — if a same-body retry is rejected with a 400 saying
2468
+ * the token must be redeemed by continuing the partial response, retry the second
2469
+ * way instead. Either way: same workspace, same platform; a mismatch is a 400.
2470
+ * Resending a token for an already-warm prefix is permitted but yields no
2471
+ * additional credit.
2472
+ *
2473
+ * `null` when the refused model isn't eligible for a fallback credit.
2474
+ */
2475
+ fallback_credit_token: string | null;
2476
+
2477
+ /**
2478
+ * Whether the accompanying `fallback_credit_token` may be redeemed with the
2479
+ * appended-assistant retry form. Only set when `fallback_credit_token` is present.
2480
+ *
2481
+ * `true`: retry by resending the same request body plus one appended `assistant`
2482
+ * message whose content is this response's `content` with any trailing whitespace
2483
+ * stripped from the final text block and unpaired `tool_use` blocks omitted (the
2484
+ * same appended-turn shape described on `fallback_credit_token`), with the token
2485
+ * attached. `false`: retry by resending the original request body unchanged, with
2486
+ * the token attached — the appended-assistant form is not available for this
2487
+ * refusal (no continuable partial content, or the request uses `output_format` or
2488
+ * a `tool_choice` that forces tool use). One exception: when the request used
2489
+ * `output_format` or a forced `tool_choice` and the refusal arrived after server
2490
+ * tools (including MCP connector tools) had already executed, the token may not be
2491
+ * redeemable by either retry form; if the exact-body retry is then rejected with a
2492
+ * 400 saying the token must be redeemed by continuing the partial response,
2493
+ * discard the token and retry without it.
2494
+ *
2495
+ * Advisory: if an appended-assistant retry is rejected with a 400 despite `true`,
2496
+ * fall back to resending the original request body with the token.
2497
+ */
2498
+ fallback_has_prefill_claim: boolean | null;
2499
+
2500
+ /**
2501
+ * The server's suggested retry target for this refusal. Populated when a fallback
2502
+ * attempt could not be made (the fallback model's rate limit was exhausted, or it
2503
+ * was overloaded); names the fallback model the caller can retry directly. Null
2504
+ * otherwise.
2505
+ */
2506
+ recommended_model: string | null;
2507
+
2270
2508
  type: 'refusal';
2271
2509
  }
2272
2510
 
@@ -4150,6 +4388,36 @@ export interface MessageCreateParamsBase {
4150
4388
  */
4151
4389
  diagnostics?: BetaDiagnosticsParam | null;
4152
4390
 
4391
+ /**
4392
+ * Body param: The `fallback_credit_token` from a prior refusal's `stop_details`.
4393
+ *
4394
+ * When a preceding request was refused and returned a `fallback_credit_token`,
4395
+ * pass that code here on the retry to have the retry's cache-creation tokens for
4396
+ * the prefix that was warm on the refused model billed at the cache-read rate.
4397
+ * Must be redeemed by the same organization and workspace, with the same request
4398
+ * body (optionally extended by one appended `assistant` message whose content is
4399
+ * the partial text — with any trailing whitespace stripped from the final text
4400
+ * block — and paired server-tool blocks streamed before the refusal; the
4401
+ * appended-assistant form is not available for requests with `output_format` set
4402
+ * or forced `tool_choice`), on an eligible fallback model, on the same platform,
4403
+ * and within 5 minutes of the refusal; a mismatch is a 400. A token minted
4404
+ * mid-server-tool-loop whose partial content was continuable may only be redeemed
4405
+ * with the appended-assistant form — if an exact-body retry is rejected with a 400
4406
+ * saying the token must be redeemed by continuing the partial response, retry with
4407
+ * the appended-assistant form instead.
4408
+ *
4409
+ * When the appended-assistant form is used on a model that otherwise disallows
4410
+ * assistant-turn prefill, this token also authorizes that one prefill.
4411
+ */
4412
+ fallback_credit_token?: string | null;
4413
+
4414
+ /**
4415
+ * Body param: Opt-in server-side retry on one or more substitute models when the
4416
+ * requested model declines for policy reasons. Tried in order: if the first entry
4417
+ * also declines, the second is tried, and so on.
4418
+ */
4419
+ fallbacks?: Array<BetaFallbackParam> | null;
4420
+
4153
4421
  /**
4154
4422
  * Body param: Specifies the geographic region for inference processing. If not
4155
4423
  * specified, the workspace's `default_inference_geo` is used.
@@ -4728,6 +4996,12 @@ export declare namespace Messages {
4728
4996
  type BetaDocumentBlock as BetaDocumentBlock,
4729
4997
  type BetaEncryptedCodeExecutionResultBlock as BetaEncryptedCodeExecutionResultBlock,
4730
4998
  type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
4999
+ type BetaFallbackBlock as BetaFallbackBlock,
5000
+ type BetaFallbackBlockParam as BetaFallbackBlockParam,
5001
+ type BetaFallbackInfo as BetaFallbackInfo,
5002
+ type BetaFallbackInfoParam as BetaFallbackInfoParam,
5003
+ type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
5004
+ type BetaFallbackParam as BetaFallbackParam,
4731
5005
  type BetaFileDocumentSource as BetaFileDocumentSource,
4732
5006
  type BetaFileImageSource as BetaFileImageSource,
4733
5007
  type BetaImageBlockParam as BetaImageBlockParam,
@@ -195,6 +195,13 @@ export interface BetaModelInfo {
195
195
  */
196
196
  id: string;
197
197
 
198
+ /**
199
+ * Model IDs this model accepts as `fallbacks[i].model` on the Messages API. An
200
+ * empty list means the `fallbacks` parameter is not supported for this model as
201
+ * primary.
202
+ */
203
+ allowed_fallback_models: Array<string> | null;
204
+
198
205
  /**
199
206
  * Model capability information.
200
207
  */
@@ -518,6 +518,37 @@ export interface BetaManagedAgentsBillingError {
518
518
  type: 'billing_error';
519
519
  }
520
520
 
521
+ /**
522
+ * An `environment_variable` credential's `auth.networking.allowed_hosts` includes
523
+ * a host the environment's network policy does not permit.
524
+ */
525
+ export interface BetaManagedAgentsCredentialHostUnreachableError {
526
+ /**
527
+ * ID of the affected credential.
528
+ */
529
+ credential_id: string;
530
+
531
+ /**
532
+ * Human-readable error description.
533
+ */
534
+ message: string;
535
+
536
+ /**
537
+ * What the client should do next in response to this error.
538
+ */
539
+ retry_status:
540
+ | BetaManagedAgentsRetryStatusRetrying
541
+ | BetaManagedAgentsRetryStatusExhausted
542
+ | BetaManagedAgentsRetryStatusTerminal;
543
+
544
+ type: 'credential_host_unreachable_error';
545
+
546
+ /**
547
+ * ID of the vault containing the affected credential.
548
+ */
549
+ vault_id: string;
550
+ }
551
+
521
552
  /**
522
553
  * Document content, either specified directly as base64 data, as text, or as a
523
554
  * reference via a URL.
@@ -554,7 +585,8 @@ export type BetaManagedAgentsEventParams =
554
585
  | BetaManagedAgentsUserToolConfirmationEventParams
555
586
  | BetaManagedAgentsUserCustomToolResultEventParams
556
587
  | BetaManagedAgentsUserDefineOutcomeEventParams
557
- | BetaManagedAgentsUserToolResultEventParams;
588
+ | BetaManagedAgentsUserToolResultEventParams
589
+ | BetaManagedAgentsSystemMessageEventParams;
558
590
 
559
591
  /**
560
592
  * Document referenced by file ID.
@@ -835,6 +867,7 @@ export interface BetaManagedAgentsSendSessionEvents {
835
867
  | BetaManagedAgentsUserCustomToolResultEvent
836
868
  | BetaManagedAgentsUserDefineOutcomeEvent
837
869
  | SessionsAPI.BetaManagedAgentsUserToolResultEvent
870
+ | SessionsAPI.BetaManagedAgentsSystemMessageEvent
838
871
  >;
839
872
  }
840
873
 
@@ -884,7 +917,8 @@ export interface BetaManagedAgentsSessionErrorEvent {
884
917
  | BetaManagedAgentsModelRequestFailedError
885
918
  | BetaManagedAgentsMCPConnectionFailedError
886
919
  | BetaManagedAgentsMCPAuthenticationFailedError
887
- | BetaManagedAgentsBillingError;
920
+ | BetaManagedAgentsBillingError
921
+ | BetaManagedAgentsCredentialHostUnreachableError;
888
922
 
889
923
  /**
890
924
  * A timestamp in RFC 3339 format
@@ -930,7 +964,8 @@ export type BetaManagedAgentsSessionEvent =
930
964
  | BetaManagedAgentsSessionThreadStatusTerminatedEvent
931
965
  | SessionsAPI.BetaManagedAgentsUserToolResultEvent
932
966
  | BetaManagedAgentsSessionThreadStatusRescheduledEvent
933
- | SessionsAPI.BetaManagedAgentsSessionUpdatedEvent;
967
+ | SessionsAPI.BetaManagedAgentsSessionUpdatedEvent
968
+ | SessionsAPI.BetaManagedAgentsSystemMessageEvent;
934
969
 
935
970
  /**
936
971
  * The agent is idle waiting on one or more blocking user-input events (tool
@@ -1415,7 +1450,25 @@ export type BetaManagedAgentsStreamSessionEvents =
1415
1450
  | BetaManagedAgentsSessionThreadStatusTerminatedEvent
1416
1451
  | SessionsAPI.BetaManagedAgentsUserToolResultEvent
1417
1452
  | BetaManagedAgentsSessionThreadStatusRescheduledEvent
1418
- | SessionsAPI.BetaManagedAgentsSessionUpdatedEvent;
1453
+ | SessionsAPI.BetaManagedAgentsSessionUpdatedEvent
1454
+ | SessionsAPI.BetaManagedAgentsSystemMessageEvent;
1455
+
1456
+ /**
1457
+ * Privileged context for the accompanying turn and all subsequent turns, appended
1458
+ * to the session's system context as a `role: "system"` turn rather than replacing
1459
+ * the top-level system prompt. At most one per request: it must be the final event
1460
+ * and immediately follow the `user.message`, `user.tool_result`, or
1461
+ * `user.custom_tool_result` it accompanies. Only supported on models that accept
1462
+ * mid-conversation system messages.
1463
+ */
1464
+ export interface BetaManagedAgentsSystemMessageEventParams {
1465
+ /**
1466
+ * System content blocks to append. Text-only.
1467
+ */
1468
+ content: Array<SessionsAPI.BetaManagedAgentsSystemContentBlock>;
1469
+
1470
+ type: 'system.message';
1471
+ }
1419
1472
 
1420
1473
  /**
1421
1474
  * Regular text content.
@@ -1891,6 +1944,7 @@ export declare namespace Events {
1891
1944
  type BetaManagedAgentsBase64DocumentSource as BetaManagedAgentsBase64DocumentSource,
1892
1945
  type BetaManagedAgentsBase64ImageSource as BetaManagedAgentsBase64ImageSource,
1893
1946
  type BetaManagedAgentsBillingError as BetaManagedAgentsBillingError,
1947
+ type BetaManagedAgentsCredentialHostUnreachableError as BetaManagedAgentsCredentialHostUnreachableError,
1894
1948
  type BetaManagedAgentsDocumentBlock as BetaManagedAgentsDocumentBlock,
1895
1949
  type BetaManagedAgentsEventParams as BetaManagedAgentsEventParams,
1896
1950
  type BetaManagedAgentsFileDocumentSource as BetaManagedAgentsFileDocumentSource,
@@ -1933,6 +1987,7 @@ export declare namespace Events {
1933
1987
  type BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent as BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent,
1934
1988
  type BetaManagedAgentsSpanOutcomeEvaluationStartEvent as BetaManagedAgentsSpanOutcomeEvaluationStartEvent,
1935
1989
  type BetaManagedAgentsStreamSessionEvents as BetaManagedAgentsStreamSessionEvents,
1990
+ type BetaManagedAgentsSystemMessageEventParams as BetaManagedAgentsSystemMessageEventParams,
1936
1991
  type BetaManagedAgentsTextBlock as BetaManagedAgentsTextBlock,
1937
1992
  type BetaManagedAgentsTextRubric as BetaManagedAgentsTextRubric,
1938
1993
  type BetaManagedAgentsTextRubricParams as BetaManagedAgentsTextRubricParams,
@@ -15,6 +15,7 @@ export {
15
15
  type BetaManagedAgentsBase64DocumentSource,
16
16
  type BetaManagedAgentsBase64ImageSource,
17
17
  type BetaManagedAgentsBillingError,
18
+ type BetaManagedAgentsCredentialHostUnreachableError,
18
19
  type BetaManagedAgentsDocumentBlock,
19
20
  type BetaManagedAgentsEventParams,
20
21
  type BetaManagedAgentsFileDocumentSource,
@@ -57,6 +58,7 @@ export {
57
58
  type BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent,
58
59
  type BetaManagedAgentsSpanOutcomeEvaluationStartEvent,
59
60
  type BetaManagedAgentsStreamSessionEvents,
61
+ type BetaManagedAgentsSystemMessageEventParams,
60
62
  type BetaManagedAgentsTextBlock,
61
63
  type BetaManagedAgentsTextRubric,
62
64
  type BetaManagedAgentsTextRubricParams,
@@ -116,6 +118,8 @@ export {
116
118
  type BetaManagedAgentsSessionStats,
117
119
  type BetaManagedAgentsSessionUpdatedEvent,
118
120
  type BetaManagedAgentsSessionUsage,
121
+ type BetaManagedAgentsSystemContentBlock,
122
+ type BetaManagedAgentsSystemMessageEvent,
119
123
  type BetaManagedAgentsUserToolResultEvent,
120
124
  type SessionCreateParams,
121
125
  type SessionRetrieveParams,