Skip to content

feat!: add the client to the AI spend CSV export - #32474

Merged
ssncferreira merged 2 commits into
mainfrom
ssncf/ai-spend-export-client
Nov 24, 2026
Merged

ssncferreira merged 2 commits into
mainfrom
ssncf/ai-spend-export-client

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds the client to the stable GET /api/v2/organizations/{organization}/ai/spend/export CSV export, so the Detailed report page (#32482) can export the same data with the same filters.

Changes

  • ExportOrganizationAISpend groups rows by client as well, and takes a client filter. Usage without a recorded client is reported as Unknown, like /ai/spend/users.
  • The export accepts a client query parameter, and adds a client column at the end of the CSV, so existing columns keep their position.
  • OrganizationAISpendDetailsFilter takes a Client.
  • Update the Spend export docs and the query and handler tests.

Breaking change

The AI spend CSV export (GET /api/v2/organizations/{organization}/ai/spend/export) now has a client column at the end, and splits rows by it.

If you rely on one row per user, group, model and provider, sum cost_micros and the token columns across clients to get the previous totals.

Closes AIGOV-733

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Nov 19, 2026

Copy link
Copy Markdown

AIGOV-733

@github-actions github-actions Bot added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label Nov 19, 2026
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-export-client branch 5 times, most recently from ac860e8 to a75033a Compare November 23, 2026 18:07
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-export-client branch from a75033a to a1fdc8e Compare November 23, 2026 18:10
@ssncferreira
ssncferreira marked this pull request as ready for review November 23, 2026 18:11

@mollymaefraser mollymaefraser 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 🚀 few nits but not blocking

AND (@group_id::uuid = '00000000-0000-0000-0000-000000000000'::uuid OR tu.effective_group_id = @group_id)
AND (@provider_name::text = '' OR ai.provider_name = @provider_name)
AND (@model::text = '' OR ai.model = @model)
AND (@client::text = '' OR COALESCE(ai.client, 'Unknown') = @client::text)

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.

nit: Can ai.client ever hold a real value of Unknown, or an empty string ''? An Unknown value would merge with NULL. A '' value can't be filtered for, because client= means "no filter". This matches /ai/spend/users, so it's fine if the client values come from a fixed set. I just want to confirm.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The client values come from a fixed set. AI Gateway resolves the client from the request headers, and stores Unknown when it can't. So currently, a client can't be stored as ''.

@ssncferreira
ssncferreira merged commit 1b9f2d8 into main Nov 24, 2026
34 checks passed
@ssncferreira
ssncferreira deleted the ssncf/ai-spend-export-client branch November 24, 2026 09:48
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 24, 2026

This branch had an error being deployed

1 failed and 1 inactive (outdated) deployments
docs-preview — f6773e2b Deployed Nov 24, 2026 by ssncferreira via cleanup #394
main — c438e91b Deployed Nov 19, 2026 by ssncferreira via cla #260505
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release/breaking This label is applied to PRs to detect breaking changes as part of the release process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants