@anthropic-ai/sdk 0.125.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 (297) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/client.d.mts +2 -2
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +2 -2
  5. package/client.d.ts.map +1 -1
  6. package/client.js +846 -840
  7. package/client.js.map +1 -1
  8. package/client.mjs +846 -834
  9. package/client.mjs.map +1 -1
  10. package/core/api-promise.js +71 -68
  11. package/core/api-promise.js.map +1 -1
  12. package/core/api-promise.mjs +71 -64
  13. package/core/api-promise.mjs.map +1 -1
  14. package/core/error.js +5 -2
  15. package/core/error.js.map +1 -1
  16. package/core/error.mjs +5 -2
  17. package/core/error.mjs.map +1 -1
  18. package/core/pagination.js +56 -50
  19. package/core/pagination.js.map +1 -1
  20. package/core/pagination.mjs +56 -41
  21. package/core/pagination.mjs.map +1 -1
  22. package/core/streaming.js +212 -209
  23. package/core/streaming.js.map +1 -1
  24. package/core/streaming.mjs +212 -209
  25. package/core/streaming.mjs.map +1 -1
  26. package/helpers/beta/mcp.js +14 -19
  27. package/helpers/beta/mcp.js.map +1 -1
  28. package/helpers/beta/mcp.mjs +14 -13
  29. package/helpers/beta/mcp.mjs.map +1 -1
  30. package/internal/constants.js +1 -1
  31. package/internal/constants.js.map +1 -1
  32. package/internal/decoders/jsonl.js +27 -24
  33. package/internal/decoders/jsonl.js.map +1 -1
  34. package/internal/decoders/jsonl.mjs +27 -24
  35. package/internal/decoders/jsonl.mjs.map +1 -1
  36. package/internal/decoders/line.js +52 -49
  37. package/internal/decoders/line.js.map +1 -1
  38. package/internal/decoders/line.mjs +52 -43
  39. package/internal/decoders/line.mjs.map +1 -1
  40. package/internal/file-store.js +256 -258
  41. package/internal/file-store.js.map +1 -1
  42. package/internal/file-store.mjs +256 -243
  43. package/internal/file-store.mjs.map +1 -1
  44. package/internal/node.browser.d.mts.map +1 -1
  45. package/internal/node.browser.d.ts.map +1 -1
  46. package/internal/node.browser.js.map +1 -1
  47. package/internal/node.browser.mjs +7 -7
  48. package/internal/node.browser.mjs.map +1 -1
  49. package/internal/shim-types.js +0 -6
  50. package/internal/shim-types.js.map +1 -1
  51. package/internal/shim-types.mjs +0 -6
  52. package/internal/shim-types.mjs.map +1 -1
  53. package/internal/shims.js +0 -6
  54. package/internal/shims.js.map +1 -1
  55. package/internal/shims.mjs +0 -6
  56. package/internal/shims.mjs.map +1 -1
  57. package/internal/stainless-helper-header.js +6 -6
  58. package/internal/stainless-helper-header.js.map +1 -1
  59. package/internal/utils/async-queue.js +66 -63
  60. package/internal/utils/async-queue.js.map +1 -1
  61. package/internal/utils/async-queue.mjs +66 -56
  62. package/internal/utils/async-queue.mjs.map +1 -1
  63. package/internal/utils/bytes.d.mts +1 -1
  64. package/internal/utils/bytes.d.mts.map +1 -1
  65. package/internal/utils/bytes.d.ts +1 -1
  66. package/internal/utils/bytes.d.ts.map +1 -1
  67. package/lib/BetaMessageStream.js +593 -590
  68. package/lib/BetaMessageStream.js.map +1 -1
  69. package/lib/BetaMessageStream.mjs +593 -590
  70. package/lib/BetaMessageStream.mjs.map +1 -1
  71. package/lib/MessageStream.js +544 -541
  72. package/lib/MessageStream.js.map +1 -1
  73. package/lib/MessageStream.mjs +544 -541
  74. package/lib/MessageStream.mjs.map +1 -1
  75. package/lib/environments/poller.js +180 -174
  76. package/lib/environments/poller.js.map +1 -1
  77. package/lib/environments/poller.mjs +180 -153
  78. package/lib/environments/poller.mjs.map +1 -1
  79. package/lib/environments/worker.js +375 -369
  80. package/lib/environments/worker.js.map +1 -1
  81. package/lib/environments/worker.mjs +374 -329
  82. package/lib/environments/worker.mjs.map +1 -1
  83. package/lib/tools/BetaToolRunner.js +316 -313
  84. package/lib/tools/BetaToolRunner.js.map +1 -1
  85. package/lib/tools/BetaToolRunner.mjs +315 -306
  86. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  87. package/lib/tools/SessionToolRunner.js +241 -235
  88. package/lib/tools/SessionToolRunner.js.map +1 -1
  89. package/lib/tools/SessionToolRunner.mjs +241 -192
  90. package/lib/tools/SessionToolRunner.mjs.map +1 -1
  91. package/lib/tools/ToolError.js +39 -36
  92. package/lib/tools/ToolError.js.map +1 -1
  93. package/lib/tools/ToolError.mjs +39 -13
  94. package/lib/tools/ToolError.mjs.map +1 -1
  95. package/package.json +3 -3
  96. package/resources/beta/agents/agents.js +135 -132
  97. package/resources/beta/agents/agents.js.map +1 -1
  98. package/resources/beta/agents/agents.mjs +135 -132
  99. package/resources/beta/agents/agents.mjs.map +1 -1
  100. package/resources/beta/beta.d.mts +5 -5
  101. package/resources/beta/beta.d.mts.map +1 -1
  102. package/resources/beta/beta.d.ts +5 -5
  103. package/resources/beta/beta.d.ts.map +1 -1
  104. package/resources/beta/beta.js +39 -36
  105. package/resources/beta/beta.js.map +1 -1
  106. package/resources/beta/beta.mjs +39 -36
  107. package/resources/beta/beta.mjs.map +1 -1
  108. package/resources/beta/dreams.d.mts +2 -28
  109. package/resources/beta/dreams.d.mts.map +1 -1
  110. package/resources/beta/dreams.d.ts +2 -28
  111. package/resources/beta/dreams.d.ts.map +1 -1
  112. package/resources/beta/environments/environments.js +157 -154
  113. package/resources/beta/environments/environments.js.map +1 -1
  114. package/resources/beta/environments/environments.mjs +157 -154
  115. package/resources/beta/environments/environments.mjs.map +1 -1
  116. package/resources/beta/environments/work.js +255 -252
  117. package/resources/beta/environments/work.js.map +1 -1
  118. package/resources/beta/environments/work.mjs +255 -252
  119. package/resources/beta/environments/work.mjs.map +1 -1
  120. package/resources/beta/index.d.mts +2 -2
  121. package/resources/beta/index.d.mts.map +1 -1
  122. package/resources/beta/index.d.ts +2 -2
  123. package/resources/beta/index.d.ts.map +1 -1
  124. package/resources/beta/index.js.map +1 -1
  125. package/resources/beta/index.mjs.map +1 -1
  126. package/resources/beta/memory-stores/memory-stores.js +150 -147
  127. package/resources/beta/memory-stores/memory-stores.js.map +1 -1
  128. package/resources/beta/memory-stores/memory-stores.mjs +150 -147
  129. package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
  130. package/resources/beta/messages/batches.d.mts +12 -1
  131. package/resources/beta/messages/batches.d.mts.map +1 -1
  132. package/resources/beta/messages/batches.d.ts +12 -1
  133. package/resources/beta/messages/batches.d.ts.map +1 -1
  134. package/resources/beta/messages/index.d.mts +1 -1
  135. package/resources/beta/messages/index.d.mts.map +1 -1
  136. package/resources/beta/messages/index.d.ts +1 -1
  137. package/resources/beta/messages/index.d.ts.map +1 -1
  138. package/resources/beta/messages/index.js.map +1 -1
  139. package/resources/beta/messages/index.mjs.map +1 -1
  140. package/resources/beta/messages/messages.d.mts +238 -100
  141. package/resources/beta/messages/messages.d.mts.map +1 -1
  142. package/resources/beta/messages/messages.d.ts +238 -100
  143. package/resources/beta/messages/messages.d.ts.map +1 -1
  144. package/resources/beta/messages/messages.js +113 -110
  145. package/resources/beta/messages/messages.js.map +1 -1
  146. package/resources/beta/messages/messages.mjs +113 -110
  147. package/resources/beta/messages/messages.mjs.map +1 -1
  148. package/resources/beta/models.d.mts +22 -1
  149. package/resources/beta/models.d.mts.map +1 -1
  150. package/resources/beta/models.d.ts +22 -1
  151. package/resources/beta/models.d.ts.map +1 -1
  152. package/resources/beta/organization/federation/federation.js +11 -8
  153. package/resources/beta/organization/federation/federation.js.map +1 -1
  154. package/resources/beta/organization/federation/federation.mjs +11 -8
  155. package/resources/beta/organization/federation/federation.mjs.map +1 -1
  156. package/resources/beta/organization/federation/rules/rules.js +187 -184
  157. package/resources/beta/organization/federation/rules/rules.js.map +1 -1
  158. package/resources/beta/organization/federation/rules/rules.mjs +187 -184
  159. package/resources/beta/organization/federation/rules/rules.mjs.map +1 -1
  160. package/resources/beta/organization/organization.js +38 -35
  161. package/resources/beta/organization/organization.js.map +1 -1
  162. package/resources/beta/organization/organization.mjs +38 -35
  163. package/resources/beta/organization/organization.mjs.map +1 -1
  164. package/resources/beta/organization/service-accounts/service-accounts.js +163 -160
  165. package/resources/beta/organization/service-accounts/service-accounts.js.map +1 -1
  166. package/resources/beta/organization/service-accounts/service-accounts.mjs +163 -160
  167. package/resources/beta/organization/service-accounts/service-accounts.mjs.map +1 -1
  168. package/resources/beta/organization/workspaces/workspaces.d.mts +3 -3
  169. package/resources/beta/organization/workspaces/workspaces.d.mts.map +1 -1
  170. package/resources/beta/organization/workspaces/workspaces.d.ts +3 -3
  171. package/resources/beta/organization/workspaces/workspaces.d.ts.map +1 -1
  172. package/resources/beta/organization/workspaces/workspaces.js +97 -94
  173. package/resources/beta/organization/workspaces/workspaces.js.map +1 -1
  174. package/resources/beta/organization/workspaces/workspaces.mjs +97 -94
  175. package/resources/beta/organization/workspaces/workspaces.mjs.map +1 -1
  176. package/resources/beta/sessions/events.d.mts +12 -21
  177. package/resources/beta/sessions/events.d.mts.map +1 -1
  178. package/resources/beta/sessions/events.d.ts +12 -21
  179. package/resources/beta/sessions/events.d.ts.map +1 -1
  180. package/resources/beta/sessions/events.js +118 -115
  181. package/resources/beta/sessions/events.js.map +1 -1
  182. package/resources/beta/sessions/events.mjs +118 -115
  183. package/resources/beta/sessions/events.mjs.map +1 -1
  184. package/resources/beta/sessions/resources.d.mts +0 -3
  185. package/resources/beta/sessions/resources.d.mts.map +1 -1
  186. package/resources/beta/sessions/resources.d.ts +0 -3
  187. package/resources/beta/sessions/resources.d.ts.map +1 -1
  188. package/resources/beta/sessions/sessions.d.mts +2 -2
  189. package/resources/beta/sessions/sessions.d.ts +2 -2
  190. package/resources/beta/sessions/sessions.js +161 -158
  191. package/resources/beta/sessions/sessions.js.map +1 -1
  192. package/resources/beta/sessions/sessions.mjs +161 -158
  193. package/resources/beta/sessions/sessions.mjs.map +1 -1
  194. package/resources/beta/sessions/threads/threads.js +86 -83
  195. package/resources/beta/sessions/threads/threads.js.map +1 -1
  196. package/resources/beta/sessions/threads/threads.mjs +86 -83
  197. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  198. package/resources/beta/skills/skills.js +104 -101
  199. package/resources/beta/skills/skills.js.map +1 -1
  200. package/resources/beta/skills/skills.mjs +104 -101
  201. package/resources/beta/skills/skills.mjs.map +1 -1
  202. package/resources/beta/tunnels/tunnels.js +188 -185
  203. package/resources/beta/tunnels/tunnels.js.map +1 -1
  204. package/resources/beta/tunnels/tunnels.mjs +188 -185
  205. package/resources/beta/tunnels/tunnels.mjs.map +1 -1
  206. package/resources/beta/user-profiles.d.mts +45 -0
  207. package/resources/beta/user-profiles.d.mts.map +1 -1
  208. package/resources/beta/user-profiles.d.ts +45 -0
  209. package/resources/beta/user-profiles.d.ts.map +1 -1
  210. package/resources/beta/user-profiles.js +25 -10
  211. package/resources/beta/user-profiles.js.map +1 -1
  212. package/resources/beta/user-profiles.mjs +25 -10
  213. package/resources/beta/user-profiles.mjs.map +1 -1
  214. package/resources/beta/vaults/credentials.d.mts +0 -14
  215. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  216. package/resources/beta/vaults/credentials.d.ts +0 -14
  217. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  218. package/resources/beta/vaults/vaults.js +156 -153
  219. package/resources/beta/vaults/vaults.js.map +1 -1
  220. package/resources/beta/vaults/vaults.mjs +156 -153
  221. package/resources/beta/vaults/vaults.mjs.map +1 -1
  222. package/resources/completions.d.mts +1 -1
  223. package/resources/completions.d.ts +1 -1
  224. package/resources/index.d.mts +1 -1
  225. package/resources/index.d.mts.map +1 -1
  226. package/resources/index.d.ts +1 -1
  227. package/resources/index.d.ts.map +1 -1
  228. package/resources/index.js.map +1 -1
  229. package/resources/index.mjs.map +1 -1
  230. package/resources/messages/index.d.mts +1 -1
  231. package/resources/messages/index.d.mts.map +1 -1
  232. package/resources/messages/index.d.ts +1 -1
  233. package/resources/messages/index.d.ts.map +1 -1
  234. package/resources/messages/index.js.map +1 -1
  235. package/resources/messages/index.mjs.map +1 -1
  236. package/resources/messages/messages.d.mts +100 -63
  237. package/resources/messages/messages.d.mts.map +1 -1
  238. package/resources/messages/messages.d.ts +100 -63
  239. package/resources/messages/messages.d.ts.map +1 -1
  240. package/resources/messages/messages.js +115 -112
  241. package/resources/messages/messages.js.map +1 -1
  242. package/resources/messages/messages.mjs +115 -112
  243. package/resources/messages/messages.mjs.map +1 -1
  244. package/resources/skills/skills.js +88 -85
  245. package/resources/skills/skills.js.map +1 -1
  246. package/resources/skills/skills.mjs +88 -85
  247. package/resources/skills/skills.mjs.map +1 -1
  248. package/resources/top-level.js +0 -1
  249. package/resources/top-level.js.map +1 -1
  250. package/resources/top-level.mjs +0 -1
  251. package/resources/top-level.mjs.map +1 -1
  252. package/src/client.ts +13 -1
  253. package/src/internal/node.browser.ts +7 -7
  254. package/src/internal/utils/bytes.ts +1 -1
  255. package/src/resources/beta/beta.ts +24 -1
  256. package/src/resources/beta/dreams.ts +2 -28
  257. package/src/resources/beta/index.ts +11 -0
  258. package/src/resources/beta/messages/batches.ts +13 -1
  259. package/src/resources/beta/messages/index.ts +10 -0
  260. package/src/resources/beta/messages/messages.ts +288 -99
  261. package/src/resources/beta/models.ts +25 -0
  262. package/src/resources/beta/organization/workspaces/workspaces.ts +3 -3
  263. package/src/resources/beta/sessions/events.ts +12 -21
  264. package/src/resources/beta/sessions/resources.ts +0 -3
  265. package/src/resources/beta/sessions/sessions.ts +2 -2
  266. package/src/resources/beta/user-profiles.ts +75 -10
  267. package/src/resources/beta/vaults/credentials.ts +0 -14
  268. package/src/resources/completions.ts +1 -1
  269. package/src/resources/index.ts +6 -0
  270. package/src/resources/messages/index.ts +6 -0
  271. package/src/resources/messages/messages.ts +128 -62
  272. package/src/tsconfig.json +13 -3
  273. package/src/version.ts +1 -1
  274. package/tools/agent-toolset/fs-util.js +0 -6
  275. package/tools/agent-toolset/fs-util.js.map +1 -1
  276. package/tools/agent-toolset/fs-util.mjs +0 -6
  277. package/tools/agent-toolset/fs-util.mjs.map +1 -1
  278. package/tools/agent-toolset/memories.js +4 -4
  279. package/tools/agent-toolset/memories.js.map +1 -1
  280. package/tools/agent-toolset/memories.mjs +2 -2
  281. package/tools/agent-toolset/memories.mjs.map +1 -1
  282. package/tools/agent-toolset/node.browser.js +12 -12
  283. package/tools/agent-toolset/node.browser.js.map +1 -1
  284. package/tools/agent-toolset/node.js +142 -139
  285. package/tools/agent-toolset/node.js.map +1 -1
  286. package/tools/agent-toolset/node.mjs +132 -125
  287. package/tools/agent-toolset/node.mjs.map +1 -1
  288. package/tools/agent-toolset/skills.js +5 -5
  289. package/tools/agent-toolset/skills.js.map +1 -1
  290. package/tools/agent-toolset/sync-interval.js +3 -3
  291. package/tools/agent-toolset/sync-interval.js.map +1 -1
  292. package/tools/memory/node.browser.js +2 -2
  293. package/tools/memory/node.browser.js.map +1 -1
  294. package/version.d.mts +1 -1
  295. package/version.d.ts +1 -1
  296. package/version.js +1 -1
  297. package/version.mjs +1 -1
