Repository navigation
feat: list organization AI spend by user - #29129
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
57e6569 to
c337295
Compare
c337295 to
d5f1fb7
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Documentation CheckUpdates Needed
New Documentation Needed
Automated review via Coder Agents |
d5f1fb7 to
3e825a5
Compare
3e825a5 to
5ee43cd
Compare
|
This PR was reworked in place on 2026-09-15: the stack now extends the released organization spend export ( @codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ee43cdc7e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
5ee43cd to
2e3b042
Compare
2c6de9d to
9c022df
Compare
|
Pushed fixes for the human review round (period validation switch, Swagger description, test moves, combined filter case, @codex review
|
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
62011b2 to
e73049f
Compare
|
Pushed the @codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e73049fb80
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Adds GET /api/v2/organizations/{organization}/ai/spend/users, a paginated
per-user report built from the same token usage as the CSV export, with
optional provider_name, model, and client filters. Each user lists the
providers and clients they spent through, and the report echoes the
applied period and the start of the retention window so clients can bound
their date pickers.
The period parsing is shared with the export through the caller's query
parser, so both endpoints now reject unknown query parameters whether or
not a period is given.
…n object Fill the report's totals object and regenerate the API reference.
Separate the default, half-specified, and explicit period cases in a switch again, keeping the shared parameter validation ahead of it. Move the export's unknown page parameter case beside the other export period validation cases, cover a combined dimension filter, and reword the filter description.
The organization AI spend users endpoint returns each user's sorted models next to providers and clients, with the API docs regenerated.
…nd users Follows the codersdk change: the handler and its tests use OrganizationAISpendPage, which cannot carry an unsupported cursor.
e73049f to
8cdc127
Compare
|
Restacked on the SDK page type (8cdc127); the retention-boundary thread is answered above. @codex review
|
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Third of a four-PR stack that reworks the AI spend page onto the released organization spend export,
GET /api/v2/organizations/{organization}/ai/spend/export, and a sibling per-user endpoint,GET /api/v2/organizations/{organization}/ai/spend/users, instead of the deployment-wide/api/v2/ai-gateway/spend/*endpoints this stack previously proposed. Every PR in the stack was rewritten in place from current main; the head branch name predates the rework. The export's accounting rules are unchanged: token usage bycreated_atin[period_start, period_end), attributed to the organization through the effective budget group, so the page reconciles with the CSV and with daily budget accounting.Adds
GET /api/v2/organizations/{organization}/ai/spend/users, a paginated per-user report beside the CSV export. It accepts the export's period parameters and the optionalprovider_name,model, andclientfilters (clientmatches afterCOALESCE(client, 'Unknown'), as the AI Gateway sessions listing does), and it authorizes identically throughResourceGroupMemberin the organization. The response isOrganizationAISpendReport: the applied period bounds,retention_startwhen retention is enabled (so the page can bound its date picker), the user count, atotalsobject over every matching user, and one page of users (limitdefault 10, max 100;offset>= 0), each with cost, unpriced usage count, providers, and clients. Each user row also lists the sorted distinct models they spent through (e73049f, added on request after the review round).The period rules (provided together, at most 31 days, within retention, default narrowed to retention) are shared with the export through the caller's query parser. As a result the export now rejects unknown query parameters whether or not a period is given; previously the excess-parameter check only ran in the explicit-period branch. The export's parameters and output are otherwise unchanged; the CSV itself is not filterable.
The JSON rows are per user while the CSV keeps its user x group x provider x model grain. That is deliberate: the page is the only JSON consumer, and an explicit
group_bycan be added later without changing this contract. A page past the last user still carries the window totals, read from the first page.Query cost, measured on PostgreSQL 13 with 400k token usages and 200k interceptions across 4 organizations (31-day window of about 52k usages for the target organization):
ListOrganizationAISpendUsers128 ms unfiltered and 68 ms filtered by provider. Token usage is read through the existing partial index on(effective_group_id, created_at); no new index is needed. The provider and client aggregates were added after this measurement.Tests cover pagination validation (including the export rejecting page parameters), report contents and filters against the CSV, retention narrowing and rejection, retention disabled, and the role matrix (Owner, User Admin, Auditor, Org Admin, Org User Admin OK; member 403; other organization 404).
Previous revisions served this report from the export endpoint through
Acceptnegotiation and also added the dimension filters to the CSV export (#29220, #29224); the separate endpoint replaces the former, and the CSV filters were dropped because the page does not use them.Codex on e73049f: P2 on the moving
now - retentionlower bound for clients that echo the default window while paging. Declined: it is the released CSV export's contract, the report echoesretention_start, and the page never echoes the default window; the handler and tests now useOrganizationAISpendPage(8cdc127).