anthropic 2.0.0 → 2.2.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +1 -1
  4. data/lib/anthropic/client.rb +8 -0
  5. data/lib/anthropic/helpers/bedrock/client.rb +5 -0
  6. data/lib/anthropic/helpers/bedrock/mantle_client.rb +5 -0
  7. data/lib/anthropic/helpers/stainless_helper_header.rb +1 -0
  8. data/lib/anthropic/helpers/threads/beta_message_thread.rb +635 -0
  9. data/lib/anthropic/helpers/tools/runner.rb +79 -11
  10. data/lib/anthropic/helpers/vertex/client.rb +5 -0
  11. data/lib/anthropic/internal/report_page_cursor.rb +2 -2
  12. data/lib/anthropic/internal/tracing.rb +2 -0
  13. data/lib/anthropic/models/anthropic_beta.rb +6 -0
  14. data/lib/anthropic/models/beta/beta_message_thread_param.rb +61 -0
  15. data/lib/anthropic/models/beta/beta_thread_continue_params.rb +29 -0
  16. data/lib/anthropic/models/beta/beta_thread_create_params.rb +21 -0
  17. data/lib/anthropic/models/beta/message_create_params.rb +13 -1
  18. data/lib/anthropic/models/beta/messages/batch_create_params.rb +13 -1
  19. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_cost_group.rb +271 -0
  20. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_cost_group_by.rb +40 -0
  21. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_cost_item.rb +57 -0
  22. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_cost_metrics.rb +57 -0
  23. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_cost_order_by.rb +22 -0
  24. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_usage_group.rb +247 -0
  25. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_usage_group_by.rb +38 -0
  26. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_usage_item.rb +57 -0
  27. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_usage_metrics.rb +79 -0
  28. data/lib/anthropic/models/beta/organization/analytics/beta_analytics_usage_order_by.rb +24 -0
  29. data/lib/anthropic/models/beta/organization/analytics/cost_list_params.rb +360 -0
  30. data/lib/anthropic/models/beta/organization/analytics/usage_list_params.rb +353 -0
  31. data/lib/anthropic/models/beta/organization/beta_analytics_actor.rb +81 -0
  32. data/lib/anthropic/models/beta/organization/beta_analytics_actor_type.rb +22 -0
  33. data/lib/anthropic/models/beta/organization/beta_analytics_api_actor.rb +27 -0
  34. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor.rb +42 -0
  35. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor_aws_provider.rb +35 -0
  36. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor_azure_provider.rb +27 -0
  37. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor_gcp_provider.rb +27 -0
  38. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor_oidc_provider.rb +27 -0
  39. data/lib/anthropic/models/beta/organization/beta_analytics_federated_actor_provider.rb +72 -0
  40. data/lib/anthropic/models/beta/organization/beta_analytics_grouped_cost_type.rb +21 -0
  41. data/lib/anthropic/models/beta/organization/beta_analytics_report_user_actor.rb +65 -0
  42. data/lib/anthropic/models/beta/organization/beta_analytics_service_account_actor.rb +27 -0
  43. data/lib/anthropic/models/beta/organization/beta_analytics_service_tier.rb +23 -0
  44. data/lib/anthropic/models/beta/organization/beta_analytics_speed.rb +19 -0
  45. data/lib/anthropic/models/beta/organization/beta_analytics_time_bucket_width.rb +20 -0
  46. data/lib/anthropic/models/beta/organization/beta_analytics_usage_cost_inference_geo.rb +19 -0
  47. data/lib/anthropic/models/beta/organization/beta_analytics_usage_cost_product_filter.rb +34 -0
  48. data/lib/anthropic/models/beta/organization/beta_analytics_usage_cost_sort_order.rb +19 -0
  49. data/lib/anthropic/models/beta/organization/beta_organization_rate_limit.rb +2 -1
  50. data/lib/anthropic/models/beta/organization/beta_plugin.rb +12 -6
  51. data/lib/anthropic/models/beta/organization/beta_plugin_content_scan.rb +11 -5
  52. data/lib/anthropic/models/beta/organization/workspaces/beta_workspace_rate_limit.rb +2 -1
  53. data/lib/anthropic/models/organization/organization_rate_limit.rb +2 -1
  54. data/lib/anthropic/models/organization/workspaces/workspace_rate_limit.rb +2 -1
  55. data/lib/anthropic/models/user_profile.rb +26 -1
  56. data/lib/anthropic/models/user_profile_enforcement_action.rb +66 -0
  57. data/lib/anthropic/models/user_profile_enforcement_action_ban.rb +62 -0
  58. data/lib/anthropic/models/user_profile_enforcement_action_next_step.rb +17 -0
  59. data/lib/anthropic/models/user_profile_enforcement_action_reason.rb +23 -0
  60. data/lib/anthropic/models/user_profile_enforcement_action_restriction.rb +67 -0
  61. data/lib/anthropic/models/user_profile_enforcement_status.rb +20 -0
  62. data/lib/anthropic/models/user_profile_list_params.rb +17 -1
  63. data/lib/anthropic/models.rb +12 -0
  64. data/lib/anthropic/resources/beta/messages.rb +78 -4
  65. data/lib/anthropic/resources/beta/organization/analytics/cost.rb +175 -0
  66. data/lib/anthropic/resources/beta/organization/analytics/cost_report.rb +13 -6
  67. data/lib/anthropic/resources/beta/organization/analytics/usage.rb +176 -0
  68. data/lib/anthropic/resources/beta/organization/analytics/usage_report.rb +9 -2
  69. data/lib/anthropic/resources/beta/organization/analytics/user_cost_report.rb +12 -5
  70. data/lib/anthropic/resources/beta/organization/analytics/user_usage_report.rb +15 -8
  71. data/lib/anthropic/resources/beta/organization/analytics.rb +8 -0
  72. data/lib/anthropic/resources/beta/organization/plugin_marketplaces.rb +6 -6
  73. data/lib/anthropic/resources/beta/organization/plugins.rb +12 -9
  74. data/lib/anthropic/resources/user_profiles.rb +5 -3
  75. data/lib/anthropic/version.rb +1 -1
  76. data/lib/anthropic.rb +42 -0
  77. data/rbi/anthropic/client.rbi +5 -0
  78. data/rbi/anthropic/helpers/bedrock/client.rbi +5 -0
  79. data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +5 -0
  80. data/rbi/anthropic/helpers/threads/beta_message_thread.rbi +100 -0
  81. data/rbi/anthropic/helpers/vertex/client.rbi +5 -0
  82. data/rbi/anthropic/internal/tracing.rbi +4 -0
  83. data/rbi/anthropic/models/anthropic_beta.rbi +10 -0
  84. data/rbi/anthropic/models/beta/beta_message_thread_param.rbi +80 -0
  85. data/rbi/anthropic/models/beta/beta_thread_continue_params.rbi +43 -0
  86. data/rbi/anthropic/models/beta/beta_thread_create_params.rbi +31 -0
  87. data/rbi/anthropic/models/beta/message_create_params.rbi +37 -0
  88. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +37 -0
  89. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_group.rbi +439 -0
  90. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_group_by.rbi +140 -0
  91. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_item.rbi +110 -0
  92. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_metrics.rbi +79 -0
  93. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_order_by.rbi +50 -0
  94. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_group.rbi +399 -0
  95. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_group_by.rbi +130 -0
  96. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_item.rbi +110 -0
  97. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_metrics.rbi +120 -0
  98. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_order_by.rbi +60 -0
  99. data/rbi/anthropic/models/beta/organization/analytics/cost_list_params.rbi +624 -0
  100. data/rbi/anthropic/models/beta/organization/analytics/usage_list_params.rbi +612 -0
  101. data/rbi/anthropic/models/beta/organization/beta_analytics_actor.rbi +134 -0
  102. data/rbi/anthropic/models/beta/organization/beta_analytics_actor_type.rbi +54 -0
  103. data/rbi/anthropic/models/beta/organization/beta_analytics_api_actor.rbi +40 -0
  104. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor.rbi +75 -0
  105. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_aws_provider.rbi +54 -0
  106. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_azure_provider.rbi +42 -0
  107. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_gcp_provider.rbi +42 -0
  108. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_oidc_provider.rbi +42 -0
  109. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_provider.rbi +107 -0
  110. data/rbi/anthropic/models/beta/organization/beta_analytics_grouped_cost_type.rbi +53 -0
  111. data/rbi/anthropic/models/beta/organization/beta_analytics_report_user_actor.rbi +94 -0
  112. data/rbi/anthropic/models/beta/organization/beta_analytics_service_account_actor.rbi +42 -0
  113. data/rbi/anthropic/models/beta/organization/beta_analytics_service_tier.rbi +63 -0
  114. data/rbi/anthropic/models/beta/organization/beta_analytics_speed.rbi +40 -0
  115. data/rbi/anthropic/models/beta/organization/beta_analytics_time_bucket_width.rbi +48 -0
  116. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_inference_geo.rbi +43 -0
  117. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_product_filter.rbi +98 -0
  118. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_sort_order.rbi +43 -0
  119. data/rbi/anthropic/models/beta/organization/beta_organization_rate_limit.rbi +4 -2
  120. data/rbi/anthropic/models/beta/organization/beta_plugin.rbi +20 -8
  121. data/rbi/anthropic/models/beta/organization/beta_plugin_content_scan.rbi +15 -6
  122. data/rbi/anthropic/models/beta/organization/workspaces/beta_workspace_rate_limit.rbi +4 -2
  123. data/rbi/anthropic/models/organization/organization_rate_limit.rbi +4 -2
  124. data/rbi/anthropic/models/organization/workspaces/workspace_rate_limit.rbi +4 -2
  125. data/rbi/anthropic/models/user_profile.rbi +42 -0
  126. data/rbi/anthropic/models/user_profile_enforcement_action.rbi +95 -0
  127. data/rbi/anthropic/models/user_profile_enforcement_action_ban.rbi +96 -0
  128. data/rbi/anthropic/models/user_profile_enforcement_action_next_step.rbi +34 -0
  129. data/rbi/anthropic/models/user_profile_enforcement_action_reason.rbi +58 -0
  130. data/rbi/anthropic/models/user_profile_enforcement_action_restriction.rbi +106 -0
  131. data/rbi/anthropic/models/user_profile_enforcement_status.rbi +39 -0
  132. data/rbi/anthropic/models/user_profile_list_params.rbi +36 -0
  133. data/rbi/anthropic/models.rbi +16 -0
  134. data/rbi/anthropic/resources/beta/messages.rbi +191 -0
  135. data/rbi/anthropic/resources/beta/organization/analytics/cost.rbi +245 -0
  136. data/rbi/anthropic/resources/beta/organization/analytics/cost_report.rbi +12 -5
  137. data/rbi/anthropic/resources/beta/organization/analytics/usage.rbi +240 -0
  138. data/rbi/anthropic/resources/beta/organization/analytics/usage_report.rbi +9 -2
  139. data/rbi/anthropic/resources/beta/organization/analytics/user_cost_report.rbi +12 -5
  140. data/rbi/anthropic/resources/beta/organization/analytics/user_usage_report.rbi +14 -7
  141. data/rbi/anthropic/resources/beta/organization/analytics.rbi +10 -0
  142. data/rbi/anthropic/resources/beta/organization/plugin_marketplaces.rbi +6 -6
  143. data/rbi/anthropic/resources/beta/organization/plugins.rbi +12 -9
  144. data/rbi/anthropic/resources/user_profiles.rbi +12 -0
  145. data/rbi/lib/anthropic/helpers/stainless_helper_header.rbi +2 -0
  146. data/sig/anthropic/client.rbs +2 -0
  147. data/sig/anthropic/helpers/bedrock/client.rbs +2 -0
  148. data/sig/anthropic/helpers/threads/beta_message_thread.rbs +40 -0
  149. data/sig/anthropic/helpers/tools/runner.rbs +40 -0
  150. data/sig/anthropic/helpers/vertex/client.rbs +2 -0
  151. data/sig/anthropic/internal/tracing.rbs +2 -0
  152. data/sig/anthropic/models/anthropic_beta.rbs +4 -0
  153. data/sig/anthropic/models/beta/beta_message_thread_param.rbs +40 -0
  154. data/sig/anthropic/models/beta/beta_thread_continue_params.rbs +20 -0
  155. data/sig/anthropic/models/beta/beta_thread_create_params.rbs +17 -0
  156. data/sig/anthropic/models/beta/message_create_params.rbs +5 -0
  157. data/sig/anthropic/models/beta/messages/batch_create_params.rbs +5 -0
  158. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_group.rbs +126 -0
  159. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_group_by.rbs +60 -0
  160. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_item.rbs +41 -0
  161. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_metrics.rbs +41 -0
  162. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_order_by.rbs +21 -0
  163. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_group.rbs +116 -0
  164. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_group_by.rbs +56 -0
  165. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_item.rbs +41 -0
  166. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_metrics.rbs +56 -0
  167. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_order_by.rbs +28 -0
  168. data/sig/anthropic/models/beta/organization/analytics/cost_list_params.rbs +188 -0
  169. data/sig/anthropic/models/beta/organization/analytics/usage_list_params.rbs +188 -0
  170. data/sig/anthropic/models/beta/organization/beta_analytics_actor.rbs +67 -0
  171. data/sig/anthropic/models/beta/organization/beta_analytics_actor_type.rbs +21 -0
  172. data/sig/anthropic/models/beta/organization/beta_analytics_api_actor.rbs +19 -0
  173. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor.rbs +34 -0
  174. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_aws_provider.rbs +30 -0
  175. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_azure_provider.rbs +20 -0
  176. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_gcp_provider.rbs +20 -0
  177. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_oidc_provider.rbs +20 -0
  178. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_provider.rbs +60 -0
  179. data/sig/anthropic/models/beta/organization/beta_analytics_grouped_cost_type.rbs +21 -0
  180. data/sig/anthropic/models/beta/organization/beta_analytics_report_user_actor.rbs +44 -0
  181. data/sig/anthropic/models/beta/organization/beta_analytics_service_account_actor.rbs +26 -0
  182. data/sig/anthropic/models/beta/organization/beta_analytics_service_tier.rbs +28 -0
  183. data/sig/anthropic/models/beta/organization/beta_analytics_speed.rbs +18 -0
  184. data/sig/anthropic/models/beta/organization/beta_analytics_time_bucket_width.rbs +19 -0
  185. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_inference_geo.rbs +18 -0
  186. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_product_filter.rbs +40 -0
  187. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_sort_order.rbs +18 -0
  188. data/sig/anthropic/models/user_profile.rbs +10 -0
  189. data/sig/anthropic/models/user_profile_enforcement_action.rbs +50 -0
  190. data/sig/anthropic/models/user_profile_enforcement_action_ban.rbs +45 -0
  191. data/sig/anthropic/models/user_profile_enforcement_action_next_step.rbs +13 -0
  192. data/sig/anthropic/models/user_profile_enforcement_action_reason.rbs +24 -0
  193. data/sig/anthropic/models/user_profile_enforcement_action_restriction.rbs +45 -0
  194. data/sig/anthropic/models/user_profile_enforcement_status.rbs +17 -0
  195. data/sig/anthropic/models/user_profile_list_params.rbs +9 -0
  196. data/sig/anthropic/models.rbs +12 -0
  197. data/sig/anthropic/resources/beta/messages.rbs +33 -0
  198. data/sig/anthropic/resources/beta/organization/analytics/cost.rbs +46 -0
  199. data/sig/anthropic/resources/beta/organization/analytics/usage.rbs +46 -0
  200. data/sig/anthropic/resources/beta/organization/analytics.rbs +4 -0
  201. data/sig/anthropic/resources/user_profiles.rbs +1 -0
  202. metadata +130 -3
@@ -66,6 +66,7 @@ module Anthropic
66
66
  ],
67
67
  betas: T::Array[T.any(String, Anthropic::AnthropicBeta::OrSymbol)],
68
68
  max_iterations: T.nilable(Integer),
69
+ thread: T.nilable(FalseClass),
69
70
  stream: T.noreturn,
70
71
  request_options: Anthropic::RequestOptions::OrHash
71
72
  ).returns(Anthropic::Helpers::Tools::Runner)
@@ -274,6 +275,11 @@ module Anthropic
274
275
  betas: nil,
275
276
  # The most requests the runner sends before it stops. No limit when `nil`.
276
277
  max_iterations: nil,
278
+ # The runner sends its requests on a message thread, so that each request after
279
+ # the first carries only the messages that are new. `false` sends the whole
280
+ # history with every request instead. `nil` leaves the thread on, and anything
281
+ # else raises `ArgumentError`.
282
+ thread: nil,
277
283
  # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
278
284
  # for streaming and non-streaming use cases, respectively.
279
285
  stream: false,
@@ -281,6 +287,152 @@ module Anthropic
281
287
  )
282
288
  end
283
289
 
290
+ # Creates a message thread: a conversation that the API keeps between requests, so
291
+ # that each turn sends only the messages that are new. It sends no request.
292
+ #
293
+ # Takes the keywords of `#create` except `thread` and `stream`.
294
+ sig do
295
+ params(
296
+ max_tokens: Integer,
297
+ model: T.any(Anthropic::Model::OrSymbol, String),
298
+ messages:
299
+ T::Array[
300
+ T.any(
301
+ Anthropic::Beta::BetaUserMessageParam::OrHash,
302
+ Anthropic::Beta::BetaAssistantMessageParam::OrHash,
303
+ Anthropic::Beta::BetaSystemMessageParam::OrHash
304
+ )
305
+ ],
306
+ cache_control:
307
+ T.nilable(Anthropic::Beta::BetaCacheControlEphemeral::OrHash),
308
+ compaction:
309
+ T.nilable(Anthropic::Beta::BetaCompactionConfig::OrHash),
310
+ container:
311
+ T.nilable(
312
+ T.any(Anthropic::Beta::BetaContainerParams::OrHash, String)
313
+ ),
314
+ context_management:
315
+ T.nilable(Anthropic::Beta::BetaContextManagementConfig::OrHash),
316
+ diagnostics:
317
+ T.nilable(Anthropic::Beta::BetaDiagnosticsParam::OrHash),
318
+ fallback_credit_token:
319
+ T.nilable(
320
+ T.any(
321
+ Anthropic::Beta::BetaFallbackCreditTokenParam::OrHash,
322
+ String
323
+ )
324
+ ),
325
+ fallbacks:
326
+ T.nilable(
327
+ T.any(
328
+ Symbol,
329
+ T::Array[Anthropic::Beta::BetaFallbackParam::OrHash]
330
+ )
331
+ ),
332
+ inference_geo: T.nilable(String),
333
+ mcp_servers:
334
+ T::Array[
335
+ Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
336
+ ],
337
+ metadata: Anthropic::Beta::BetaMetadata::OrHash,
338
+ output_config: Anthropic::Beta::BetaOutputConfig::OrHash,
339
+ output_format:
340
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash),
341
+ service_tier:
342
+ Anthropic::Beta::MessageCreateParams::ServiceTier::OrSymbol,
343
+ speed:
344
+ T.nilable(Anthropic::Beta::MessageCreateParams::Speed::OrSymbol),
345
+ stop_sequences: T::Array[String],
346
+ system_: Anthropic::Beta::MessageCreateParams::System::Variants,
347
+ thinking:
348
+ T.any(
349
+ Anthropic::Beta::BetaThinkingConfigEnabled::OrHash,
350
+ Anthropic::Beta::BetaThinkingConfigDisabled::OrHash,
351
+ Anthropic::Beta::BetaThinkingConfigBetweenTools::OrHash,
352
+ Anthropic::Beta::BetaThinkingConfigAdaptive::OrHash
353
+ ),
354
+ tool_choice:
355
+ T.any(
356
+ Anthropic::Beta::BetaToolChoiceAuto::OrHash,
357
+ Anthropic::Beta::BetaToolChoiceAny::OrHash,
358
+ Anthropic::Beta::BetaToolChoiceTool::OrHash,
359
+ Anthropic::Beta::BetaToolChoiceNone::OrHash
360
+ ),
361
+ tools:
362
+ T::Array[
363
+ T.any(
364
+ Anthropic::Beta::BetaTool::OrHash,
365
+ Anthropic::Beta::BetaToolBash20241022::OrHash,
366
+ Anthropic::Beta::BetaToolBash20250124::OrHash,
367
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
368
+ Anthropic::Beta::BetaCodeExecutionTool20250825::OrHash,
369
+ Anthropic::Beta::BetaCodeExecutionTool20260120::OrHash,
370
+ Anthropic::Beta::BetaCodeExecutionTool20260521::OrHash,
371
+ Anthropic::Beta::BetaBrowserToolset20260801::OrHash,
372
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
373
+ Anthropic::Beta::BetaMemoryTool20250818::OrHash,
374
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
375
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
376
+ Anthropic::Beta::BetaToolComputerUse20251124::OrHash,
377
+ Anthropic::Beta::BetaComputerToolset20260801::OrHash,
378
+ Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
379
+ Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
380
+ Anthropic::Beta::BetaToolTextEditor20250728::OrHash,
381
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
382
+ Anthropic::Beta::BetaWebFetchTool20250910::OrHash,
383
+ Anthropic::Beta::BetaWebSearchTool20260209::OrHash,
384
+ Anthropic::Beta::BetaWebFetchTool20260209::OrHash,
385
+ Anthropic::Beta::BetaWebFetchTool20260309::OrHash,
386
+ Anthropic::Beta::BetaWebSearchTool20260318::OrHash,
387
+ Anthropic::Beta::BetaWebFetchTool20260318::OrHash,
388
+ Anthropic::Beta::BetaAdvisorTool20260301::OrHash,
389
+ Anthropic::Beta::BetaToolSearchToolBm25_20251119::OrHash,
390
+ Anthropic::Beta::BetaToolSearchToolRegex20251119::OrHash,
391
+ Anthropic::Beta::BetaMCPToolset::OrHash
392
+ )
393
+ ],
394
+ betas: T::Array[T.any(Anthropic::AnthropicBeta::OrSymbol, String)],
395
+ user_profile_id: String,
396
+ workspace_id: String,
397
+ unsupported_request_behavior: Symbol,
398
+ request_options: Anthropic::RequestOptions::OrHash
399
+ ).returns(Anthropic::Helpers::Threads::BetaMessageThread)
400
+ end
401
+ def thread(
402
+ max_tokens:,
403
+ model:,
404
+ # The messages that seed the history. The first turn sends them.
405
+ messages: nil,
406
+ cache_control: nil,
407
+ compaction: nil,
408
+ container: nil,
409
+ context_management: nil,
410
+ diagnostics: nil,
411
+ fallback_credit_token: nil,
412
+ fallbacks: nil,
413
+ inference_geo: nil,
414
+ mcp_servers: nil,
415
+ metadata: nil,
416
+ output_config: nil,
417
+ output_format: nil,
418
+ service_tier: nil,
419
+ speed: nil,
420
+ stop_sequences: nil,
421
+ system_: nil,
422
+ thinking: nil,
423
+ tool_choice: nil,
424
+ tools: nil,
425
+ betas: nil,
426
+ user_profile_id: nil,
427
+ workspace_id: nil,
428
+ # What a turn does when the API cannot serve the request on a thread: `:error`
429
+ # (the default) raises the error, and `:continue_unthreaded` sends the turn again,
430
+ # and every later turn, with the whole history and no thread.
431
+ unsupported_request_behavior: :error,
432
+ request_options: {}
433
+ )
434
+ end
435
+
284
436
  # See {Anthropic::Resources::Beta::Messages#stream_raw} for streaming counterpart.
