Skip to content

feat: add organization AI spend report types and client methods - #29223

Merged
ibetitsmike merged 4 commits into
mike/ai-spend-query-usersfrom
mike/ai-spend-sdk
Sep 17, 2026
Merged

ibetitsmike merged 4 commits into
mike/ai-spend-query-usersfrom
mike/ai-spend-sdk

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

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

Adds the SDK types for the per-user report: OrganizationAISpendFilter (an optional period plus the three dimension filters, so the generated TypeScript type accepts the server default period), OrganizationAISpendUser (cost, unpriced usage count, models, and the providers and clients the user spent through), and OrganizationAISpendReport (the applied period, the retention window start when the deployment purges AI Gateway data, a totals object with the cost and unpriced usage count over every matching user, and one page of users). The new OrganizationAISpendUsers method requests /ai/spend/users with pagination and decodes the report. ExportOrganizationAISpend is unchanged.

Includes the regenerated typesGenerated.ts.

Xum prepared this PR on behalf of @ibetitsmike.

Codex on c90e9a1: P2, the SDK method took Pagination, whose AfterID cursor the endpoint rejects; fixed in 14d0797 with an offset-only OrganizationAISpendPage.

@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 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 🔄 Running since 2026-09-17T04:31:20.348642Z 14d0797 Draft marked ready
ℹ️ 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 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 changed the base branch from mike/ai-spend-query-session-counts to mike/ai-spend-query-rollups September 15, 2026 18:49
@ibetitsmike ibetitsmike changed the title feat: add AI Gateway spend SDK types and client methods feat: add organization AI spend report types and client methods 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dcaab5d0b1

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

Comment thread codersdk/aibridge.go Resolved
Comment thread codersdk/aibridge.go Resolved
Comment thread codersdk/aibridge.go Resolved
Comment thread site/src/api/typesGenerated.ts Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Pushed fixes for the review round (see the resolved threads for details).

@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. Breezy!

Reviewed commit: 8fbedad4c1

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

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment thread codersdk/aibridge.go Resolved
@ibetitsmike
ibetitsmike removed this pull request from stack #29372 September 16, 2026 12:23
@ibetitsmike
ibetitsmike changed the base branch from mike/ai-spend-query-rollups to mike/ai-spend-query-users September 16, 2026 12:23
Comment thread codersdk/aibridge.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Pushed fixes for the human review round (report totals moved into a totals object).

@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: 1ecb60bc7f

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

Add OrganizationAISpendFilter, which carries the period plus the optional
provider_name, model, and client dimensions for the per-user organization
AI spend report, and OrganizationAISpendReport and OrganizationAISpendUser,
its paginated JSON representation. OrganizationAISpendUsers requests it
from GET /organizations/{organization}/ai/spend/users. The CSV export
client method is unchanged.

The server side follows in the next change.
Move the report's total cost and unpriced usage count into a totals object.
Each user in the organization AI spend report lists the models they
spent through, sorted, next to providers and clients.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Pushed the models field on OrganizationAISpendUser (c90e9a1) and restacked.

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c90e9a1ccd

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

Comment thread codersdk/aibridge.go Resolved
The users endpoint pages by limit and offset, so the SDK method takes an
OrganizationAISpendPage instead of Pagination, whose AfterID cursor the
endpoint rejects as an unknown parameter.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Pushed the offset-only page type (14d0797).

@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. Keep them coming!

Reviewed commit: 14d0797368

ℹ️ 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 ready for review September 17, 2026 04:31
@ibetitsmike
ibetitsmike merged commit 518d1ac into main Sep 17, 2026
37 checks passed
@ibetitsmike
ibetitsmike deleted the mike/ai-spend-sdk branch September 17, 2026 04:32
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 17, 2026
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.

2 participants