Repository navigation
feat: price AI Gateway token usage with the request organization (2/2) - #31121
Merged
SasSwart merged 1 commit intoOct 30, 2026
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
SasSwart
force-pushed
the
sas/aigov-716-org-prices
branch
from
October 28, 2026 08:35
bd1d0bb to
6bc1f5a
Compare
SasSwart
force-pushed
the
sas/aigov-716-org-prices
branch
from
October 28, 2026 08:52
6bc1f5a to
26f644d
Compare
SasSwart
marked this pull request as ready for review
October 28, 2026 08:58
SasSwart
force-pushed
the
sas/aigov-716-org-prices
branch
2 times, most recently
from
October 28, 2026 13:25
4a2e92c to
58b33a3
Compare
SasSwart
force-pushed
the
sas/aigov-716-org-prices
branch
from
October 29, 2026 10:14
58b33a3 to
ca4dd58
Compare
mtojek
approved these changes
Oct 29, 2026
Cost now passes the organization stored on the interception to the price lookup, so an organization's price applies to requests made in it. The lookup falls back to the site-wide custom price and then the price book, and an interception without an organization uses only site-wide prices.
SasSwart
force-pushed
the
sas/aigov-716-org-prices
branch
from
October 30, 2026 11:20
ca4dd58 to
235e6f1
Compare
SasSwart
added a commit
that referenced
this pull request
Oct 30, 2026
…1/2) (#31120) `IsAuthorized` resolves the workspace organization, but uses it only to reject requests; nothing downstream reads it. The budget check and cost each resolve the group site-wide, so a user working in an org B workspace can be billed in org A, and no interception records its organization. Resolve the request organization once, in `IsAuthorized`. A workspace session token resolves to the workspace's organization (source `workspace`). Any other request, including chatd requests until AIGOV-713, resolves to the organization of the user's site-wide effective group (source `effective_group`). Return the source in `IsAuthorizedResponse`. Have aibridged pass the organization to `IsBudgetExceeded`, which resolves the budget inside it, and stamp the organization and source on `RecordInterception`. Resolve cost's effective group inside the organization stored on the interception. When there is no organization, behave site-wide as before. Move `resolveOrganization` and the workspace checks into `orgresolver.go`, and leave a slot for the chat organization (AIGOV-713). Bump the aibridged API to v1.6, adding `IsAuthorizedResponse.organization_source` and `IsBudgetExceededRequest.organization_id`. aibridged checks only the shape of the organization (both fields or neither, and a valid non-nil UUID), not the source value. That lets a newer coderd add a source without breaking older gateways. Behaviour changes to review: - Spend follows the workspace's organization. A user whose budgets are all in org A has no limit in an org B workspace if B has none. - A database error while resolving the organization now returns 403 from `IsAuthorized`, instead of 500 from `IsBudgetExceeded`. - Requests without a workspace make up to three extra budget queries in `IsAuthorized`. - The user spend status endpoint (`GET /api/v2/users/{user}/ai/spend`) stays site-wide, so it can disagree with where a request was charged. The org-aware price lookup follows in #31121. Part of AIGOV-716. Stacked on #31119. --- *This PR was generated by Coder Agents on behalf of @SasSwart.*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cost looks up model prices site-wide only, so an organization's own prices never apply, even though #31118 now stores the request organization on each interception.
Pass the interception's stored organization to
GetAIModelPriceForProvider. The lookup already falls back from the organization's price to the site-wide custom price, then to the price book. An interception without an organization (old rows, old gateways) uses only site-wide prices, as before.Remove
TODO(AIGOV-716). MakeTestRecordTokenUsageAuthorizedstore an organization and assert that its price wins under the strict authorizer.Part of AIGOV-716. Stacked on #31120.
This PR was generated by Coder Agents on behalf of @SasSwart.