@@ -10,123 +10,126 @@ const parser_1 = require("../../lib/parser.js");
10
10
  const BatchesAPI = tslib_1.__importStar(require("./batches.js"));
11
11
  const batches_1 = require("./batches.js");
12
12
  const constants_1 = require("../../internal/constants.js");
13
- class Messages extends resource_1.APIResource {
14
- constructor() {
15
- super(...arguments);
16
- this.batches = new BatchesAPI.Batches(this._client);
17
- }
18
- create(params, options) {
19
- const { user_profile_id, workspace_id, ...body } = params;
20
- if (body.model in DEPRECATED_MODELS) {
21
- console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
13
+ var Messages = /* @__PURE__ */ (() => {
14
+ class Messages extends resource_1.APIResource {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.batches = new BatchesAPI.Batches(this._client);
22
18
  }
23
- if (MODELS_TO_WARN_WITH_THINKING_ENABLED.includes(body.model) &&
24
- body.thinking &&
25
- body.thinking.type === 'enabled') {
26
- console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
19
+ create(params, options) {
20
+ const { user_profile_id, workspace_id, ...body } = params;
21
+ if (body.model in DEPRECATED_MODELS) {
22
+ console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
23
+ }
24
+ if (MODELS_TO_WARN_WITH_THINKING_ENABLED.includes(body.model) &&
25
+ body.thinking &&
26
+ body.thinking.type === 'enabled') {
27
+ console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
28
+ }
29
+ let timeout = options?.timeout ?? this._client._options.timeout;
30
+ if (!body.stream && timeout == null) {
31
+ const maxNonstreamingTokens = constants_1.MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
32
+ timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
33
+ }
34
+ // Collect helper info from tools and messages
35
+ const helperHeader = (0, stainless_helper_header_1.stainlessHelperHeader)(body.tools, body.messages);
36
+ return this._client.post('/v1/messages', {
37
+ body,
38
+ timeout: timeout ?? 600000,
39
+ ...options,
40
+ headers: (0, headers_1.buildHeaders)([
41
+ {
42
+ ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
43
+ ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
44
+ },
45
+ helperHeader,
46
+ options?.headers,
47
+ ]),
48
+ stream: params.stream ?? false,
49
+ });
27
50
  }
28
- let timeout = options?.timeout ?? this._client._options.timeout;
29
- if (!body.stream && timeout == null) {
30
- const maxNonstreamingTokens = constants_1.MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
31
- timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
51
+ /**
52
+ * Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
53
+ * the response will be automatically parsed and available in the `parsed_output` property of the message.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const message = await client.messages.parse({
58
+ * model: 'claude-sonnet-4-5-20250929',
59
+ * max_tokens: 1024,
60
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
61
+ * output_config: {
62
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
63
+ * },
64
+ * });
65
+ *
66
+ * console.log(message.parsed_output?.answer); // 4
67
+ * ```
68
+ */
69
+ parse(params, options) {
70
+ return this.create(params, options).then((message) => (0, parser_1.parseMessage)(message, params, { logger: this._client.logger ?? console }));
71
+ }
72
+ /**
73
+ * Create a Message stream.
74
+ *
75
+ * If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
76
+ * the final message will include a `parsed_output` property with the parsed content.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const stream = client.messages.stream({
81
+ * model: 'claude-sonnet-4-5-20250929',
82
+ * max_tokens: 1024,
83
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
84
+ * output_config: {
85
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
86
+ * },
87
+ * });
88
+ *
89
+ * const message = await stream.finalMessage();
90
+ * console.log(message.parsed_output?.answer); // 4
91
+ * ```
92
+ */
93
+ stream(body, options) {
94
+ return MessageStream_1.MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
95
+ }
96
+ /**
97
+ * Count the number of tokens in a Message.
98
+ *
99
+ * The Token Count API can be used to count the number of tokens in a Message,
100
+ * including tools, images, and documents, without creating it.
101
+ *
102
+ * Learn more about token counting in our
103
+ * [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const messageTokensCount =
108
+ * await client.messages.countTokens({
109
+ * messages: [{ content: 'Hello, world', role: 'user' }],
110
+ * model: 'claude-opus-5',
111
+ * });
112
+ * ```
113
+ */
114
+ countTokens(params, options) {
115
+ const { user_profile_id, workspace_id, ...body } = params;
116
+ return this._client.post('/v1/messages/count_tokens', {
117
+ body,
118
+ ...options,
119
+ headers: (0, headers_1.buildHeaders)([
120
+ {
121
+ ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
122
+ ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
123
+ },
124
+ options?.headers,
125
+ ]),
126
+ });
32
127
  }
33
- // Collect helper info from tools and messages
34
- const helperHeader = (0, stainless_helper_header_1.stainlessHelperHeader)(body.tools, body.messages);
35
- return this._client.post('/v1/messages', {
36
- body,
37
- timeout: timeout ?? 600000,
38
- ...options,
39
- headers: (0, headers_1.buildHeaders)([
40
- {
41
- ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
42
- ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
43
- },
44
- helperHeader,
45
- options?.headers,
46
- ]),
47
- stream: params.stream ?? false,
48
- });
49
- }
50
- /**
51
- * Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
52
- * the response will be automatically parsed and available in the `parsed_output` property of the message.
53
- *
54
- * @example
55
- * ```ts
56
- * const message = await client.messages.parse({
57
- * model: 'claude-sonnet-4-5-20250929',
58
- * max_tokens: 1024,
59
- * messages: [{ role: 'user', content: 'What is 2+2?' }],
60
- * output_config: {
61
- * format: zodOutputFormat(z.object({ answer: z.number() })),
62
- * },
63
- * });
64
- *
65
- * console.log(message.parsed_output?.answer); // 4
66
- * ```
67
- */
68
- parse(params, options) {
69
- return this.create(params, options).then((message) => (0, parser_1.parseMessage)(message, params, { logger: this._client.logger ?? console }));
70
- }
71
- /**
72
- * Create a Message stream.
73
- *
74
- * If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
75
- * the final message will include a `parsed_output` property with the parsed content.
76
- *
77
- * @example
78
- * ```ts
79
- * const stream = client.messages.stream({
80
- * model: 'claude-sonnet-4-5-20250929',
81
- * max_tokens: 1024,
82
- * messages: [{ role: 'user', content: 'What is 2+2?' }],
83
- * output_config: {
84
- * format: zodOutputFormat(z.object({ answer: z.number() })),
85
- * },
86
- * });
87
- *
88
- * const message = await stream.finalMessage();
89
- * console.log(message.parsed_output?.answer); // 4
90
- * ```
91
- */
92
- stream(body, options) {
93
- return MessageStream_1.MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
94
- }
95
- /**
96
- * Count the number of tokens in a Message.
97
- *
98
- * The Token Count API can be used to count the number of tokens in a Message,
99
- * including tools, images, and documents, without creating it.
100
- *
101
- * Learn more about token counting in our
102
- * [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
103
- *
104
- * @example
105
- * ```ts
106
- * const messageTokensCount =
107
- * await client.messages.countTokens({
108
- * messages: [{ content: 'Hello, world', role: 'user' }],
109
- * model: 'claude-opus-5',
110
- * });
111
- * ```
112
- */
113
- countTokens(params, options) {
114
- const { user_profile_id, workspace_id, ...body } = params;
115
- return this._client.post('/v1/messages/count_tokens', {
116
- body,
117
- ...options,
118
- headers: (0, headers_1.buildHeaders)([
119
- {
120
- ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
121
- ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
122
- },
123
- options?.headers,
124
- ]),
125
- });
126
128
  }
127
- }
129
+ Messages.Batches = batches_1.Batches;
130
+ return Messages;
131
+ })();
128
132
  exports.Messages = Messages;
129
133
  const DEPRECATED_MODELS = {};
130
134
  const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-mythos-preview', 'claude-opus-4-6'];
131
- Messages.Batches = batches_1.Batches;
132
135
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":";;;;AACA,qDAAkD;AAElD,uDAAsD;AAEtD,uFAA+E;AAC/E,8DAAwD;AACxD,gDAK0B;AAC1B,iEAAwC;AACxC,0CAkBmB;AAGnB,2DAAqE;AAErE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BAAiB,GAEnB,EAAE,CAAC;AAEP,MAAM,oCAAoC,GAAY,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC"}
@@ -6,122 +6,125 @@ import { parseMessage, } from "../../lib/parser.mjs";
6
6
  import * as BatchesAPI from "./batches.mjs";
7
7
  import { Batches, } from "./batches.mjs";
8
8
  import { MODEL_NONSTREAMING_TOKENS } from "../../internal/constants.mjs";
9
- export class Messages extends APIResource {
10
- constructor() {
11
- super(...arguments);
12
- this.batches = new BatchesAPI.Batches(this._client);
13
- }
14
- create(params, options) {
15
- const { user_profile_id, workspace_id, ...body } = params;
16
- if (body.model in DEPRECATED_MODELS) {
17
- console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
9
+ export var Messages = /* @__PURE__ */ (() => {
10
+ class Messages extends APIResource {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.batches = new BatchesAPI.Batches(this._client);
18
14
  }
19
- if (MODELS_TO_WARN_WITH_THINKING_ENABLED.includes(body.model) &&
20
- body.thinking &&
21
- body.thinking.type === 'enabled') {
22
- console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
15
+ create(params, options) {
16
+ const { user_profile_id, workspace_id, ...body } = params;
17
+ if (body.model in DEPRECATED_MODELS) {
18
+ console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
19
+ }
20
+ if (MODELS_TO_WARN_WITH_THINKING_ENABLED.includes(body.model) &&
21
+ body.thinking &&
22
+ body.thinking.type === 'enabled') {
23
+ console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
24
+ }
25
+ let timeout = options?.timeout ?? this._client._options.timeout;
26
+ if (!body.stream && timeout == null) {
27
+ const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
28
+ timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
29
+ }
30
+ // Collect helper info from tools and messages
31
+ const helperHeader = stainlessHelperHeader(body.tools, body.messages);
32
+ return this._client.post('/v1/messages', {
33
+ body,
34
+ timeout: timeout ?? 600000,
35
+ ...options,
36
+ headers: buildHeaders([
37
+ {
38
+ ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
39
+ ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
40
+ },
41
+ helperHeader,
42
+ options?.headers,
43
+ ]),
44
+ stream: params.stream ?? false,
45
+ });
23
46
  }
24
- let timeout = options?.timeout ?? this._client._options.timeout;
25
- if (!body.stream && timeout == null) {
26
- const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
27
- timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
47
+ /**
48
+ * Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
49
+ * the response will be automatically parsed and available in the `parsed_output` property of the message.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const message = await client.messages.parse({
54
+ * model: 'claude-sonnet-4-5-20250929',
55
+ * max_tokens: 1024,
56
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
57
+ * output_config: {
58
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
59
+ * },
60
+ * });
61
+ *
62
+ * console.log(message.parsed_output?.answer); // 4
63
+ * ```
64
+ */
65
+ parse(params, options) {
66
+ return this.create(params, options).then((message) => parseMessage(message, params, { logger: this._client.logger ?? console }));
67
+ }
68
+ /**
69
+ * Create a Message stream.
70
+ *
71
+ * If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
72
+ * the final message will include a `parsed_output` property with the parsed content.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const stream = client.messages.stream({
77
+ * model: 'claude-sonnet-4-5-20250929',
78
+ * max_tokens: 1024,
79
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
80
+ * output_config: {
81
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
82
+ * },
83
+ * });
84
+ *
85
+ * const message = await stream.finalMessage();
86
+ * console.log(message.parsed_output?.answer); // 4
87
+ * ```
88
+ */
89
+ stream(body, options) {
90
+ return MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
91
+ }
92
+ /**
93
+ * Count the number of tokens in a Message.
94
+ *
95
+ * The Token Count API can be used to count the number of tokens in a Message,
96
+ * including tools, images, and documents, without creating it.
97
+ *
98
+ * Learn more about token counting in our
99
+ * [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const messageTokensCount =
104
+ * await client.messages.countTokens({
105
+ * messages: [{ content: 'Hello, world', role: 'user' }],
106
+ * model: 'claude-opus-5',
107
+ * });
108
+ * ```
109
+ */
110
+ countTokens(params, options) {
111
+ const { user_profile_id, workspace_id, ...body } = params;
112
+ return this._client.post('/v1/messages/count_tokens', {
113
+ body,
114
+ ...options,
115
+ headers: buildHeaders([
116
+ {
117
+ ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
118
+ ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
119
+ },
120
+ options?.headers,
121
+ ]),
122
+ });
28
123
  }
29
- // Collect helper info from tools and messages
30
- const helperHeader = stainlessHelperHeader(body.tools, body.messages);
31
- return this._client.post('/v1/messages', {
32
- body,
33
- timeout: timeout ?? 600000,
34
- ...options,
35
- headers: buildHeaders([
36
- {
37
- ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
38
- ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
39
- },
40
- helperHeader,
41
- options?.headers,
42
- ]),
43
- stream: params.stream ?? false,
44
- });
45
- }
46
- /**
47
- * Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
48
- * the response will be automatically parsed and available in the `parsed_output` property of the message.
49
- *
50
- * @example
51
- * ```ts
52
- * const message = await client.messages.parse({
53
- * model: 'claude-sonnet-4-5-20250929',
54
- * max_tokens: 1024,
55
- * messages: [{ role: 'user', content: 'What is 2+2?' }],
56
- * output_config: {
57
- * format: zodOutputFormat(z.object({ answer: z.number() })),
58
- * },
59
- * });
60
- *
61
- * console.log(message.parsed_output?.answer); // 4
62
- * ```
63
- */
64
- parse(params, options) {
65
- return this.create(params, options).then((message) => parseMessage(message, params, { logger: this._client.logger ?? console }));
66
- }
67
- /**
68
- * Create a Message stream.
69
- *
70
- * If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
71
- * the final message will include a `parsed_output` property with the parsed content.
72
- *
73
- * @example
74
- * ```ts
75
- * const stream = client.messages.stream({
76
- * model: 'claude-sonnet-4-5-20250929',
77
- * max_tokens: 1024,
78
- * messages: [{ role: 'user', content: 'What is 2+2?' }],
79
- * output_config: {
80
- * format: zodOutputFormat(z.object({ answer: z.number() })),
81
- * },
82
- * });
83
- *
84
- * const message = await stream.finalMessage();
85
- * console.log(message.parsed_output?.answer); // 4
86
- * ```
87
- */
88
- stream(body, options) {
89
- return MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
90
- }
91
- /**
92
- * Count the number of tokens in a Message.
93
- *
94
- * The Token Count API can be used to count the number of tokens in a Message,
95
- * including tools, images, and documents, without creating it.
96
- *
97
- * Learn more about token counting in our
98
- * [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
99
- *
100
- * @example
101
- * ```ts
102
- * const messageTokensCount =
103
- * await client.messages.countTokens({
104
- * messages: [{ content: 'Hello, world', role: 'user' }],
105
- * model: 'claude-opus-5',
106
- * });
107
- * ```
108
- */
109
- countTokens(params, options) {
110
- const { user_profile_id, workspace_id, ...body } = params;
111
- return this._client.post('/v1/messages/count_tokens', {
112
- body,
113
- ...options,
114
- headers: buildHeaders([
115
- {
116
- ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
117
- ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
118
- },
119
- options?.headers,
120
- ]),
121
- });
122
124
  }
123
- }
125
+ Messages.Batches = Batches;
126
+ return Messages;
127
+ })();
124
128
  const DEPRECATED_MODELS = {};
125
129
  const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-mythos-preview', 'claude-opus-4-6'];
126
- Messages.Batches = Batches;
127
130
  //# sourceMappingURL=messages.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.mjs","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":"AACA,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,EAOL,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;IAwKrE,CAAC;IA1IC,MAAM,CACJ,MAA2B,EAC3B,OAAwB;QAExB,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC1D,IAAI,IAAI,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CACV,cAAc,IAAI,CAAC,KAAK,iDACtB,iBAAiB,CAAC,I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