Skip to content

feat(sdk): add grouped usage report endpoints and V2 usage report filters - #202

Open
bmaydan wants to merge 5 commits into
mainfrom
ben/usage-report-grouped
Open

bmaydan wants to merge 5 commits into
mainfrom
ben/usage-report-grouped

Conversation

@bmaydan

@bmaydan bmaydan commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Brings the SDK's billing activity APIs in line with the V2 usage report and exposes the Reports page's grouped usage data.

Filters (V2 usage report parity)

  • Add cluster_ids and subfilters (job / multi-machine job / deployment tags, assistant message API keys) to BillingActivityFilters and BillingApi.
  • get_activity_filter_values returns cluster IDs and subfilter values, and drops resource_ids / resource_ids_truncated, which the server no longer sends. New get_activity_filter_resource_names pages through resource IDs.
  • BillingActivityFilterValues.resource_types now pairs each type ID with its display name (from named_resource_types), falling back to the raw IDs for older servers.
  • CSV downloads no longer send limit / cursor (ignored server-side) and now forward tag subfilters under the same dotted keys the UI uses.

Grouped endpoints

  • get_activity_group_totals — cost per resource type, user or teamspace over the range (/usage-report-rollup/group-totals).
  • get_activity_group_daily_totals — the same split per UTC day (/usage-report-rollup/group-daily-totals).
  • get_activity_breakdown — the breakdown CSV download, one row per UTC day × resource type × user × teamspace, as CSV or JSON (/usage-report/download/breakdown).
  • New BillingActivityGroupBy enum and BillingActivityGroup* dataclasses, exported and documented in organization.rst, with Organization wrappers.

Tests

  • Unit tests for the new endpoints and filters, plus contract tests (test_billing_api_contract.py) that run BillingApi through the real generated client with only the HTTP request stubbed, so drift against the vendored client fails in tests rather than at runtime.

🤖 Generated with Claude Code

— Claude Opus 5.5, on direct instruction; text not reviewed

bmaydan and others added 4 commits October 14, 2026 14:33
…port

The V2 usage report and its filter-values endpoint gained cloud account
and per-resource-type filters, and moved resource IDs to a paginated
endpoint, so the SDK's billing filters had fallen behind:

- Add cluster_ids and subfilters (job/MMT/deployment tags, assistant
  message API keys) to BillingActivityFilters and BillingApi.
- Return cluster_ids and subfilter values from get_activity_filter_values,
  dropping resource_ids/resource_ids_truncated, which the server no
  longer sends.
- Add get_activity_filter_resource_names for paging through resource IDs.
- Stop sending limit and the pagination cursor to the CSV downloads,
  which ignore them, and reject tag subfilters there since the download
  endpoints don't apply them yet.
- Fix resource type examples to the raw values the server uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The session and resource download endpoints now read the job, multi-machine
job and deployment tag subfilters (grid #47735), so forward them under the
same dotted keys the UI uses instead of rejecting them with a ValueError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BillingActivityFilterValues.resource_types now pairs each resource type
ID with its display name, read from the server's named_resource_types.
Servers that don't send it yet fall back to the legacy raw IDs, named
after themselves.

Also adds contract tests that run BillingApi through the real generated
client, stubbing only the HTTP request, so drift between BillingApi and
the vendored client shows up in tests rather than at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ownload

Expose the Reports page's grouped usage data through BillingApi and
Organization:

- get_activity_group_totals: cost per resource type, user or teamspace,
  summed over the queried range (/usage-report-rollup/group-totals).
- get_activity_group_daily_totals: the same split per UTC day
  (/usage-report-rollup/group-daily-totals).
- get_activity_breakdown: the breakdown CSV download, one row per UTC day,
  resource type, user and teamspace, as CSV or JSON
  (/usage-report/download/breakdown).

All three take the same filters as the V2 usage report. Adds the
BillingActivityGroupBy enum and the BillingActivityGroup* response
dataclasses, exports them, and documents them in the organization docs.
get_activity now shares its filter kwargs builder with the grouped
endpoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ation method

Sphinx can't resolve BillingApi, which isn't in the docs, so the docs
build failed on the cross-reference. Also applies ruff's
pytest.fixture() style to the contract tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant