Repository navigation
feat: add organization unpriced AI models endpoint - #31753
Conversation
ad8cc69 to
a88e1cb
Compare
a88e1cb to
50901a6
Compare
50901a6 to
25fcdf7
Compare
25fcdf7 to
f4fca88
Compare
f4fca88 to
4484f55
Compare
4484f55 to
83ad095
Compare
83ad095 to
2638c0a
Compare
2638c0a to
0a301d4
Compare
0a301d4 to
577e27c
Compare
577e27c to
9721677
Compare
9721677 to
909764a
Compare
909764a to
fe61228
Compare
fe61228 to
87c0ba1
Compare
c7ed743 to
f4e2209
Compare
f4e2209 to
20109cd
Compare
20109cd to
edb1b37
Compare
ca467db to
243f1ce
Compare
243f1ce to
21028c4
Compare
21028c4 to
a4e5815
Compare
a4e5815 to
91e4a81
Compare
91e4a81 to
cb2baf0
Compare
cb2baf0 to
03de7ab
Compare
| // | ||
| // @Summary List organization unpriced AI models | ||
| // @Description Returns, for each provider, the requested models with token usage recorded without a price in the organization over the period, most unpriced tokens first. Only models without a price now are returned. A model has a price when it has a site-wide price for the provider's type or an organization price for the provider. Usage is attributed to the organization through its effective group. | ||
| // @Description The optional period_start and period_end query parameters bound the period and are interpreted as UTC. They must be provided together and span at most 31 days. When both are omitted, the current budget period is used. |
There was a problem hiding this comment.
Blocking: wrong default presented as fixed (Fact Checker).
The handler calls aiSpendRetainedPeriod (enterprise/coderd/aimodelprices.go:378). When the AI Gateway retention (default 60d, codersdk/deployment.go:2012-2019) is shorter than the budget period, the default start is clamped to the retention window. An explicit period_start older than that window returns 400 (enterprise/coderd/aibridge.go:1267-1291). The sibling export endpoint documents both behaviors at enterprise/coderd/aibridge.go:1296, and this description does not.
| // @Description The optional period_start and period_end query parameters bound the period and are interpreted as UTC. They must be provided together and span at most 31 days. When both are omitted, the current budget period is used. | |
| // @Description The optional period_start and period_end query parameters bound the period and are interpreted as UTC. They must be provided together and span at most 31 days. When both are omitted, the current budget period is used, narrowed to the AI Gateway data retention window when retention is shorter than the period. An explicit period_start older than that window is rejected with 400. |
Run make gen afterwards so coderd/apidoc and the Swagger output pick up the new text.
There was a problem hiding this comment.
This will be addressed in a follow-up
Documentation CheckBlocking
Findings for agents- id: accuracy-1
persona: accuracy
class: wrong
blocking: true
file: docs/reference/api/schemas.md
line: 16975
quote: "Period end is the exclusive upper bound of the current budget period."
evidence:
- enterprise/coderd/aimodelprices.go:398-399
- enterprise/coderd/aimodelprices_test.go (ExplicitPeriodWithoutUsage)
- codersdk/aibridge.go:67-68
rule: null
problem: The response echoes an explicit caller window, so "current budget period" is false for that request.
fix: "Period end is the exclusive upper bound of the applied period." (change at codersdk/aibridge.go, then make gen)
verified: true
- id: accuracy-2
persona: accuracy
class: wrong
blocking: true
file: enterprise/coderd/aimodelprices.go
line: 354
quote: "When both are omitted, the current budget period is used."
evidence:
- enterprise/coderd/aimodelprices.go:378
- enterprise/coderd/aibridge.go:1267-1291
- enterprise/coderd/aibridge.go:1296
- codersdk/deployment.go:2012-2019
rule: null
problem: The default start is clamped to the retention window when retention is shorter than the period, and an explicit old period_start returns 400. Neither is stated.
fix: See the suggestion block on the inline comment.
verified: true
- id: audience-1
persona: audience
class: suggestion
blocking: false
file: docs/reference/api/schemas.md
line: 16942
quote: "| `model` | string"
evidence:
- codersdk/aimodelprices.go:144-160
- coderd/database/queries/aicostcontrol.sql:779-822
- docs/ai-governance/ai-gateway/cost-controls.md:222
rule: null
problem: The model, provider_name, and provider_type rows have no description, so a reader cannot tell the model is the requested one.
fix: Add field comments in codersdk/aimodelprices.go, then make gen.
verified: true
- id: learner-1
persona: learner
class: wrong
blocking: true
merged_into: accuracy-1
- id: consistency-1
persona: consistency
class: suggestion
blocking: false
merged_into: accuracy-1Automated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong. |
|
|
||
| // Only roles that can read the organization's prices can list its | ||
| // unpriced models. | ||
| t.Run("RoleAccess", func(t *testing.T) { |
There was a problem hiding this comment.
I like this personally. Just asking based on codebase patterns. Should this be tested in dbauthz instead?
There was a problem hiding this comment.
dbauthz already checks the query asks for ResourceAiModelPrice.InOrg(org) and roles_test covers which roles have it. This test covers the endpoint wiring: the handler's 403 and the 404 for another org's admin. It follows the other AI spend endpoints.
Description
Adds the experimental
GET /api/experimental/organizations/{organization}/ai/model-prices/unpricedendpoint behind the "N models not set up" warning on the organization AI spend page (Figma). It lists the models used in the period that still hold no price in the organization, using the query from this stack.Changes
organizationUnpricedAIModelshandler andExperimentalClient.OrganizationUnpricedAIModels:aiSpendRetainedPeriod, since token usage is subject to data retention.count, andmodels(provider name, display name, icon and type, model, token count), most unpriced tokens first.Note: pagination will be added in a follow-up.
Closes AIGOV-730
Note
Generated by Coder Agents on behalf of @ssncferreira.