Skip to content

feat: filter the organization AI spend export by provider, model, and client - #29224

Closed
ibetitsmike wants to merge 3 commits into
mike/ai-spend-sdkfrom
mike/ai-spend-endpoint-users
Closed

ibetitsmike wants to merge 3 commits into
mike/ai-spend-sdkfrom
mike/ai-spend-endpoint-users

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Fourth of a six-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 by created_at in [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.

The export handler parses every query parameter with one QueryParamParser, so provider_name, model, and client reach the CSV query and unknown parameters fail with 400 whether or not a period is given. Previously the excess-parameter check only ran in the explicit-period branch.

Includes the regenerated API docs and endpoint tests for each filter and for the uniform excess-parameter rejection.

Xum prepared this PR on behalf of @ibetitsmike.

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check 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.

@ibetitsmike
ibetitsmike force-pushed the mike/ai-spend-endpoint-users branch from 903e233 to 3a53085 Compare September 11, 2026 10:01
@ibetitsmike
ibetitsmike marked this pull request as ready for review September 11, 2026 11:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T23:08:45.184134Z f434067 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike
ibetitsmike force-pushed the mike/ai-spend-endpoint-users branch from 3a53085 to a307401 Compare September 14, 2026 08:03
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: a3074017f3

ℹ️ 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".

@ibetitsmike
ibetitsmike marked this pull request as draft September 15, 2026 18:48
@ibetitsmike
ibetitsmike removed this pull request from stack #29225 September 15, 2026 18:49
@ibetitsmike
ibetitsmike force-pushed the mike/ai-spend-endpoint-users branch from a307401 to 7f9d14c Compare September 15, 2026 18:51
@ibetitsmike ibetitsmike changed the title feat: add AI Gateway spend users endpoint feat: filter the organization AI spend export by provider, model, and client Sep 15, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

This PR was reworked in place on 2026-09-15: the stack now extends the released organization spend export (GET /api/v2/organizations/{organization}/ai/spend/export) with filters and an Accept: application/json per-user report instead of adding /api/v2/ai-gateway/spend/* endpoints, and the page shows one organization's total and per-user cost only. The description above reflects the new content; earlier review threads refer to code that no longer exists on this branch. #29222 (session counts) was closed because it has no counterpart.

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7f9d14cc1f

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/ai-spend-endpoint-users branch from 7f9d14c to f434067 Compare September 15, 2026 20:37
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Re-requesting review on the current head after the stack rebase (same content, new commit).

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: f434067114

ℹ️ 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".

…l, and client

Add optional provider_name, model, and client parameters to
ExportOrganizationAISpend, matching the predicates ListOrganizationAISpendUsers
already applies. An empty value matches everything, and client compares
against COALESCE(client, 'Unknown') like the AI Gateway sessions list. The
export handler passes empty filters for now; exposing them as query
parameters follows separately.

Cover the filters on the export and add a reconciliation test that sums the
export per user and compares it with the user report for every filter
combination, so the two queries cannot drift apart silently.
Add OrganizationAISpendFilter, which carries the period plus the optional
provider_name, model, and client dimensions for the organization AI spend
export, and switch ExportOrganizationAISpend to it. Add
OrganizationAISpendReport and OrganizationAISpendUser, the paginated
per-user JSON representation of the same export, with OrganizationAISpend
requesting it through Accept: application/json.

The server side of the filters and the JSON representation follows in the
next changes; existing callers keep receiving CSV.
… client

Accept optional provider_name, model, and client query parameters on
GET /organizations/{organization}/ai/spend/export and pass them to the
export query. Parse every parameter with one query parser so unknown
parameters are rejected with 400 regardless of whether a period is given;
previously only requests with an explicit period were checked.

Cover each filter, the Unknown client, empty filters, and the uniform
unknown-parameter rejection.
@ibetitsmike
ibetitsmike force-pushed the mike/ai-spend-endpoint-users branch from f434067 to d0b0237 Compare September 16, 2026 11:17
@ibetitsmike
ibetitsmike removed this pull request from stack #29372 September 16, 2026 12:23
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 16, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Closing: this stack was reshaped to drop the CSV export dimension filters. The Spend page reads the per-user JSON report (/ai/spend/users, #29129), which keeps its provider_name, model, and client filters; the CSV export stays unfiltered as released. #29220 is closed for the same reason. The branch is left in place in case the filters are wanted later.

Xum closed this PR on behalf of @ibetitsmike.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant