GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@SasSwart

@SasSwart SasSwart commented Oct 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

AIGOV-716

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned SasSwart Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 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.

  • docs/admin/integrations/devcontainers/envbuilder/add-envbuilder.md
  • docs/admin/integrations/multiple-kube-clusters.md
  • docs/admin/security/secrets.md
  • docs/admin/templates/extending-templates/agent-metadata.md
  • docs/admin/templates/extending-templates/modules.md
  • docs/admin/templates/extending-templates/parameters/compatibility-mode.md
  • docs/admin/templates/extending-templates/parameters/conditional-parameters.md
  • docs/admin/templates/extending-templates/parameters/form-types.md
  • docs/admin/templates/extending-templates/parameters/identity-aware-parameters.md
  • docs/admin/templates/extending-templates/parameters/index.md
  • docs/admin/templates/extending-templates/parameters/troubleshooting.md
  • docs/admin/templates/extending-templates/parameters/validation.md
  • docs/admin/templates/extending-templates/parameters/workspace-presets.md
  • docs/admin/templates/extending-templates/prebuilt-workspaces.md
  • docs/admin/templates/index.md
  • docs/admin/templates/managing-templates/index.md
  • docs/admin/templates/open-in-coder.md
  • docs/ai-coder/agent-firewall/example-policy.md
  • docs/ai-coder/agent-firewall/index.md
  • docs/ai-coder/agents/getting-started.md
  • docs/ai-coder/agents/licensing-usage.md
  • docs/ai-coder/agents/platform-controls/index.md
  • docs/ai-coder/agents/platform-controls/template-optimization.md
  • docs/ai-coder/ai-gateway/audit.md
  • docs/get-started/customize-your-template/add-a-language.md
  • docs/get-started/index.md
  • docs/install/server/kubernetes/index.md
  • docs/install/server/rancher.md
  • docs/tutorials/cloning-git-repositories.md
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SasSwart SasSwart mentioned this pull request Oct 26, 2026
feat: use the resolved organization for AI Gateway budgets and cost (1/2) #31120
Merged
@SasSwart
SasSwart added this pull request to stack #31264 October 26, 2026 12:00
@SasSwart
SasSwart force-pushed the sas/aigov-716-org-prices branch from bd1d0bb to 6bc1f5a Compare October 28, 2026 08:35
@SasSwart
SasSwart force-pushed the sas/aigov-716-org-prices branch from 6bc1f5a to 26f644d Compare October 28, 2026 08:52
@SasSwart
SasSwart requested a review from ssncferreira October 28, 2026 08:58
@SasSwart
SasSwart marked this pull request as ready for review October 28, 2026 08:58
@SasSwart
SasSwart force-pushed the sas/aigov-716-org-prices branch 2 times, most recently from 4a2e92c to 58b33a3 Compare October 28, 2026 13:25
@SasSwart
SasSwart force-pushed the sas/aigov-716-org-prices branch from 58b33a3 to ca4dd58 Compare October 29, 2026 10:14
mtojek
mtojek approved these changes Oct 29, 2026
View reviewed changes
@SasSwart
feat: price AI Gateway token usage with the request organization (2/2)
235e6f1
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
SasSwart force-pushed the sas/aigov-716-org-prices branch from ca4dd58 to 235e6f1 Compare October 30, 2026 11:20
@SasSwart
SasSwart merged commit 5baa8ef into main Oct 30, 2026
27 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@SasSwart
SasSwart deleted the sas/aigov-716-org-prices branch October 30, 2026 11:35
SasSwart added a commit that referenced this pull request Oct 30, 2026
@SasSwart
feat: use the resolved organization for AI Gateway budgets and cost (…
15365c6
…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.*
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@mtojek mtojek mtojek approved these changes
@ssncferreira ssncferreira Awaiting requested review from ssncferreira

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@SasSwart SasSwart

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@SasSwart @mtojek
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.