285
437
  #
286
438
  # Send a structured list of input messages with text and/or image content, and the
@@ -351,6 +503,13 @@ module Anthropic
351
503
  Anthropic::Beta::BetaThinkingConfigBetweenTools::OrHash,
352
504
  Anthropic::Beta::BetaThinkingConfigAdaptive::OrHash
353
505
  ),
506
+ thread:
507
+ T.nilable(
508
+ T.any(
509
+ Anthropic::Beta::BetaThreadCreateParams::OrHash,
510
+ Anthropic::Beta::BetaThreadContinueParams::OrHash
511
+ )
512
+ ),
354
513
  tool_choice:
355
514
  T.any(
356
515
  Anthropic::Beta::BetaToolChoiceAuto::OrHash,
@@ -598,6 +757,12 @@ module Anthropic
598
757
  # [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking)
599
758
  # for each model's behavior.
600
759
  thinking: nil,
760
+ # Body param: Server-held conversation state (a Thread). `{"type": "create"}` asks
761
+ # the server to hold this conversation's state under the response's `id`;
762
+ # `{"type": "continue", "previous_message_id": ...}` resumes from a previous
763
+ # response so only the new turn's messages are sent. The response shape is
764
+ # unchanged.
765
+ thread: nil,
601
766
  # Body param: How the model should use the provided tools. The model can use a
602
767
  # specific tool, any available tool, decide by itself, or not use tools at all.
603
768
  tool_choice: nil,
@@ -768,6 +933,13 @@ module Anthropic
768
933
  Anthropic::Beta::BetaThinkingConfigBetweenTools::OrHash,
769
934
  Anthropic::Beta::BetaThinkingConfigAdaptive::OrHash
770
935
  ),
