anthropic 2.1.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 (172) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -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/resources/beta/messages.rb +78 -4
  56. data/lib/anthropic/resources/beta/organization/analytics/cost.rb +175 -0
  57. data/lib/anthropic/resources/beta/organization/analytics/cost_report.rb +13 -6
  58. data/lib/anthropic/resources/beta/organization/analytics/usage.rb +176 -0
  59. data/lib/anthropic/resources/beta/organization/analytics/usage_report.rb +9 -2
  60. data/lib/anthropic/resources/beta/organization/analytics/user_cost_report.rb +12 -5
  61. data/lib/anthropic/resources/beta/organization/analytics/user_usage_report.rb +15 -8
  62. data/lib/anthropic/resources/beta/organization/analytics.rb +8 -0
  63. data/lib/anthropic/resources/beta/organization/plugin_marketplaces.rb +6 -6
  64. data/lib/anthropic/resources/beta/organization/plugins.rb +12 -9
  65. data/lib/anthropic/version.rb +1 -1
  66. data/lib/anthropic.rb +36 -0
  67. data/rbi/anthropic/client.rbi +5 -0
  68. data/rbi/anthropic/helpers/bedrock/client.rbi +5 -0
  69. data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +5 -0
  70. data/rbi/anthropic/helpers/threads/beta_message_thread.rbi +100 -0
  71. data/rbi/anthropic/helpers/vertex/client.rbi +5 -0
  72. data/rbi/anthropic/internal/tracing.rbi +4 -0
  73. data/rbi/anthropic/models/anthropic_beta.rbi +10 -0
  74. data/rbi/anthropic/models/beta/beta_message_thread_param.rbi +80 -0
  75. data/rbi/anthropic/models/beta/beta_thread_continue_params.rbi +43 -0
  76. data/rbi/anthropic/models/beta/beta_thread_create_params.rbi +31 -0
  77. data/rbi/anthropic/models/beta/message_create_params.rbi +37 -0
  78. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +37 -0
  79. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_group.rbi +439 -0
  80. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_group_by.rbi +140 -0
  81. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_item.rbi +110 -0
  82. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_metrics.rbi +79 -0
  83. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_cost_order_by.rbi +50 -0
  84. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_group.rbi +399 -0
  85. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_group_by.rbi +130 -0
  86. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_item.rbi +110 -0
  87. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_metrics.rbi +120 -0
  88. data/rbi/anthropic/models/beta/organization/analytics/beta_analytics_usage_order_by.rbi +60 -0
  89. data/rbi/anthropic/models/beta/organization/analytics/cost_list_params.rbi +624 -0
  90. data/rbi/anthropic/models/beta/organization/analytics/usage_list_params.rbi +612 -0
  91. data/rbi/anthropic/models/beta/organization/beta_analytics_actor.rbi +134 -0
  92. data/rbi/anthropic/models/beta/organization/beta_analytics_actor_type.rbi +54 -0
  93. data/rbi/anthropic/models/beta/organization/beta_analytics_api_actor.rbi +40 -0
  94. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor.rbi +75 -0
  95. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_aws_provider.rbi +54 -0
  96. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_azure_provider.rbi +42 -0
  97. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_gcp_provider.rbi +42 -0
  98. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_oidc_provider.rbi +42 -0
  99. data/rbi/anthropic/models/beta/organization/beta_analytics_federated_actor_provider.rbi +107 -0
  100. data/rbi/anthropic/models/beta/organization/beta_analytics_grouped_cost_type.rbi +53 -0
  101. data/rbi/anthropic/models/beta/organization/beta_analytics_report_user_actor.rbi +94 -0
  102. data/rbi/anthropic/models/beta/organization/beta_analytics_service_account_actor.rbi +42 -0
  103. data/rbi/anthropic/models/beta/organization/beta_analytics_service_tier.rbi +63 -0
  104. data/rbi/anthropic/models/beta/organization/beta_analytics_speed.rbi +40 -0
  105. data/rbi/anthropic/models/beta/organization/beta_analytics_time_bucket_width.rbi +48 -0
  106. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_inference_geo.rbi +43 -0
  107. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_product_filter.rbi +98 -0
  108. data/rbi/anthropic/models/beta/organization/beta_analytics_usage_cost_sort_order.rbi +43 -0
  109. data/rbi/anthropic/models/beta/organization/beta_organization_rate_limit.rbi +4 -2
  110. data/rbi/anthropic/models/beta/organization/beta_plugin.rbi +20 -8
  111. data/rbi/anthropic/models/beta/organization/beta_plugin_content_scan.rbi +15 -6
  112. data/rbi/anthropic/models/beta/organization/workspaces/beta_workspace_rate_limit.rbi +4 -2
  113. data/rbi/anthropic/models/organization/organization_rate_limit.rbi +4 -2
  114. data/rbi/anthropic/models/organization/workspaces/workspace_rate_limit.rbi +4 -2
  115. data/rbi/anthropic/resources/beta/messages.rbi +191 -0
  116. data/rbi/anthropic/resources/beta/organization/analytics/cost.rbi +245 -0
  117. data/rbi/anthropic/resources/beta/organization/analytics/cost_report.rbi +12 -5
  118. data/rbi/anthropic/resources/beta/organization/analytics/usage.rbi +240 -0
  119. data/rbi/anthropic/resources/beta/organization/analytics/usage_report.rbi +9 -2
  120. data/rbi/anthropic/resources/beta/organization/analytics/user_cost_report.rbi +12 -5
  121. data/rbi/anthropic/resources/beta/organization/analytics/user_usage_report.rbi +14 -7
  122. data/rbi/anthropic/resources/beta/organization/analytics.rbi +10 -0
  123. data/rbi/anthropic/resources/beta/organization/plugin_marketplaces.rbi +6 -6
  124. data/rbi/anthropic/resources/beta/organization/plugins.rbi +12 -9
  125. data/rbi/lib/anthropic/helpers/stainless_helper_header.rbi +2 -0
  126. data/sig/anthropic/client.rbs +2 -0
  127. data/sig/anthropic/helpers/bedrock/client.rbs +2 -0
  128. data/sig/anthropic/helpers/threads/beta_message_thread.rbs +40 -0
  129. data/sig/anthropic/helpers/tools/runner.rbs +40 -0
  130. data/sig/anthropic/helpers/vertex/client.rbs +2 -0
  131. data/sig/anthropic/internal/tracing.rbs +2 -0
  132. data/sig/anthropic/models/anthropic_beta.rbs +4 -0
  133. data/sig/anthropic/models/beta/beta_message_thread_param.rbs +40 -0
  134. data/sig/anthropic/models/beta/beta_thread_continue_params.rbs +20 -0
  135. data/sig/anthropic/models/beta/beta_thread_create_params.rbs +17 -0
  136. data/sig/anthropic/models/beta/message_create_params.rbs +5 -0
  137. data/sig/anthropic/models/beta/messages/batch_create_params.rbs +5 -0
  138. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_group.rbs +126 -0
  139. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_group_by.rbs +60 -0
  140. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_item.rbs +41 -0
  141. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_metrics.rbs +41 -0
  142. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_cost_order_by.rbs +21 -0
  143. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_group.rbs +116 -0
  144. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_group_by.rbs +56 -0
  145. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_item.rbs +41 -0
  146. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_metrics.rbs +56 -0
  147. data/sig/anthropic/models/beta/organization/analytics/beta_analytics_usage_order_by.rbs +28 -0
  148. data/sig/anthropic/models/beta/organization/analytics/cost_list_params.rbs +188 -0
  149. data/sig/anthropic/models/beta/organization/analytics/usage_list_params.rbs +188 -0
  150. data/sig/anthropic/models/beta/organization/beta_analytics_actor.rbs +67 -0
  151. data/sig/anthropic/models/beta/organization/beta_analytics_actor_type.rbs +21 -0
  152. data/sig/anthropic/models/beta/organization/beta_analytics_api_actor.rbs +19 -0
  153. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor.rbs +34 -0
  154. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_aws_provider.rbs +30 -0
  155. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_azure_provider.rbs +20 -0
  156. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_gcp_provider.rbs +20 -0
  157. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_oidc_provider.rbs +20 -0
  158. data/sig/anthropic/models/beta/organization/beta_analytics_federated_actor_provider.rbs +60 -0
  159. data/sig/anthropic/models/beta/organization/beta_analytics_grouped_cost_type.rbs +21 -0
  160. data/sig/anthropic/models/beta/organization/beta_analytics_report_user_actor.rbs +44 -0
  161. data/sig/anthropic/models/beta/organization/beta_analytics_service_account_actor.rbs +26 -0
  162. data/sig/anthropic/models/beta/organization/beta_analytics_service_tier.rbs +28 -0
  163. data/sig/anthropic/models/beta/organization/beta_analytics_speed.rbs +18 -0
  164. data/sig/anthropic/models/beta/organization/beta_analytics_time_bucket_width.rbs +19 -0
  165. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_inference_geo.rbs +18 -0
  166. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_product_filter.rbs +40 -0
  167. data/sig/anthropic/models/beta/organization/beta_analytics_usage_cost_sort_order.rbs +18 -0
  168. data/sig/anthropic/resources/beta/messages.rbs +33 -0
  169. data/sig/anthropic/resources/beta/organization/analytics/cost.rbs +46 -0
  170. data/sig/anthropic/resources/beta/organization/analytics/usage.rbs +46 -0
  171. data/sig/anthropic/resources/beta/organization/analytics.rbs +4 -0
  172. metadata +111 -2
@@ -0,0 +1,240 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Resources
5
+ class Beta
6
+ class Organization
7
+ class Analytics
8
+ class Usage
9
+ # Get token usage 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 usage in the range,
13
+ # ranked by the `order_by` metric or ordered by time bucket; every combination is
14
+ # returned across pages. With no `group_by[]` and no `time_bucket_width`, a single
15
+ # row aggregates the whole range. Includes all usage, whether or not it is
16
+ # attributable to a seat user. Requires an API key with the `read:analytics`
17
+ # scope, or an Admin API key.
18
+ sig do
19
+ params(
20
+ starting_at: Time,
21
+ actor_ids: T.nilable(T::Array[String]),
22
+ actor_types:
23
+ T.nilable(
24
+ T::Array[
25
+ Anthropic::Beta::Organization::BetaAnalyticsActorType::OrSymbol
26
+ ]
27
+ ),
28
+ agent_ids: T.nilable(T::Array[String]),
29
+ api_key_ids: T.nilable(T::Array[String]),
30
+ claude_tag_categories:
31
+ T.nilable(
32
+ T::Array[
33
+ Anthropic::Beta::Organization::BetaAnalyticsClaudeTagCategory::OrSymbol
34
+ ]
35
+ ),
36
+ claude_tag_user_ids: T.nilable(T::Array[String]),
37
+ context_windows:
38
+ T.nilable(
39
+ T::Array[
40
+ Anthropic::Beta::Organization::BetaAnalyticsContextWindow::OrSymbol
41
+ ]
42
+ ),
43
+ deployment_ids: T.nilable(T::Array[String]),
44
+ ending_at: T.nilable(Time),
45
+ environment_ids: T.nilable(T::Array[String]),
46
+ exclude_deleted_users: T::Boolean,
47
+ group_by:
48
+ T.nilable(
49
+ T::Array[
50
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsUsageGroupBy::OrSymbol
51
+ ]
52
+ ),
53
+ inference_geos:
54
+ T.nilable(
55
+ T::Array[
56
+ Anthropic::Beta::Organization::BetaAnalyticsInferenceGeoFilter::OrSymbol
57
+ ]
58
+ ),
59
+ limit: Integer,
60
+ models: T.nilable(T::Array[String]),
61
+ order:
62
+ Anthropic::Beta::Organization::BetaAnalyticsUsageCostSortOrder::OrSymbol,
63
+ order_by:
64
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsUsageOrderBy::OrSymbol,
65
+ page: T.nilable(String),
66
+ products:
67
+ T.nilable(
68
+ T::Array[
69
+ Anthropic::Beta::Organization::BetaAnalyticsUsageCostProductFilter::OrSymbol
70
+ ]
71
+ ),
72
+ rbac_group_ids: T.nilable(T::Array[String]),
73
+ service_tiers:
74
+ T.nilable(
75
+ T::Array[
76
+ Anthropic::Beta::Organization::BetaAnalyticsServiceTier::OrSymbol
77
+ ]
78
+ ),
79
+ session_ids: T.nilable(T::Array[String]),
80
+ slack_channel_ids: T.nilable(T::Array[String]),
81
+ speeds:
82
+ T.nilable(
83
+ T::Array[
84
+ Anthropic::Beta::Organization::BetaAnalyticsSpeed::OrSymbol
85
+ ]
86
+ ),
87
+ time_bucket_width:
88
+ T.nilable(
89
+ Anthropic::Beta::Organization::BetaAnalyticsTimeBucketWidth::OrSymbol
90
+ ),
91
+ user_profile_ids: T.nilable(T::Array[String]),
92
+ workspace_ids: T.nilable(T::Array[String]),
93
+ betas:
94
+ T::Array[T.any(Anthropic::AnthropicBeta::OrSymbol, String)],
95
+ request_options: Anthropic::RequestOptions::OrHash
96
+ ).returns(
97
+ Anthropic::Internal::ReportPageCursor[
98
+ Anthropic::Beta::Organization::Analytics::BetaAnalyticsUsageItem
99
+ ]
100
+ )
101
+ end
102
+ def list(
103
+ # Query param: Start of range, inclusive. RFC 3339 tz-aware. Must be within the
104
+ # last 365 days and no earlier than 2026-01-01T00:00:00Z.
105
+ starting_at:,
106
+ # Query param: Filter to usage attributed to specific identities, by tagged ID: a
107
+ # `user_...`, `svac_...` (service account), or `apikey_...` ID. An `apikey_` entry
108
+ # matches only usage attributed to the key itself, not usage on that key
109
+ # attributed to a user or service account (use `api_key_ids[]` for every request a
110
+ # key authenticated). Federated identities have no tagged ID; select them with
111
+ # `actor_types[]`. Use `group_by[]=actor` to break out per-identity values.
112
+ actor_ids: nil,
113
+ # Query param: Filter to usage attributed to specific kinds of identity. Use
114
+ # `group_by[]=actor_type` to break out per-kind values.
115
+ actor_types: nil,
116
+ # Query param: Filter to usage incurred by sessions of specific Claude Managed
117
+ # Agents agents. Use `group_by[]=agent_id` to break out per-agent values. Claude
118
+ # Developer Platform organizations only.
119
+ agent_ids: nil,
120
+ # Query param: Filter to usage authenticated by specific API keys, by tagged API
121
+ # key ID (`apikey_...`), whichever identity the usage is attributed to. Include an
122
+ # empty entry (`api_key_ids[]=`) to also match usage that no API key
123
+ # authenticated. Use `group_by[]=api_key_id` to break out per-key values; usage
124
+ # without a key has a null `api_key_id`. Claude Developer Platform organizations
125
+ # only.
126
+ api_key_ids: nil,
127
+ # Query param: Filter to Claude Tag (Claude in Slack) usage in specific spend
128
+ # categories. Usage with no category never matches. `dm` usage is reported under
129
+ # the user's product rather than `claude_tag`, so combining this filter with
130
+ # `products[]=claude_tag` excludes it. Use `group_by[]=claude_tag_category` to
131
+ # break out per-category values.
132
+ claude_tag_categories: nil,
133
+ # Query param: Filter to Claude Tag (Claude in Slack) usage attributed to specific
134
+ # Slack users, by Slack user ID (for example `U0123ABCDEF`), not claude.ai user
135
+ # ID. Usage that is not Claude Tag, and Claude Tag usage not attributed to a
136
+ # single user, never matches. Use `group_by[]=claude_tag_user_id` to break out
137
+ # per-user values.
138
+ claude_tag_user_ids: nil,
139
+ # Query param: Filter to specific context-window pricing tiers. Use
140
+ # `group_by[]=context_window` to break out per-tier values.
141
+ context_windows: nil,
142
+ # Query param: Filter to usage incurred by Claude Managed Agents sessions that
143
+ # specific deployments started. Use `group_by[]=deployment_id` to break out
144
+ # per-deployment values. Claude Developer Platform organizations only.
145
+ deployment_ids: nil,
146
+ # Query param: End of range, exclusive. Required when `time_bucket_width` is set.
147
+ # Without `time_bucket_width`, defaults to the earlier of now and `starting_at` +
148
+ # 31 days. The range may span at most 31 days.
149
+ ending_at: nil,
150
+ # Query param: Filter to usage incurred by Claude Managed Agents sessions that ran
151
+ # in specific environments. Use `group_by[]=environment_id` to break out
152
+ # per-environment values. Claude Developer Platform organizations only.
153
+ environment_ids: nil,
154
+ # Query param: If true, omit rows whose `actor` is a `user_actor` with
155
+ # `deleted: true`. Requires `group_by[]=actor`. Rows for other actor types, and
156
+ # rows whose `actor` is null, are always kept. A page may contain fewer than
157
+ # `limit` rows; use `has_more` and `next_page` to paginate as usual.
158
+ exclude_deleted_users: nil,
159
+ # Query param: Dimensions to break usage out by (at most 5): one row per
160
+ # combination of their values with usage in the range (and per time bucket, when
161
+ # `time_bucket_width` is set), every combination returned across pages rather than
162
+ # a capped top set. When omitted, a single row aggregates the whole range.
163
+ group_by: nil,
164
+ # Query param: Filter to specific inference regions. `not_available` matches rows
165
+ # where the region is unset. Use `group_by[]=inference_geo` to break out
166
+ # per-region values.
167
+ inference_geos: nil,
168
+ # Query param: Number of rows per page (1-1000, default 20).
169
+ # `cost_type`/`token_type` fan-out rows (cost endpoint only) do not count toward
170
+ # this limit, so `data` can exceed it.
171
+ limit: nil,
172
+ # Query param: Models to include. Defaults to all models. Use `group_by[]=model`
173
+ # to break out per-model values.
174
+ models: nil,
175
+ # Query param: Sort direction of the `order_by` metric, or of the time buckets
176
+ # when `order_by` is `time` and `time_bucket_width` is set. Defaults to `desc`.
177
+ order: nil,
178
+ # Query param: Row order. A metric ranks rows by that metric in the `order`
179
+ # direction. `time` orders rows by time bucket in the `order` direction (newest
180
+ # first by default) and, within a bucket, by `total_tokens`, highest first. `time`
181
+ # takes effect only with `time_bucket_width`; without it, `time` is the same as
182
+ # `total_tokens`. Defaults to `total_tokens`.
183
+ order_by: nil,
184
+ # Query param: Opaque cursor from a previous response's `next_page` field.
185
+ page: nil,
186
+ # Query param: Product surfaces to include. Defaults to all products.
187
+ products: nil,
188
+ # Query param: Filter to usage attributed to specific RBAC groups. Accepts tagged
189
+ # RBAC group IDs (`rbac_group_...`) or bare group UUIDs. A row matches when the
190
+ # user belonged to any of the listed groups on the (UTC) day the usage occurred;
191
+ # usage with no group attribution never matches.
192
+ rbac_group_ids: nil,
193
+ # Query param: Filter to specific service tiers. Use `group_by[]=service_tier` to
194
+ # break out per-tier values. Claude Developer Platform organizations only; matches
195
+ # nothing for a Claude Enterprise organization.
196
+ service_tiers: nil,
197
+ # Query param: Filter to usage incurred by specific Claude Managed Agents
198
+ # sessions, by tagged session ID (`sesn_...`). Use `group_by[]=session_id` to
199
+ # break out per-session values. Claude Developer Platform organizations only.
200
+ session_ids: nil,
201
+ # Query param: Filter to usage originating from specific Slack channels. Use
202
+ # `group_by[]=slack_channel_id` to break out per-channel values.
203
+ slack_channel_ids: nil,
204
+ # Query param: Filter to fast or standard inference mode. Use `group_by[]=speed`
205
+ # to break out per-mode values.
206
+ speeds: nil,
207
+ # Query param: Time-bucket granularity. When set, rows are returned per time
208
+ # bucket (one per bucket and dimension combination with usage) and each row's
209
+ # `starting_at` and `ending_at` are that bucket's bounds; the time bucket counts
210
+ # toward `limit`. `ending_at` is required when `time_bucket_width` is set, and
211
+ # with `time_bucket_width="1m"` the range may span at most 24 hours. When omitted,
212
+ # each row aggregates the requested range with `starting_at` and `ending_at` each
213
+ # rounded down to the hour.
214
+ time_bucket_width: nil,
215
+ # Query param: Filter to usage attributed to specific user profiles, by tagged
216
+ # user profile ID (`uprof_...`). Use `group_by[]=user_profile_id` to break out
217
+ # per-profile values. Claude Developer Platform organizations only.
218
+ user_profile_ids: nil,
219
+ # Query param: Filter to usage in specific workspaces, by tagged workspace ID
220
+ # (`wrkspc_...`). Use `group_by[]=workspace_id` to break out per-workspace values.
221
+ # Claude Developer Platform organizations only; matches nothing for a Claude
222
+ # Enterprise organization.
223
+ workspace_ids: nil,
224
+ # Header param: This endpoint is in beta: requests must send
225
+ # `analytics-usage-cost-2026-08-24` in this header.
226
+ betas: nil,
227
+ request_options: {}
228
+ )
229
+ end
230
+
231
+ # @api private
232
+ sig { params(client: Anthropic::Client).returns(T.attached_class) }
233
+ def self.new(client:)
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -6,12 +6,19 @@ module Anthropic
6
6
  class Organization
7
7
  class Analytics
8
8
  class UsageReport
9
- # Get token usage over time across a date range.
9
+ # [Legacy] Get token usage over time across a date range.
10
10
  #
11
11
  # Returns token usage bucketed by minute, hour, or day, optionally broken down by
12
- # product, model, context window, inference region, or speed. Available to
12
+ # one or more `group_by[]` dimensions, such as product or model. Available to
13
13
  # organizations on a Claude Enterprise plan. Requires an API key with the
14
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/usage`](/docs/en/api/beta/organization/analytics/usage/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,
@@ -6,14 +6,21 @@ module Anthropic
6
6
  class Organization
7
7
  class Analytics
8
8
  class UserCostReport
9
- # Get per-user cost in USD across a date range.
9
+ # [Legacy] Get per-user cost in USD across a date range.
10
10
  #
11
- # Returns one row per user, ranked by spend. Use this to see which users account
12
- # for the most cost. Only cost attributable to a seat user is included; for
13
- # organization-wide totals including direct API-key and automation traffic, use
14
- # the bucketed `/v1/organizations/analytics/cost_report` endpoint. Available to
11
+ # Returns cost per user, ranked by spend; `group_by[]` or `bucket_width` splits a
12
+ # user across several rows. Use this to see which users account for the most cost.
13
+ # Only cost attributed to a user account is included; cost with no user attributed
14
+ # to it, such as requests attributed only to an API key, is left out. Available to
15
15
  # organizations on a Claude Enterprise plan. Requires an API key with the
16
16
  # `read:analytics` scope.
17
+ #
18
+ # This endpoint is one of the legacy Claude Enterprise usage and cost reports. For
19
+ # new integrations, use
20
+ # [`GET /v1/organizations/analytics/cost`](/docs/en/api/beta/organization/analytics/cost/list)
21
+ # in the Usage and Cost Analytics API instead. To move an existing integration,
22
+ # see
23
+ # [Migrate from the Claude Enterprise usage and cost reports](/docs/en/manage-claude/usage-cost-analytics-api#migrate-from-enterprise-analytics-reports).
17
24
  sig do
18
25
  params(
19
26
  starting_at: Time,
@@ -6,14 +6,21 @@ module Anthropic
6
6
  class Organization
7
7
  class Analytics
8
8
  class UserUsageReport
9
- # Get per-user token usage across a date range.
9
+ # [Legacy] Get per-user token usage across a date range.
10
10
  #
11
- # Returns one row per user, ranked by the chosen token metric. Use this to see
12
- # which users consume the most tokens. Only usage attributable to a seat user is
13
- # included; for organization-wide totals including direct API-key and automation
14
- # traffic, use the bucketed `/v1/organizations/analytics/usage_report` endpoint.
15
- # Available to organizations on a Claude Enterprise plan. Requires an API key with
16
- # the `read:analytics` scope.
11
+ # Returns usage per user, ranked by the chosen token metric; `group_by[]` or
12
+ # `bucket_width` splits a user across several rows. Use this to see which users
13
+ # consume the most tokens. Only usage attributed to a user account is included;
14
+ # usage with no user attributed to it, such as requests attributed only to an API
15
+ # key, is left out. Available to organizations on a Claude Enterprise plan.
16
+ # Requires an API key with the `read:analytics` scope.
17
+ #
18
+ # This endpoint is one of the legacy Claude Enterprise usage and cost reports. For
19
+ # new integrations, use
20
+ # [`GET /v1/organizations/analytics/usage`](/docs/en/api/beta/organization/analytics/usage/list)
21
+ # in the Usage and Cost Analytics API instead. To move an existing integration,
22
+ # see
23
+ # [Migrate from the Claude Enterprise usage and cost reports](/docs/en/manage-claude/usage-cost-analytics-api#migrate-from-enterprise-analytics-reports).
17
24
  sig do
18
25
  params(
19
26
  starting_at: Time,
@@ -48,6 +48,16 @@ module Anthropic
48
48
  end
49
49
  attr_reader :artifacts
50
50
 
51
+ sig do
52
+ returns(Anthropic::Resources::Beta::Organization::Analytics::Usage)
53
+ end
54
+ attr_reader :usage
55
+
56
+ sig do
57
+ returns(Anthropic::Resources::Beta::Organization::Analytics::Cost)
58
+ end
59
+ attr_reader :cost
60
+
51
61
  sig do
52
62
  returns(
53
63
  Anthropic::Resources::Beta::Organization::Analytics::UsageReport
@@ -165,9 +165,9 @@ module Anthropic
165
165
  # part, with some files left out. An archive that cannot be read as a marketplace
166
166
  # is reported, not refused: the response is a report with `valid: false`. Plugin
167
167
  # sources outside the marketplace are fetched anonymously from GitHub, so a
168
- # private one is reported as not found; a source on any other host is not fetched
169
- # here, and the report notes that it will be checked when the marketplace actually
170
- # synchronizes.
168
+ # private one is reported as not found or as needing a GitHub sign-in; a source on
169
+ # any other host is not fetched here, and the report notes that it will be checked
170
+ # when the marketplace actually synchronizes.
171
171
  #
172
172
  # Nothing is recorded on the Compliance API activity feed.
173
173
  #
@@ -220,9 +220,9 @@ module Anthropic
220
220
  # part, with some files left out. A repository that is missing, private, or has no
221
221
  # such branch or commit is reported, not refused: the response is a report with
222
222
  # `valid: false`. Plugin sources outside the marketplace are fetched anonymously
223
- # from GitHub, so a private one is reported as not found; a source on any other
224
- # host is not fetched here, and the report notes that it will be checked when the
225
- # marketplace actually synchronizes.
223
+ # from GitHub, so a private one is reported as not found or as needing a GitHub
224
+ # sign-in; a source on any other host is not fetched here, and the report notes
225
+ # that it will be checked when the marketplace actually synchronizes.
226
226
  #
227
227
  # Nothing is recorded on the Compliance API activity feed.
228
228
  #
@@ -141,15 +141,18 @@ module Anthropic
141
141
  # already served to pin it without changing what is served. No new version is
142
142
  # created.
143
143
  #
144
- # When the organization has content scanning enabled, a version whose scan is
145
- # still running is refused with a 409 (`error_code` `scan_pending`; retry once the
146
- # scan finishes) and one whose scan failed, errored or reached no verdict with a
147
- # 400 (`scan_failed`; a `warn` is accepted). When the Plugin is in the
148
- # organization's library marketplace, a version other than the one served is also
149
- # refused with a 409 when one of its skills has a name that an organization skill
150
- # (one an administrator uploaded for the whole organization in claude.ai) has
151
- # since taken: `error_code` `skill_name_taken`, with that name in
152
- # `details.skill_name`. A member-owned Plugin cannot be updated here (403).
144
+ # When the organization has content scanning enabled, a version whose
145
+ # `content_scan.status` is `processing` is refused with a 409 (`error_code`
146
+ # `scan_pending`; retry once the scan finishes). A version whose
147
+ # `content_scan.status` is `errored`, or whose `content_scan.assessment` is `fail`
148
+ # or `unknown`, is refused with a 400 (`error_code` `scan_failed`); a `warn` is
149
+ # accepted. If the scan outcome cannot be read at that moment, the request fails
150
+ # with a retryable 503 instead. When the Plugin is in the organization's library
151
+ # marketplace, a version other than the one served is also refused with a 409 when
152
+ # one of its skills has a name that an organization skill (one an administrator
153
+ # uploaded for the whole organization in claude.ai) has since taken: `error_code`
154
+ # `skill_name_taken`, with that name in `details.skill_name`. A member-owned
155
+ # Plugin cannot be updated here (403).
153
156
  #
154
157
  # This endpoint does not write installation settings; they are written at
155
158
  # `/v1/organizations/plugins/{plugin_id}/installation_settings/{target}`.
@@ -9,6 +9,8 @@ module Anthropic
9
9
 
10
10
  FALLBACK_REFUSAL_MIDDLEWARE = T.let("fallback-refusal-middleware", String)
11
11
 
12
+ MESSAGE_THREAD = T.let("message-thread", String)
13
+
12
14
  class << self
13
15
  sig { params(headers: T::Hash[T.any(String, Symbol), T.untyped], value: String).returns(String) }
14
16
  def merged_value(headers, value)
@@ -33,6 +33,8 @@ module Anthropic
33
33
  private def api_key_auth: -> ::Hash[String, String]
34
34
 
35
35
  private def bearer_auth: -> ::Hash[String, String]
36
+ def message_threads?: -> bool
37
+
36
38
  private def resolve_default_credentials?: -> bool
37
39
 
38
40
  def timeout_overridden?: -> bool
@@ -10,6 +10,8 @@ module Anthropic
10
10
 
11
11
  def models: -> bot
12
12
 
13
+ def message_threads?: -> bool
14
+
13
15
  def files: -> bot
14
16
 
15
17
  def skills: -> bot
@@ -0,0 +1,40 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Threads
4
+ class BetaMessageThread
5
+ type unsupported_request_behavior = :error | :continue_unthreaded
6
+
7
+ type message =
8
+ Anthropic::Models::Beta::beta_message_param
9
+ | Anthropic::Beta::BetaMessage
10
+ | ::Hash[Symbol, top]
11
+
12
+ def messages: -> ::Array[::Hash[Symbol, top]]
13
+
14
+ def previous_message_id: -> String?
15
+
16
+ def params: -> ::Hash[Symbol, top]
17
+
18
+ def append: (*message messages) -> void
19
+
20
+ def update: (**top params) -> void
21
+
22
+ def fork: -> Anthropic::Helpers::Threads::BetaMessageThread
23
+
24
+ def tool_runner: (
25
+ ?max_iterations: Integer?
26
+ ) -> Anthropic::Helpers::Tools::Runner
27
+
28
+ def send_message: (
29
+ *message messages,
30
+ **top params
31
+ ) -> Anthropic::Beta::BetaMessage
32
+
33
+ def stream: (
34
+ *message messages,
35
+ **top params
36
+ ) -> Anthropic::Helpers::Streaming::MessageStream
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Tools
4
+ class Runner
5
+ type message =
6
+ Anthropic::Models::Beta::beta_message_param | ::Hash[Symbol, top]
7
+
8
+ type params =
9
+ Anthropic::Models::Beta::MessageCreateParams | ::Hash[Symbol, top]
10
+
11
+ def params: -> params
12
+
13
+ def params=: (params params) -> void
14
+
15
+ def finished?: -> bool
16
+
17
+ def feed_messages: (*message messages) -> void
18
+
19
+ def add_tools: (*top tools) -> void
20
+
21
+ def remove_tools: (*top tools) -> void
22
+
23
+ def compact_before_next_turn: (
24
+ ?(Anthropic::Beta::BetaCompactionConfig
25
+ | ::Hash[Symbol, top])? compaction
26
+ ) -> void
27
+
28
+ def next_message: -> Anthropic::Beta::BetaMessage?
29
+
30
+ def run_until_finished: -> ::Array[Anthropic::Beta::BetaMessage]
31
+
32
+ def each_message: { (Anthropic::Beta::BetaMessage) -> void } -> void
33
+
34
+ def each_streaming: {
35
+ (Anthropic::Helpers::Streaming::MessageStream) -> void
36
+ } -> void
37
+ end
38
+ end
39
+ end
40
+ end
@@ -12,6 +12,8 @@ module Anthropic
12
12
 
13
13
  private def resolve_default_credentials?: -> bool
14
14
 
15
+ def message_threads?: -> bool
16
+
15
17
  def files: -> bot
16
18
 
17
19
  def skills: -> bot
@@ -246,6 +246,8 @@ module Anthropic
246
246
  ORGANIZATION_ANALYTICS_PLUGINS_LIST: "anthropic.organization.analytics.plugins.list"
247
247
  ORGANIZATION_ANALYTICS_SKILLS_LIST: "anthropic.organization.analytics.skills.list"
248
248
  ORGANIZATION_ANALYTICS_ARTIFACTS_LIST: "anthropic.organization.analytics.artifacts.list"
249
+ ORGANIZATION_ANALYTICS_USAGE_LIST: "anthropic.organization.analytics.usage.list"
250
+ ORGANIZATION_ANALYTICS_COST_LIST: "anthropic.organization.analytics.cost.list"
249
251
  ORGANIZATION_ANALYTICS_USAGE_REPORT_LIST: "anthropic.organization.analytics.usage_report.list"
250
252
  ORGANIZATION_ANALYTICS_USER_USAGE_REPORT_LIST: "anthropic.organization.analytics.user_usage_report.list"
251
253
  ORGANIZATION_ANALYTICS_COST_REPORT_LIST: "anthropic.organization.analytics.cost_report.list"
@@ -53,6 +53,8 @@ module Anthropic
53
53
  | :"spend-limit-reads-2026-09-26"
54
54
  | :"telemetry-destinations-2026-08-11"
55
55
  | :"webhooks-2026-10-07"
56
+ | :"message-threads-2026-08-12"
57
+ | :"analytics-usage-cost-2026-08-24"
56
58
  | String
57
59
 
58
60
  module AnthropicBeta
@@ -112,6 +114,8 @@ module Anthropic
112
114
  SPEND_LIMIT_READS_2026_09_26: :"spend-limit-reads-2026-09-26"
113
115
  TELEMETRY_DESTINATIONS_2026_08_11: :"telemetry-destinations-2026-08-11"
114
116
  WEBHOOKS_2026_10_07: :"webhooks-2026-10-07"
117
+ MESSAGE_THREADS_2026_08_12: :"message-threads-2026-08-12"
118
+ ANALYTICS_USAGE_COST_2026_08_24: :"analytics-usage-cost-2026-08-24"
115
119
  end
116
120
  end
117
121
  end
@@ -0,0 +1,40 @@
1
+ module Anthropic
2
+ module Models
3
+ module BetaMessageThreadParam = Beta::BetaMessageThreadParam
4
+
5
+ module Beta
6
+ type beta_message_thread_param =
7
+ Anthropic::Beta::BetaThreadCreateParams
8
+ | Anthropic::Beta::BetaThreadContinueParams
9
+
10
+ module BetaMessageThreadParam
11
+ extend Anthropic::Internal::Type::Union
12
+
13
+ type type_ = :create | :continue
14
+
15
+ module Type
16
+ extend Anthropic::Internal::Type::Enum
17
+
18
+ CREATE: :create
19
+ CONTINUE: :continue
20
+
21
+ def self?.values: -> ::Array[Anthropic::Models::Beta::BetaMessageThreadParam::type_]
22
+ end
23
+
24
+ def self?.variants: -> ::Array[Anthropic::Models::Beta::beta_message_thread_param]
25
+
26
+ def self.new:
27
+ (type: :create | "create") -> Anthropic::Beta::BetaThreadCreateParams
28
+ | (
29
+ type: :continue | "continue",
30
+ previous_message_id: String
31
+ ) -> Anthropic::Beta::BetaThreadContinueParams
32
+ | (
33
+ type: Anthropic::Models::Beta::BetaMessageThreadParam::type_
34
+ | String,
35
+ ?previous_message_id: String
36
+ ) -> Anthropic::Models::Beta::beta_message_thread_param
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Anthropic
2
+ module Models
3
+ class BetaThreadContinueParams = Beta::BetaThreadContinueParams
4
+
5
+ module Beta
6
+ type beta_thread_continue_params =
7
+ { previous_message_id: String, type: :continue }
8
+
9
+ class BetaThreadContinueParams < Anthropic::Internal::Type::BaseModel
10
+ attr_accessor previous_message_id: String
11
+
12
+ attr_accessor type: :continue
13
+
14
+ def initialize: (previous_message_id: String, ?type: :continue) -> void
15
+
16
+ def to_hash: -> { previous_message_id: String, type: :continue }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Anthropic
2
+ module Models
3
+ class BetaThreadCreateParams = Beta::BetaThreadCreateParams
4
+
5
+ module Beta
6
+ type beta_thread_create_params = { type: :create }
7
+
8
+ class BetaThreadCreateParams < Anthropic::Internal::Type::BaseModel
9
+ attr_accessor type: :create
10
+
11
+ def initialize: (?type: :create) -> void
12
+
13
+ def to_hash: -> { type: :create }
14
+ end
15
+ end
16
+ end
17
+ end