GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing github.com — feat: price AI Gateway token usage with the request organization (2/2) by SasSwart · Pull Request #31121 · coder/coder Conversation
|
| Stored org | Org price | Site-wide custom | Price used |
|---|---|---|---|
| none | any | any | site-wide custom, then price book |
| B | live | any | B's price |
| B | soft-deleted or absent | present | site-wide custom |
| B | absent | absent | price book, or NULL cost |
Remove TODO(AIGOV-716). Make TestRecordTokenUsageAuthorized store 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
All contributors have signed the CLA ✍️ ✅ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bd1d0bb to
6bc1f5a
Compare
6bc1f5a to
26f644d
Compare
4a2e92c to
58b33a3
Compare
58b33a3 to
ca4dd58
Compare
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.
ca4dd58 to
235e6f1
Compare
There was an error while loading. Please reload this page.
…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.*
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.