936
+ thread:
937
+ T.nilable(
938
+ T.any(
939
+ Anthropic::Beta::BetaThreadCreateParams::OrHash,
940
+ Anthropic::Beta::BetaThreadContinueParams::OrHash
941
+ )
942
+ ),
771
943
  tool_choice:
772
944
  T.any(
773
945
  Anthropic::Beta::BetaToolChoiceAuto::OrHash,
@@ -1020,6 +1192,12 @@ module Anthropic
1020
1192
  # [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking)
1021
1193
  # for each model's behavior.
1022
1194
  thinking: nil,
1195
+ # Body param: Server-held conversation state (a Thread). `{"type": "create"}` asks
1196
+ # the server to hold this conversation's state under the response's `id`;
1197
+ # `{"type": "continue", "previous_message_id": ...}` resumes from a previous
1198
+ # response so only the new turn's messages are sent. The response shape is
1199
+ # unchanged.
1200
+ thread: nil,
1023
1201
  # Body param: How the model should use the provided tools. The model can use a
1024
1202
  # specific tool, any available tool, decide by itself, or not use tools at all.
1025
1203
  tool_choice: nil,
@@ -1499,6 +1677,13 @@ module Anthropic
1499
1677
  Anthropic::Beta::BetaThinkingConfigBetweenTools::OrHash,
1500
1678
  Anthropic::Beta::BetaThinkingConfigAdaptive::OrHash
1501
1679
  ),
