Skip to content

feat: scope unpriced AI models to an organization and its prices - #31752

Merged
ssncferreira merged 2 commits into
ssncf/unpriced-models-queryfrom
ssncf/unpriced-models-org-scope
Nov 13, 2026
Merged

ssncferreira merged 2 commits into
ssncf/unpriced-models-queryfrom
ssncf/unpriced-models-org-scope

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Scopes GetUnpricedAIModels to an optional organization and checks organization prices, so the unpriced models endpoint can list what an organization still needs to price. Usage is attributed to an organization through its token usage's effective group, the same as spend.

Changes

  • Optional organization_id: when set, only that organization's usage counts, and when null (the notification), all usage counts.
  • A model still holds a price if it has a site-wide price for the provider type, or an organization price (ai_model_configs, live and with a price) for the provider in the usage's organization.
  • dbauthz reads ResourceAiModelPrice, scoped to the organization when one is given, like GetAIModelPriceForProvider.
  • Table-driven query tests run every case for all organizations, org A and org B.
Cases

Model X is on anthropic-prod. Y is the model the provider reports serving for X. "Notif" is the deployment-wide notification, "UI A/B" is the endpoint for org A/B.

# Prices Usage Notif before Notif after UI A UI B
1 No price for X anywhere A uses X, unpriced ✅ ✅ ✅ ❌ (B didn't use X)
2 Site-wide price for X A and B use X, priced ❌ ❌ ❌ ❌
3 A priced X before the usage Only A uses X, priced ❌ ❌ ❌ ❌
4 A priced X after the usage Only A uses X, unpriced when recorded ✅ (wrong) ❌ ❌ ❌
5 A priced X, B has none A uses X (priced), B uses X (unpriced) ✅ (because of B) ✅ (because of B) ❌ ✅
6a No price for X or Y when recorded, then Y priced site-wide Only A uses X, unpriced when recorded ✅ ✅ ✅ ❌
6b Same as 6a A and B use X, unpriced when recorded ✅ ✅ ✅ ✅
7a No price for X, but a site-wide price for Y A uses X, priced through Y ❌ ❌ ❌ ❌
7b No price for X, A priced Y, and B has none A and B use X: A priced through Y, B unpriced ✅ (because of B) ✅ (because of B) ❌ ✅

Note: pagination will be added in a follow-up.

Related to AIGOV-730

Note

Generated by Coder Agents on behalf of @ssncferreira.

@ssncferreira
ssncferreira added this pull request to stack #31754 November 4, 2026 12:36
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 6e21386 to 7fe798c Compare November 4, 2026 12:43
@linear-code

linear-code Bot commented Nov 4, 2026

Copy link
Copy Markdown

AIGOV-730

@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 7fe798c to eb91267 Compare November 6, 2026 10:53
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from eb91267 to b0728cc Compare November 6, 2026 11:10
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from b0728cc to 20eacaa Compare November 6, 2026 11:15
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 20eacaa to 5fd78f9 Compare November 6, 2026 11:27
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 5fd78f9 to 195e62e Compare November 6, 2026 11:32
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 195e62e to 45aa183 Compare November 6, 2026 11:38
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 45aa183 to 2acf4e4 Compare November 6, 2026 11:47
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 2acf4e4 to 8e16ebf Compare November 6, 2026 11:50
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 8e16ebf to e85c847 Compare November 6, 2026 12:00
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from e85c847 to 22ef31f Compare November 6, 2026 12:05
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch 2 times, most recently from e6034d4 to b7a54c3 Compare November 6, 2026 12:14
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from b7a54c3 to cffdd02 Compare November 6, 2026 15:47
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch 8 times, most recently from d635f43 to 492b2fc Compare November 6, 2026 16:18
@ssncferreira
ssncferreira marked this pull request as ready for review November 6, 2026 16:48
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 492b2fc to b9f855e Compare November 11, 2026 12:54
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from b9f855e to a1038da Compare November 12, 2026 10:20
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from a1038da to 3c756d9 Compare November 13, 2026 10:58
@ssncferreira
ssncferreira requested a review from pawbana November 13, 2026 11:59
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-org-scope branch from 3c756d9 to 1ca8010 Compare November 13, 2026 12:17

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

Well done. changes to request. Just a few questions for my own understanding.

Comment thread coderd/database/querier_test.go Resolved
Comment thread coderd/database/querier_test.go Resolved
Comment thread coderd/database/querier_test.go Resolved
@ssncferreira
ssncferreira merged commit d611c60 into main Nov 13, 2026
29 checks passed
@ssncferreira
ssncferreira deleted the ssncf/unpriced-models-org-scope branch November 13, 2026 13:21
@ssncferreira
ssncferreira temporarily deployed to docs-preview November 13, 2026 13:21 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
docs-preview — 2309bb2d Deployed Nov 13, 2026 by ssncferreira via cleanup #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants