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,175 @@
1
+ # frozen_string_literal: true
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
+ #
18
+ # Some parameter documentations has been truncated, see
19
+ # {Anthropic::Models::Beta::Organization::Analytics::CostListParams} for more
20
+ # details.
21
+ #
22
+ # @overload list(starting_at:, actor_ids: nil, actor_types: nil, agent_ids: nil, api_key_ids: nil, claude_tag_categories: nil, claude_tag_user_ids: nil, context_windows: nil, deployment_ids: nil, ending_at: nil, environment_ids: nil, exclude_deleted_users: nil, group_by: nil, inference_geos: nil, limit: nil, models: nil, order: nil, order_by: nil, page: nil, products: nil, rbac_group_ids: nil, service_tiers: nil, session_ids: nil, slack_channel_ids: nil, speeds: nil, time_bucket_width: nil, user_profile_ids: nil, workspace_ids: nil, betas: nil, request_options: {})
23
+ #
24
+ # @param starting_at [Time] Query param: Start of range, inclusive. RFC 3339 tz-aware. Must be within the la
25
+ #
26
+ # @param actor_ids [Array<String>, nil] Query param: Filter to usage attributed to specific identities, by tagged ID: a
27
+ #
28
+ # @param actor_types [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsActorType>, nil] Query param: Filter to usage attributed to specific kinds of identity. Use `grou
29
+ #
30
+ # @param agent_ids [Array<String>, nil] Query param: Filter to usage incurred by sessions of specific Claude Managed Age
31
+ #
32
+ # @param api_key_ids [Array<String>, nil] Query param: Filter to usage authenticated by specific API keys, by tagged API k
33
+ #
34
+ # @param claude_tag_categories [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsClaudeTagCategory>, nil] Query param: Filter to Claude Tag (Claude in Slack) usage in specific spend cate
35
+ #
36
+ # @param claude_tag_user_ids [Array<String>, nil] Query param: Filter to Claude Tag (Claude in Slack) usage attributed to specific
37
+ #
38
+ # @param context_windows [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsContextWindow>, nil] Query param: Filter to specific context-window pricing tiers. Use `group_by[]=co
39
+ #
40
+ # @param deployment_ids [Array<String>, nil] Query param: Filter to usage incurred by Claude Managed Agents sessions that spe
41
+ #
42
+ # @param ending_at [Time, nil] Query param: End of range, exclusive. Required when `time_bucket_width` is set.
43
+ #
44
+ # @param environment_ids [Array<String>, nil] Query param: Filter to usage incurred by Claude Managed Agents sessions that ran
45
+ #
46
+ # @param exclude_deleted_users [Boolean] Query param: If true, omit rows whose `actor` is a `user_actor` with `deleted: t
47
+ #
48
+ # @param group_by [Array<Symbol, Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsCostGroupBy>, nil] Query param: Dimensions to break cost out by (at most 5, not counting `cost_type
49
+ #
50
+ # @param inference_geos [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsInferenceGeoFilter>, nil] Query param: Filter to specific inference regions. `not_available` matches rows
51
+ #
52
+ # @param limit [Integer] Query param: Number of rows per page (1-1000, default 20). `cost_type`/`token_ty
53
+ #
54
+ # @param models [Array<String>, nil] Query param: Models to include. Defaults to all models. Use `group_by[]=model` t
55
+ #
56
+ # @param order [Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsUsageCostSortOrder] Query param: Sort direction of the `order_by` metric, or of the time buckets whe
57
+ #
58
+ # @param order_by [Symbol, Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsCostOrderBy] Query param: Row order. A metric ranks rows by that metric in the `order` direct
59
+ #
60
+ # @param page [String, nil] Query param: Opaque cursor from a previous response's `next_page` field.
61
+ #
62
+ # @param products [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsUsageCostProductFilter>, nil] Query param: Product surfaces to include. Defaults to all products.
63
+ #
64
+ # @param rbac_group_ids [Array<String>, nil] Query param: Filter to usage attributed to specific RBAC groups. Accepts tagged
65
+ #
66
+ # @param service_tiers [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsServiceTier>, nil] Query param: Filter to specific service tiers. Use `group_by[]=service_tier` to
67
+ #
68
+ # @param session_ids [Array<String>, nil] Query param: Filter to usage incurred by specific Claude Managed Agents sessions
69
+ #
70
+ # @param slack_channel_ids [Array<String>, nil] Query param: Filter to usage originating from specific Slack channels. Use `grou
71
+ #
72
+ # @param speeds [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsSpeed>, nil] Query param: Filter to fast or standard inference mode. Use `group_by[]=speed` t
73
+ #
74
+ # @param time_bucket_width [Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsTimeBucketWidth, nil] Query param: Time-bucket granularity. When set, rows are returned per time bucke
75
+ #
76
+ # @param user_profile_ids [Array<String>, nil] Query param: Filter to usage attributed to specific user profiles, by tagged use
77
+ #
78
+ # @param workspace_ids [Array<String>, nil] Query param: Filter to usage in specific workspaces, by tagged workspace ID (`wr
79
+ #
80
+ # @param betas [Array<Symbol, String, Anthropic::Models::AnthropicBeta>] Header param: This endpoint is in beta: requests must send `analytics-usage-cost
81
+ #
82
+ # @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
83
+ #
84
+ # @return [Anthropic::Internal::ReportPageCursor<Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsCostItem>]
85
+ #
86
+ # @see Anthropic::Models::Beta::Organization::Analytics::CostListParams
87
+ def list(params)
88
+ query_params =
89
+ [
90
+ :starting_at,
91
+ :actor_ids,
92
+ :actor_types,
93
+ :agent_ids,
94
+ :api_key_ids,
95
+ :claude_tag_categories,
96
+ :claude_tag_user_ids,
97
+ :context_windows,
98
+ :deployment_ids,
99
+ :ending_at,
100
+ :environment_ids,
101
+ :exclude_deleted_users,
102
+ :group_by,
103
+ :inference_geos,
104
+ :limit,
105
+ :models,
106
+ :order,
107
+ :order_by,
108
+ :page,
109
+ :products,
110
+ :rbac_group_ids,
111
+ :service_tiers,
112
+ :session_ids,
113
+ :slack_channel_ids,
114
+ :speeds,
115
+ :time_bucket_width,
116
+ :user_profile_ids,
117
+ :workspace_ids
118
+ ]
119
+ parsed, options = Anthropic::Beta::Organization::Analytics::CostListParams.dump_request(params)
120
+ query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
121
+ @client.request(
122
+ span_name: Anthropic::Internal::Tracing::SpanName::ORGANIZATION_ANALYTICS_COST_LIST,
123
+ span_route: "/v1/organizations/analytics/cost",
124
+ span_query: %w[
125
+ actor_ids
126
+ actor_types
127
+ agent_ids
128
+ api_key_ids
129
+ claude_tag_categories
130
+ claude_tag_user_ids
131
+ context_windows
132
+ deployment_ids
133
+ ending_at
134
+ environment_ids
135
+ exclude_deleted_users
136
+ group_by
137
+ inference_geos
138
+ limit
139
+ models
140
+ order
141
+ order_by
142
+ page
143
+ products
144
+ rbac_group_ids
145
+ service_tiers
146
+ session_ids
147
+ slack_channel_ids
148
+ speeds
149
+ starting_at
150
+ time_bucket_width
151
+ user_profile_ids
152
+ workspace_ids
153
+ ],
154
+ method: :get,
155
+ path: "v1/organizations/analytics/cost?beta=true",
156
+ query: query,
157
+ headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
158
+ page: Anthropic::Internal::ReportPageCursor,
159
+ model: Anthropic::Beta::Organization::Analytics::BetaAnalyticsCostItem,
160
+ options: {extra_headers: {"anthropic-beta" => "analytics-usage-cost-2026-08-24"}, **options}
161
+ )
162
+ end
163
+
164
+ # @api private
165
+ #
166
+ # @param client [Anthropic::Client]
167
+ def initialize(client:)
168
+ @client = client
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ 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.
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.
9
+ # [Legacy] Get cost in USD over time across a date range.
10
+ #
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
  #
16
23
  # Some parameter documentations has been truncated, see
17
24
  # {Anthropic::Models::Beta::Organization::Analytics::CostReportListParams} for
@@ -0,0 +1,176 @@
1
+ # frozen_string_literal: true
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
+ #
19
+ # Some parameter documentations has been truncated, see
20
+ # {Anthropic::Models::Beta::Organization::Analytics::UsageListParams} for more
21
+ # details.
22
+ #
23
+ # @overload list(starting_at:, actor_ids: nil, actor_types: nil, agent_ids: nil, api_key_ids: nil, claude_tag_categories: nil, claude_tag_user_ids: nil, context_windows: nil, deployment_ids: nil, ending_at: nil, environment_ids: nil, exclude_deleted_users: nil, group_by: nil, inference_geos: nil, limit: nil, models: nil, order: nil, order_by: nil, page: nil, products: nil, rbac_group_ids: nil, service_tiers: nil, session_ids: nil, slack_channel_ids: nil, speeds: nil, time_bucket_width: nil, user_profile_ids: nil, workspace_ids: nil, betas: nil, request_options: {})
24
+ #
25
+ # @param starting_at [Time] Query param: Start of range, inclusive. RFC 3339 tz-aware. Must be within the la
26
+ #
27
+ # @param actor_ids [Array<String>, nil] Query param: Filter to usage attributed to specific identities, by tagged ID: a
28
+ #
29
+ # @param actor_types [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsActorType>, nil] Query param: Filter to usage attributed to specific kinds of identity. Use `grou
30
+ #
31
+ # @param agent_ids [Array<String>, nil] Query param: Filter to usage incurred by sessions of specific Claude Managed Age
32
+ #
33
+ # @param api_key_ids [Array<String>, nil] Query param: Filter to usage authenticated by specific API keys, by tagged API k
34
+ #
35
+ # @param claude_tag_categories [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsClaudeTagCategory>, nil] Query param: Filter to Claude Tag (Claude in Slack) usage in specific spend cate
36
+ #
37
+ # @param claude_tag_user_ids [Array<String>, nil] Query param: Filter to Claude Tag (Claude in Slack) usage attributed to specific
38
+ #
39
+ # @param context_windows [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsContextWindow>, nil] Query param: Filter to specific context-window pricing tiers. Use `group_by[]=co
40
+ #
41
+ # @param deployment_ids [Array<String>, nil] Query param: Filter to usage incurred by Claude Managed Agents sessions that spe
42
+ #
43
+ # @param ending_at [Time, nil] Query param: End of range, exclusive. Required when `time_bucket_width` is set.
44
+ #
45
+ # @param environment_ids [Array<String>, nil] Query param: Filter to usage incurred by Claude Managed Agents sessions that ran
46
+ #
47
+ # @param exclude_deleted_users [Boolean] Query param: If true, omit rows whose `actor` is a `user_actor` with `deleted: t
48
+ #
49
+ # @param group_by [Array<Symbol, Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsUsageGroupBy>, nil] Query param: Dimensions to break usage out by (at most 5): one row per combinati
50
+ #
51
+ # @param inference_geos [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsInferenceGeoFilter>, nil] Query param: Filter to specific inference regions. `not_available` matches rows
52
+ #
53
+ # @param limit [Integer] Query param: Number of rows per page (1-1000, default 20). `cost_type`/`token_ty
54
+ #
55
+ # @param models [Array<String>, nil] Query param: Models to include. Defaults to all models. Use `group_by[]=model` t
56
+ #
57
+ # @param order [Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsUsageCostSortOrder] Query param: Sort direction of the `order_by` metric, or of the time buckets whe
58
+ #
59
+ # @param order_by [Symbol, Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsUsageOrderBy] Query param: Row order. A metric ranks rows by that metric in the `order` direct
60
+ #
61
+ # @param page [String, nil] Query param: Opaque cursor from a previous response's `next_page` field.
62
+ #
63
+ # @param products [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsUsageCostProductFilter>, nil] Query param: Product surfaces to include. Defaults to all products.
64
+ #
65
+ # @param rbac_group_ids [Array<String>, nil] Query param: Filter to usage attributed to specific RBAC groups. Accepts tagged
66
+ #
67
+ # @param service_tiers [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsServiceTier>, nil] Query param: Filter to specific service tiers. Use `group_by[]=service_tier` to
68
+ #
69
+ # @param session_ids [Array<String>, nil] Query param: Filter to usage incurred by specific Claude Managed Agents sessions
70
+ #
71
+ # @param slack_channel_ids [Array<String>, nil] Query param: Filter to usage originating from specific Slack channels. Use `grou
72
+ #
73
+ # @param speeds [Array<Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsSpeed>, nil] Query param: Filter to fast or standard inference mode. Use `group_by[]=speed` t
74
+ #
75
+ # @param time_bucket_width [Symbol, Anthropic::Models::Beta::Organization::BetaAnalyticsTimeBucketWidth, nil] Query param: Time-bucket granularity. When set, rows are returned per time bucke
76
+ #
77
+ # @param user_profile_ids [Array<String>, nil] Query param: Filter to usage attributed to specific user profiles, by tagged use
78
+ #
79
+ # @param workspace_ids [Array<String>, nil] Query param: Filter to usage in specific workspaces, by tagged workspace ID (`wr
80
+ #
81
+ # @param betas [Array<Symbol, String, Anthropic::Models::AnthropicBeta>] Header param: This endpoint is in beta: requests must send `analytics-usage-cost
82
+ #
83
+ # @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
84
+ #
85
+ # @return [Anthropic::Internal::ReportPageCursor<Anthropic::Models::Beta::Organization::Analytics::BetaAnalyticsUsageItem>]
86
+ #
87
+ # @see Anthropic::Models::Beta::Organization::Analytics::UsageListParams
88
+ def list(params)
89
+ query_params =
90
+ [
91
+ :starting_at,
92
+ :actor_ids,
93
+ :actor_types,
94
+ :agent_ids,
95
+ :api_key_ids,
96
+ :claude_tag_categories,
97
+ :claude_tag_user_ids,
98
+ :context_windows,
99
+ :deployment_ids,
100
+ :ending_at,
101
+ :environment_ids,
102
+ :exclude_deleted_users,
103
+ :group_by,
104
+ :inference_geos,
105
+ :limit,
106
+ :models,
107
+ :order,
108
+ :order_by,
109
+ :page,
110
+ :products,
111
+ :rbac_group_ids,
112
+ :service_tiers,
113
+ :session_ids,
114
+ :slack_channel_ids,
115
+ :speeds,
116
+ :time_bucket_width,
117
+ :user_profile_ids,
118
+ :workspace_ids
119
+ ]
120
+ parsed, options = Anthropic::Beta::Organization::Analytics::UsageListParams.dump_request(params)
121
+ query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
122
+ @client.request(
123
+ span_name: Anthropic::Internal::Tracing::SpanName::ORGANIZATION_ANALYTICS_USAGE_LIST,
124
+ span_route: "/v1/organizations/analytics/usage",
125
+ span_query: %w[
126
+ actor_ids
127
+ actor_types
128
+ agent_ids
129
+ api_key_ids
130
+ claude_tag_categories
131
+ claude_tag_user_ids
132
+ context_windows
133
+ deployment_ids
134
+ ending_at
135
+ environment_ids
136
+ exclude_deleted_users
137
+ group_by
138
+ inference_geos
139
+ limit
140
+ models
141
+ order
142
+ order_by
143
+ page
144
+ products
145
+ rbac_group_ids
146
+ service_tiers
147
+ session_ids
148
+ slack_channel_ids
149
+ speeds
150
+ starting_at
151
+ time_bucket_width
152
+ user_profile_ids
153
+ workspace_ids
154
+ ],
155
+ method: :get,
156
+ path: "v1/organizations/analytics/usage?beta=true",
157
+ query: query,
158
+ headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
159
+ page: Anthropic::Internal::ReportPageCursor,
160
+ model: Anthropic::Beta::Organization::Analytics::BetaAnalyticsUsageItem,
161
+ options: {extra_headers: {"anthropic-beta" => "analytics-usage-cost-2026-08-24"}, **options}
162
+ )
163
+ end
164
+
165
+ # @api private
166
+ #
167
+ # @param client [Anthropic::Client]
168
+ def initialize(client:)
169
+ @client = client
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -6,13 +6,20 @@ 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
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).
22
+ #
16
23
  # Some parameter documentations has been truncated, see
17
24
  # {Anthropic::Models::Beta::Organization::Analytics::UsageReportListParams} for
18
25
  # more details.
@@ -6,15 +6,22 @@ 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
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).
24
+ #
18
25
  # Some parameter documentations has been truncated, see
19
26
  # {Anthropic::Models::Beta::Organization::Analytics::UserCostReportListParams} for
20
27
  # more details.
@@ -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.
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.
9
+ # [Legacy] Get per-user token usage across a date range.
10
+ #
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
  #
18
25
  # Some parameter documentations has been truncated, see
19
26
  # {Anthropic::Models::Beta::Organization::Analytics::UserUsageReportListParams}
@@ -26,6 +26,12 @@ module Anthropic
26
26
  # @return [Anthropic::Resources::Beta::Organization::Analytics::Artifacts]
27
27
  attr_reader :artifacts
28
28
 
29
+ # @return [Anthropic::Resources::Beta::Organization::Analytics::Usage]
30
+ attr_reader :usage
31
+
32
+ # @return [Anthropic::Resources::Beta::Organization::Analytics::Cost]
33
+ attr_reader :cost
34
+
29
35
  # @return [Anthropic::Resources::Beta::Organization::Analytics::UsageReport]
30
36
  attr_reader :usage_report
31
37
 
@@ -50,6 +56,8 @@ module Anthropic
50
56
  @plugins = Anthropic::Resources::Beta::Organization::Analytics::Plugins.new(client: client)
51
57
  @skills = Anthropic::Resources::Beta::Organization::Analytics::Skills.new(client: client)
52
58
  @artifacts = Anthropic::Resources::Beta::Organization::Analytics::Artifacts.new(client: client)
59
+ @usage = Anthropic::Resources::Beta::Organization::Analytics::Usage.new(client: client)
60
+ @cost = Anthropic::Resources::Beta::Organization::Analytics::Cost.new(client: client)
53
61
  @usage_report = Anthropic::Resources::Beta::Organization::Analytics::UsageReport.new(client: client)
54
62
  @user_usage_report =
55
63
  Anthropic::Resources::Beta::Organization::Analytics::UserUsageReport.new(client: client)
@@ -174,9 +174,9 @@ module Anthropic
174
174
  # part, with some files left out. An archive that cannot be read as a marketplace
175
175
  # is reported, not refused: the response is a report with `valid: false`. Plugin
176
176
  # sources outside the marketplace are fetched anonymously from GitHub, so a
177
- # private one is reported as not found; a source on any other host is not fetched
178
- # here, and the report notes that it will be checked when the marketplace actually
179
- # synchronizes.
177
+ # private one is reported as not found or as needing a GitHub sign-in; a source on
178
+ # any other host is not fetched here, and the report notes that it will be checked
179
+ # when the marketplace actually synchronizes.
180
180
  #
181
181
  # Nothing is recorded on the Compliance API activity feed.
182
182
  #
@@ -242,9 +242,9 @@ module Anthropic
242
242
  # part, with some files left out. A repository that is missing, private, or has no
243
243
  # such branch or commit is reported, not refused: the response is a report with
244
244
  # `valid: false`. Plugin sources outside the marketplace are fetched anonymously
245
- # from GitHub, so a private one is reported as not found; a source on any other
246
- # host is not fetched here, and the report notes that it will be checked when the
247
- # marketplace actually synchronizes.
245
+ # from GitHub, so a private one is reported as not found or as needing a GitHub
246
+ # sign-in; a source on any other host is not fetched here, and the report notes
247
+ # that it will be checked when the marketplace actually synchronizes.
248
248
  #
249
249
  # Nothing is recorded on the Compliance API activity feed.
250
250
  #
@@ -147,15 +147,18 @@ module Anthropic
147
147
  # already served to pin it without changing what is served. No new version is
148
148
  # created.
149
149
  #
150
- # When the organization has content scanning enabled, a version whose scan is
151
- # still running is refused with a 409 (`error_code` `scan_pending`; retry once the
152
- # scan finishes) and one whose scan failed, errored or reached no verdict with a
153
- # 400 (`scan_failed`; a `warn` is accepted). When the Plugin is in the
154
- # organization's library marketplace, a version other than the one served is also
155
- # refused with a 409 when one of its skills has a name that an organization skill
156
- # (one an administrator uploaded for the whole organization in claude.ai) has
157
- # since taken: `error_code` `skill_name_taken`, with that name in
158
- # `details.skill_name`. A member-owned Plugin cannot be updated here (403).
150
+ # When the organization has content scanning enabled, a version whose
151
+ # `content_scan.status` is `processing` is refused with a 409 (`error_code`
152
+ # `scan_pending`; retry once the scan finishes). A version whose
153
+ # `content_scan.status` is `errored`, or whose `content_scan.assessment` is `fail`
154
+ # or `unknown`, is refused with a 400 (`error_code` `scan_failed`); a `warn` is
155
+ # accepted. If the scan outcome cannot be read at that moment, the request fails
156
+ # with a retryable 503 instead. When the Plugin is in the organization's library
157
+ # marketplace, a version other than the one served is also refused with a 409 when
158
+ # one of its skills has a name that an organization skill (one an administrator
159
+ # uploaded for the whole organization in claude.ai) has since taken: `error_code`
160
+ # `skill_name_taken`, with that name in `details.skill_name`. A member-owned
161
+ # Plugin cannot be updated here (403).
159
162
  #
160
163
  # This endpoint does not write installation settings; they are written at
161
164
  # `/v1/organizations/plugins/{plugin_id}/installation_settings/{target}`.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anthropic
4
- VERSION = "2.1.0"
4
+ VERSION = "2.2.0"
5
5
  end