Skip to content

docs: document how AI Gateway assigns a request's organization - #31925

Merged
SasSwart merged 3 commits into
mainfrom
sas/aigov-753-document-org-resolution
Nov 17, 2026
Merged

SasSwart merged 3 commits into
mainfrom
sas/aigov-753-document-org-resolution

Conversation

@SasSwart

@SasSwart SasSwart commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Documents how AI Gateway assigns every request to one organization, and how that organization now decides the effective group, budget, overrides, and spend. Adds a Request organization page and corrects pages that still described budget resolution as deployment-wide.

Refs AIGOV-753. Describes behavior merged in #30902, #31118, #31119, #31120, #31121, #31583, and #31584.

Changes

  • New page docs/ai-governance/ai-gateway/request-organization.md (sidebar, after Cost control): resolution order, the effective group fallback, rejected requests, what the organization controls, a multi-org worked example, reports that still resolve across all orgs, and the caveat for standalone gateways older than v2.40.
  • cost-controls.md: removes "the effective group is deployment-wide", scopes overrides and effective group resolution to the request's organization, and adds the reporting caveat.
  • standalone.md: older replicas check budgets across all organizations.
  • coder-agents/platform-controls/{index,spend-management}.md: these said an override beats every group budget, which is no longer true for chats in another organization.

For reviewers

  • Mismatch rejection is not documented. The ticket and RFC describe rejecting a workspace/chat org mismatch. A chat can only bind a workspace in its own org (coderd/exp_chats.go), chatd requests resolve to the chat's org even with a workspace, and no client request can carry both inputs. The page says the two always agree instead.
  • "v2.40" is inferred. release/2.39 is on aibridged API v1.5 and main is on v1.6, so v1.6 ships in v2.40. A 2.39.x backport would make this wrong.
  • Custom prices. The price lookup reads per-org prices, but no API or CLI can set them yet, so the page says custom prices apply in every org. This needs an update when per-org prices ship.
  • Site-wide reports. The avatar menu, Agents usage indicator, GET /api/v2/users/{user}/ai/spend, Members tab budget, Groups page combined limit, and blocked_users metric still resolve across all orgs (TODO(AIGOV-527)), so they can disagree with what was enforced.

Release note draft

- AI Gateway budgets and spend follow the request's organization (#31119, #31120, #31121, #31583, #31584)

  > Every AI Gateway request now belongs to one organization: the workspace's organization for workspace session tokens, the chat's organization for Coder Agents, and otherwise the organization of the user's effective group. Budgets, user overrides, and spend apply within that organization only, instead of across all of the user's organizations. Users in one organization see no change. Users in several organizations can hit a smaller budget, or have no limit at all, in another organization's workspaces and chats. Requests are rejected when the user is no longer a member of the workspace's or chat's organization, or of any organization.
  >
  > Migration: Set budgets in every organization your users send AI requests from. Upgrade standalone AI Gateway replicas to v2.40. Older replicas keep checking budgets across all organizations until upgraded.

Validation

make pre-commit-light, Vale on the changed files, and make lint/docs-manifest pass. A doc-check author self-check found 13 blocking findings, all fixed. Not applied: a suggested test pinning the site-wide spend endpoint (code change, out of scope for this docs PR).

Decision log and verified behavior

Sources: AIGOV-753, epic AIGOV-749 and its delivered tickets (AIGOV-712 to 716), the canceled AIGOV-717, and the RFC "AI Gateway Model RBAC and Org-Scoping" (Phase 1).

Verified against main (a3aab79775):

Claim Evidence
Order: workspace session token, chat org, site-wide effective group coderd/aibridgedserver/orgresolver.go resolveOrganization
Workspace session token = coder_workspace_owner.session_token provisionerdserver.WorkspaceSessionTokenName, workspaceAttribution (API tokens excluded)
Rejections return 403 unauthorized coderd/aibridged/http.go IsAuthorized failure path
Rejected: deleted workspace, not a member of the workspace/chat org or org deleted, no live org orgresolver.go ErrUnknownWorkspace, ErrUnknownOrganizationMember, ErrNoOrganization
Chat request takes chat org even with a workspace enterprise/aibridged_integration_test.go "delegated organization with workspace"
With an org, only that org's groups, override, and Everyone group count coderd/aibridge/budget/budget.go, #31119
Fallback with no budgets: default org, then earliest membership GetUserEveryoneFallbackGroup
Budget counts only spend recorded against its group GetUserAISpendSince keyed on effective_group_id
Notifications use the per-request effective group coderd/aibridgedserver/notifications.go
Per-org prices not settable UpsertOrganizationAIProviderModelConfig has no non-test caller
v2.39 gateways: site-wide budget check, no org recorded release/2.39 coderd/aibridged/http.go, aibridge/recorder/drpc_recorder.go

Page vs. section: a dedicated explanation page, because cost-controls.md is already long and RFC Phases 3 and 4 (model RBAC, "require organization scope") will build on the same resolution rules.


This PR was generated by Coder Agents on behalf of @SasSwart.

Add a Request organization page that explains how AI Gateway picks the
organization for each request (workspace session token, then Coder
Agents chat, then the effective group fallback), which requests are
rejected, and how the organization drives budgets, overrides and spend.

Update cost control, standalone gateway and Coder Agents spend pages
that described budget resolution as deployment-wide.

Refs AIGOV-753
@SasSwart
SasSwart temporarily deployed to main November 9, 2026 12:32 — with GitHub Actions Inactive
@SasSwart
SasSwart temporarily deployed to main November 9, 2026 12:32 — with GitHub Actions Inactive
@linear-code

linear-code Bot commented Nov 9, 2026

Copy link
Copy Markdown

AIGOV-753

@SasSwart
SasSwart marked this pull request as ready for review November 13, 2026 08:29
@SasSwart
SasSwart temporarily deployed to main November 13, 2026 08:30 — with GitHub Actions Inactive
…t-org-resolution

# Conflicts:
#	docs/manifest/ai-governance/ai-gateway.yml
@SasSwart
SasSwart temporarily deployed to main November 13, 2026 08:37 — with GitHub Actions Inactive
@SasSwart
SasSwart temporarily deployed to docs-preview November 13, 2026 08:39 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Links open this pull request's preview at https://pr-31925.docs.cdr-preview.dev, which updates with each push.

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.

Preview sites for each built commit (1)

Every built commit keeps its own preview, newest first. Previews aren't indexed by search engines and are deleted when this pull request is merged or closed.

@nickvigilante nickvigilante 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.

A mix of my feedback and Coder Agents's feedback. Overall, the docs read well, and I only have a few nits.


### Model prices

The request's organization doesn't change the price, because the custom prices that you set with [`coder exp ai-model-prices`](./cost-controls.md#configure-model-prices) apply in every organization.

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.

Optional: this statement depends on a current limitation (no API or CLI can set per-org prices yet, per the PR description) and will go stale when per-org prices ship. Consider linking the tracking ticket in the PR or a follow-up issue so the page gets updated with that change.

🤖 Review generated with Coder Agents on behalf of @nickvigilante.

- Keep the list of site-wide reports only on the request organization page.
- Say the spend export aggregates spend and does not list requests.
- Say where coderd rejects requests for older standalone replicas.
- Apply suggested wording for the earlier-than-v2.40 section.
@SasSwart
SasSwart temporarily deployed to main November 16, 2026 11:05 — with GitHub Actions Inactive

@nickvigilante nickvigilante 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! :shipit: 🚀

@SasSwart
SasSwart merged commit 4ac8f0a into main Nov 17, 2026
32 of 35 checks passed
@SasSwart
SasSwart deleted the sas/aigov-753-document-org-resolution branch November 17, 2026 07:51
@SasSwart
SasSwart temporarily deployed to main November 17, 2026 07:51 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
docs-preview — 1d0162dd Deployed Nov 17, 2026 by SasSwart via cleanup #154
main — 1d0162dd Deployed Nov 17, 2026 by SasSwart via cla #258435
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