Skip to content

feat: paginate the organization unpriced AI models endpoint - #32170

Merged
ssncferreira merged 4 commits into
mainfrom
ssncf/unpriced-models-pagination
Nov 20, 2026
Merged

ssncferreira merged 4 commits into
mainfrom
ssncf/unpriced-models-pagination

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Paginates the experimental GET /api/experimental/organizations/{organization}/ai/model-prices/unpriced endpoint from #31753. The list is keyed by the requested model, which clients set, so it has no upper bound.

Changes

  • GetUnpricedAIModels takes limit_opt and offset_opt, and each row carries the count of every model. A zero limit returns every model, so the unpriced models notification is unchanged.
  • The endpoint reads limit and offset with parseOrganizationAISpendPage (default 10, maximum 100), as the other AI spend endpoints do.
  • count is now the number of models over every page.
  • ExperimentalClient.OrganizationUnpricedAIModels takes an OrganizationAISpendPage.
  • Add query and handler tests for pagination.

Related to AIGOV-730

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Nov 13, 2026

Copy link
Copy Markdown

AIGOV-730

@ssncferreira
ssncferreira temporarily deployed to docs-preview November 13, 2026 12:41 — with GitHub Actions Inactive
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 3496ae0 to 985e9b4 Compare November 13, 2026 12:49
@ssncferreira
ssncferreira temporarily deployed to docs-preview November 13, 2026 12:52 — with GitHub Actions Inactive
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 985e9b4 to 6c56899 Compare November 13, 2026 13:08
@ssncferreira
ssncferreira temporarily deployed to docs-preview November 13, 2026 13:11 — with GitHub Actions Inactive
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 6c56899 to 177604e Compare November 13, 2026 13:21
@ssncferreira
ssncferreira temporarily deployed to docs-preview November 13, 2026 13:24 — with GitHub Actions Inactive
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 177604e to 7c23f24 Compare November 17, 2026 14:53
Base automatically changed from ssncf/unpriced-models-endpoint to main November 17, 2026 15:34
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 7c23f24 to 158c358 Compare November 17, 2026 15:34
@ssncferreira
ssncferreira temporarily deployed to main November 17, 2026 15:34 — with GitHub Actions Inactive
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 158c358 to a633cc3 Compare November 19, 2026 09:52
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from a633cc3 to b33ae60 Compare November 19, 2026 11:12
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from b33ae60 to 64005e8 Compare November 19, 2026 11:23
@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-models-pagination branch from 64005e8 to 62994d7 Compare November 19, 2026 11:26

@pawbana pawbana 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, one small non important nit.

}, got)
})

t.Run("Pagination", func(t *testing.T) {

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.

nit+: This is tested in querier so I don't think it must be tested here but on API layer I think there is no test that shows limit working. Here there only 2 models with offset 1, non working limit in theory could still pass as there is no 3rd model that could be potentially returned.
Another test without offset and limit 1 would cover it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 👍

Comment thread enterprise/coderd/aimodelprices.go Outdated
Models: slice.List(rows, db2sdk.UnpricedAIModel),
}
if len(rows) > 0 {
resp.Count = rows[0].Count

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.

When offset >= number of rows no rows are returned and Count will not be set.
Running the query agains with limit:1 offset: 0 would get this count.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I had it like that at first, but removed it because other paginated endpoints (users, members, groups) return a count of 0 for a page past the end. However, some AI spend endpoints already keep the count on every page, so I added it back to stay consistent with them.

}, got)
})

t.Run("Validation", func(t *testing.T) {

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.

nit: test case for invalid limit value could be added, I think limit <= 0 / limit > 100

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a draft PR that adds tests for the shared pagination helper: #32168. That way, the limit validation is tested once there, and the endpoints don't need duplicate tests. Will update it to include this endpoint once this is merged.

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

Few nits and one Q/suggestion 👍

Comment thread enterprise/coderd/aimodelprices.go Resolved
Comment thread enterprise/coderd/aimodelprices.go Resolved

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

One more nit below. Also, my earlier "Request changes" was meant as a Comment. The count fallback is the only thing I'd like fixed before merge; the rest are nits. I'll approve once that's in.

{
name: "UnknownParameter",
params: map[string]string{"limit": "10"},
params: map[string]string{"model": "model-without-price"},

@mollymaefraser mollymaefraser Nov 19, 2026 •

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.

Nit: now that the endpoint accepts limit and offset, could we add a case for a limit that's out of range, e.g. {"limit": "101"} (or "0"), expecting Query parameters have invalid values.?

parseOrganizationAISpendPage is shared and tested elsewhere, so this is a cheap guard. If the endpoint is later wired to a different parser or loses its maximum, this test would catch it. (Same idea as @pawbana's nit above, so one change covers both.)

@ssncferreira ssncferreira Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a draft PR that adds tests for the shared pagination helper: #32168. That way the limit validation is tested once there, and the endpoints don't need duplicate tests. Will update it to include this endpoint once this is merged.

@mollymaefraser mollymaefraser 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!! Thanks for addressing the comments 🚀

@ssncferreira
ssncferreira merged commit 13381e3 into main Nov 20, 2026
33 of 34 checks passed
@ssncferreira
ssncferreira deleted the ssncf/unpriced-models-pagination branch November 20, 2026 17:48
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
docs-preview — bfa6747c Deployed Nov 20, 2026 by ssncferreira via cleanup #297
main — bfa6747c Deployed Nov 20, 2026 by ssncferreira via cla #261453
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.

3 participants