Page the gateway's Anthropic models listing - #681
Open
moomindani wants to merge 1 commit into
Open
moomindani wants to merge 1 commit into
moomindani wants to merge 1 commit into
Conversation
`GET /ai-gateway/anthropic/v1/models` implements Anthropic's cursor pagination — `limit` (20 by default, 1000 at most), `after_id`, `has_more` — but discovery read it once with no `limit` and ignored `has_more`. On a workspace advertising more models than one default page holds, every model after the first page was invisible to `ug configure`, the model pickers, and `discover_claude_models`. Walk the pages instead, asking for the documented maximum `limit`. The cursor is the last id in `data`: the response's `last_id` is documented as the `after_id` for the next page, but the gateway leaves it null even when it sets `has_more`, so a walk that trusted it would stall after one page. A repeated cursor stops the walk, and a failure mid-walk keeps what was collected — the same shape as the model-services walk. Verified against a live workspace: 9 models at the default page size, and the same 9 when the page size is forced to 2 so the gateway actually paginates (5 pages). The single unpaged read at that page size sees 2 of the 9. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
GET /ai-gateway/anthropic/v1/modelsimplements Anthropic's cursor pagination —limit(20 by default, 1000 at most),
after_id,has_more. Discovery read it once with nolimitand ignoredhas_more, so on a workspace that advertises more models than onedefault page holds, every model after the first page was invisible to
ug configure, themodel pickers, and
discover_claude_models.This walks the pages, asking for the documented maximum
limit. The cursor is the last idin
data: the response'slast_idis documented as theafter_idfor the next page, butthe gateway leaves it null even when it sets
has_more(#680), so a walk that trusted itwould stall after one page. A repeated cursor stops the walk, and a failure mid-walk keeps
what was collected — the same shape as the model-services and model-provider-service walks
in the same module.
Verification
Unit tests (
tests/test_databricks.py, 6 added): multi-page collection, a family that onlyappears on a later page,
last_idused as the cursor when the gateway sends one, a repeatedcursor stopping the walk, a mid-walk failure keeping what was collected, and a first-page
failure surfacing the reason. The four paging tests fail on the unpatched code
(
assert ['a'] == ['a', 'b']) and pass with it.Against a live workspace advertising 9 Anthropic models:
has_more: true,last_id: nulluv run pytest tests/test_databricks.py— 276 passed.uv run ruff check .— clean.The 8 failures in the wider suite (
test_claude_smart_routing_v2.py,test_codex_smart_routing_v2.py,test_e2e_user_agent.py) reproduce on an unmodifiedmainand are unrelated.This pull request and its description were written by Isaac.