1680
+ thread:
1681
+ T.nilable(
1682
+ T.any(
1683
+ Anthropic::Beta::BetaThreadCreateParams::OrHash,
1684
+ Anthropic::Beta::BetaThreadContinueParams::OrHash
1685
+ )
1686
+ ),
1502
1687
  tool_choice:
1503
1688
  T.any(
1504
1689
  Anthropic::Beta::BetaToolChoiceAuto::OrHash,
@@ -1745,6 +1930,12 @@ module Anthropic
1745
1930
  # [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking)
1746
1931
  # for each model's behavior.
1747
1932
  thinking: nil,
1933
+ # Body param: Server-held conversation state (a Thread). `{"type": "create"}` asks
1934
+ # the server to hold this conversation's state under the response's `id`;
1935
+ # `{"type": "continue", "previous_message_id": ...}` resumes from a previous
1936
+ # response so only the new turn's messages are sent. The response shape is
1937
+ # unchanged.
1938
+ thread: nil,
1748
1939
  # Body param: How the model should use the provided tools. The model can use a
1749
1940
  # specific tool, any available tool, decide by itself, or not use tools at all.
1750
1941
  tool_choice: nil,
@@ -0,0 +1,245 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Resources
5
+ class Beta
6
+ class Organization
7
+ class Analytics
8
+ class Cost
9
+ # Get cost in USD across a date range, broken out by dimension.
10
+ #
11
+ # Returns one row per combination of the requested `group_by[]` dimensions (and
12
+ # time bucket, when `time_bucket_width` is set) that has cost in the range, ranked
13
+ # by spend or ordered by time bucket; every combination is returned across pages.
14
+ # With no `group_by[]` and no `time_bucket_width`, a single row aggregates the
15
+ # whole range. Includes all cost, whether or not it is attributable to a seat
16
+ # user. Requires an API key with the `read:analytics` scope, or an Admin API key.
17
+ sig do
18
+ params(
19
+ starting_at: Time,
20
+ actor_ids: T.nilable(T::Array[String]),
21
+ actor_types:
22
+ T.nilable(
23
+ T::Array[
24
+ Anthropic::Beta::Organization::BetaAnalyticsActorType::OrSymbol
25
+ ]
26
+ ),
27
+ agent_ids: T.nilable(T::Array[String]),
28
+ api_key_ids: T.nilable(T::Array[String]),
29
+ claude_tag_categories:
30
+ T.nilable(
31
+ T::Array[
32
+ Anthropic::Beta::Organization::BetaAnalyticsClaudeTagCategory::OrSymbol
33
+ ]
34
+ ),
35
+ claude_tag_user_ids: T.nilable(T::Array[String]),
36
+ context_windows:
37
+ T.nilable(
38
+ T::Array[
39
+ Anthropic::Beta::Organization::BetaAnalyticsContextWindow::OrSymbol
40
+ ]
41
+ ),
42
+ deployment_ids: T.nilable(T::Array[String]),
43
+ ending_at: T.nilable(Time),
44
+ environment_ids: T.nilable(T::Array[String]),
45
+ exclude_deleted_users: T::Boolean,
46
+ group_by:
47
+ T.nilable(
48
+ T::Array[
49
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsCostGroupBy::OrSymbol
50
+ ]
51
+ ),
52
+ inference_geos:
53
+ T.nilable(
54
+ T::Array[
55
+ Anthropic::Beta::Organization::BetaAnalyticsInferenceGeoFilter::OrSymbol
56
+ ]
57
+ ),
58
+ limit: Integer,
59
+ models: T.nilable(T::Array[String]),
60
+ order:
61
+ Anthropic::Beta::Organization::BetaAnalyticsUsageCostSortOrder::OrSymbol,
62
+ order_by:
63
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsCostOrderBy::OrSymbol,
64
+ page: T.nilable(String),
65
+ products:
66
+ T.nilable(
67
+ T::Array[
68
+ Anthropic::Beta::Organization::BetaAnalyticsUsageCostProductFilter::OrSymbol
69
+ ]
70
+ ),
71
+ rbac_group_ids: T.nilable(T::Array[String]),
72
+ service_tiers:
73
+ T.nilable(
74
+ T::Array[
75
+ Anthropic::Beta::Organization::BetaAnalyticsServiceTier::OrSymbol
76
+ ]
77
+ ),
78
+ session_ids: T.nilable(T::Array[String]),
79
+ slack_channel_ids: T.nilable(T::Array[String]),
80
+ speeds:
81
+ T.nilable(
82
+ T::Array[
83
+ Anthropic::Beta::Organization::BetaAnalyticsSpeed::OrSymbol
84
+ ]
85
+ ),
86
+ time_bucket_width:
87
+ T.nilable(
88
+ Anthropic::Beta::Organization::BetaAnalyticsTimeBucketWidth::OrSymbol
89
+ ),
90
+ user_profile_ids: T.nilable(T::Array[String]),
91
+ workspace_ids: T.nilable(T::Array[String]),
92
+ betas:
93
+ T::Array[T.any(Anthropic::AnthropicBeta::OrSymbol, String)],
94
+ request_options: Anthropic::RequestOptions::OrHash
95
+ ).returns(
96
+ Anthropic::Internal::ReportPageCursor[
97
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsCostItem
98
+ ]
99
+ )
100
+ end
101
+ def list(
102
+ # Query param: Start of range, inclusive. RFC 3339 tz-aware. Must be within the
103
+ # last 365 days and no earlier than 2026-01-01T00:00:00Z.
104
+ starting_at:,
105
+ # Query param: Filter to usage attributed to specific identities, by tagged ID: a
106
+ # `user_...`, `svac_...` (service account), or `apikey_...` ID. An `apikey_` entry
107
+ # matches only usage attributed to the key itself, not usage on that key
108
+ # attributed to a user or service account (use `api_key_ids[]` for every request a
109
+ # key authenticated). Federated identities have no tagged ID; select them with
110
+ # `actor_types[]`. Use `group_by[]=actor` to break out per-identity values.
111
+ actor_ids: nil,
112
+ # Query param: Filter to usage attributed to specific kinds of identity. Use
113
+ # `group_by[]=actor_type` to break out per-kind values.
114
+ actor_types: nil,
115
+ # Query param: Filter to usage incurred by sessions of specific Claude Managed
116
+ # Agents agents. Use `group_by[]=agent_id` to break out per-agent values. Claude
117
+ # Developer Platform organizations only.
118
+ agent_ids: nil,
119
+ # Query param: Filter to usage authenticated by specific API keys, by tagged API
120
+ # key ID (`apikey_...`), whichever identity the usage is attributed to. Include an
121
+ # empty entry (`api_key_ids[]=`) to also match usage that no API key
122
+ # authenticated. Use `group_by[]=api_key_id` to break out per-key values; usage
123
+ # without a key has a null `api_key_id`. Claude Developer Platform organizations
124
+ # only.
125
+ api_key_ids: nil,
126
+ # Query param: Filter to Claude Tag (Claude in Slack) usage in specific spend
127
+ # categories. Usage with no category never matches. `dm` usage is reported under
128
+ # the user's product rather than `claude_tag`, so combining this filter with
129
+ # `products[]=claude_tag` excludes it. Use `group_by[]=claude_tag_category` to
130
+ # break out per-category values.
131
+ claude_tag_categories: nil,
132
+ # Query param: Filter to Claude Tag (Claude in Slack) usage attributed to specific
133
+ # Slack users, by Slack user ID (for example `U0123ABCDEF`), not claude.ai user
134
+ # ID. Usage that is not Claude Tag, and Claude Tag usage not attributed to a
135
+ # single user, never matches. Use `group_by[]=claude_tag_user_id` to break out
136
+ # per-user values.
137
+ claude_tag_user_ids: nil,
138
+ # Query param: Filter to specific context-window pricing tiers. Use
139
+ # `group_by[]=context_window` to break out per-tier values.
140
+ context_windows: nil,
141
+ # Query param: Filter to usage incurred by Claude Managed Agents sessions that
142
+ # specific deployments started. Use `group_by[]=deployment_id` to break out
143
+ # per-deployment values. Claude Developer Platform organizations only.
144
+ deployment_ids: nil,
145
+ # Query param: End of range, exclusive. Required when `time_bucket_width` is set.
146
+ # Without `time_bucket_width`, defaults to the earlier of now and `starting_at` +
147
+ # 31 days. The range may span at most 31 days.
148
+ ending_at: nil,
149
+ # Query param: Filter to usage incurred by Claude Managed Agents sessions that ran
150
+ # in specific environments. Use `group_by[]=environment_id` to break out
151
+ # per-environment values. Claude Developer Platform organizations only.
152
+ environment_ids: nil,
153
+ # Query param: If true, omit rows whose `actor` is a `user_actor` with
154
+ # `deleted: true`. Requires `group_by[]=actor`. Rows for other actor types, and
155
+ # rows whose `actor` is null, are always kept. A page may contain fewer than
156
+ # `limit` rows; use `has_more` and `next_page` to paginate as usual.
157
+ exclude_deleted_users: nil,
158
+ # Query param: Dimensions to break cost out by (at most 5, not counting
159
+ # `cost_type` and `token_type`): one row per combination of their values with cost
160
+ # in the range (and per time bucket, when `time_bucket_width` is set), every
161
+ # combination returned across pages rather than a capped top set. `cost_type` and
162
+ # `token_type` do not count toward `limit`: `cost_type` returns one row per cost
163
+ # component (tokens, web search, code execution, and `session_usage`, Claude
164
+ # Managed Agents session time); `token_type` returns one row per token type, each
165
+ # with `cost_type: "tokens"`; combining both returns the per-token-type rows plus
166
+ # the web-search, code-execution and session-usage rows. When omitted, a single
167
+ # row aggregates the whole range.
168
+ group_by: nil,
169
+ # Query param: Filter to specific inference regions. `not_available` matches rows
170
+ # where the region is unset. Use `group_by[]=inference_geo` to break out
171
+ # per-region values.
172
+ inference_geos: nil,
173
+ # Query param: Number of rows per page (1-1000, default 20).
174
+ # `cost_type`/`token_type` fan-out rows (cost endpoint only) do not count toward
175
+ # this limit, so `data` can exceed it.
176
+ limit: nil,
177
+ # Query param: Models to include. Defaults to all models. Use `group_by[]=model`
178
+ # to break out per-model values.
179
+ models: nil,
180
+ # Query param: Sort direction of the `order_by` metric, or of the time buckets
181
+ # when `order_by` is `time` and `time_bucket_width` is set. Defaults to `desc`.
182
+ order: nil,
183
+ # Query param: Row order. A metric ranks rows by that metric in the `order`
184
+ # direction. `time` orders rows by time bucket in the `order` direction (newest
185
+ # first by default) and, within a bucket, by `amount`, highest first. `time` takes
186
+ # effect only with `time_bucket_width`; without it, `time` is the same as
187
+ # `amount`. Defaults to `amount`.
188
+ order_by: nil,
189
+ # Query param: Opaque cursor from a previous response's `next_page` field.
190
+ page: nil,
191
+ # Query param: Product surfaces to include. Defaults to all products.
192
+ products: nil,
193
+ # Query param: Filter to usage attributed to specific RBAC groups. Accepts tagged
194
+ # RBAC group IDs (`rbac_group_...`) or bare group UUIDs. A row matches when the
195
+ # user belonged to any of the listed groups on the (UTC) day the usage occurred;
196
+ # usage with no group attribution never matches.
197
+ rbac_group_ids: nil,
198
+ # Query param: Filter to specific service tiers. Use `group_by[]=service_tier` to
199
+ # break out per-tier values. Claude Developer Platform organizations only; matches
200
+ # nothing for a Claude Enterprise organization.
201
+ service_tiers: nil,
202
+ # Query param: Filter to usage incurred by specific Claude Managed Agents
203
+ # sessions, by tagged session ID (`sesn_...`). Use `group_by[]=session_id` to
204
+ # break out per-session values. Claude Developer Platform organizations only.
205
+ session_ids: nil,
206
+ # Query param: Filter to usage originating from specific Slack channels. Use
207
+ # `group_by[]=slack_channel_id` to break out per-channel values.
208
+ slack_channel_ids: nil,
209
+ # Query param: Filter to fast or standard inference mode. Use `group_by[]=speed`
210
+ # to break out per-mode values.
211
+ speeds: nil,
212
+ # Query param: Time-bucket granularity. When set, rows are returned per time
213
+ # bucket (one per bucket and dimension combination with usage) and each row's
214
+ # `starting_at` and `ending_at` are that bucket's bounds; the time bucket counts
215
+ # toward `limit`. `ending_at` is required when `time_bucket_width` is set, and
216
+ # with `time_bucket_width="1m"` the range may span at most 24 hours. When omitted,
217
+ # each row aggregates the requested range with `starting_at` and `ending_at` each
218
+ # rounded down to the hour.
219
+ time_bucket_width: nil,
220
+ # Query param: Filter to usage attributed to specific user profiles, by tagged
221
+ # user profile ID (`uprof_...`). Use `group_by[]=user_profile_id` to break out
222
+ # per-profile values. Claude Developer Platform organizations only.
223
+ user_profile_ids: nil,
224
+ # Query param: Filter to usage in specific workspaces, by tagged workspace ID
225
+ # (`wrkspc_...`). Use `group_by[]=workspace_id` to break out per-workspace values.
226
+ # Claude Developer Platform organizations only; matches nothing for a Claude
227
+ # Enterprise organization.
228
+ workspace_ids: nil,
229
+ # Header param: This endpoint is in beta: requests must send
230
+ # `analytics-usage-cost-2026-08-24` in this header.
231
+ betas: nil,
232
+ request_options: {}
233
+ )
234
+ end
235
+
236
+ # @api private
237
+ sig { params(client: Anthropic::Client).returns(T.attached_class) }
238
+ def self.new(client:)
239
+ end
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
@@ -6,12 +6,19 @@ module Anthropic
6
6
  class Organization
7
7
  class Analytics
8
8
  class CostReport
9
- # Get cost in USD over time across a date range.
9
+ # [Legacy] Get cost in USD over time across a date range.
10
10
  #
11
- # Returns cost bucketed by minute, hour, or day, optionally broken down by
12
- # product, model, context window, inference region, speed, cost type, or token
13
- # type. Available to organizations on a Claude Enterprise plan. Requires an API
14
- # key with the `read:analytics` scope.
11
+ # Returns cost bucketed by minute, hour, or day, optionally broken down by one or
12
+ # more `group_by[]` dimensions, such as model or cost type. Available to
13
+ # organizations on a Claude Enterprise plan. Requires an API key with the
14
+ # `read:analytics` scope.
15
+ #
16
+ # This endpoint is one of the legacy Claude Enterprise usage and cost reports. For
17
+ # new integrations, use
18
+ # [`GET /v1/organizations/analytics/cost`](/docs/en/api/beta/organization/analytics/cost/list)
19
+ # in the Usage and Cost Analytics API instead. To move an existing integration,
20
+ # see
21
+ # [Migrate from the Claude Enterprise usage and cost reports](/docs/en/manage-claude/usage-cost-analytics-api#migrate-from-enterprise-analytics-reports).
15
22
  sig do
16
23
  params(
17
24
  starting_at: Time,