Skip to content

Page the gateway's Anthropic models listing - #681

Open
moomindani wants to merge 1 commit into
databricks:mainfrom
moomindani:fix/anthropic-models-pagination
Open

moomindani wants to merge 1 commit into
databricks:mainfrom
moomindani:fix/anthropic-models-pagination

Conversation

@moomindani

Copy link
Copy Markdown

What

GET /ai-gateway/anthropic/v1/models implements Anthropic's cursor pagination — limit
(20 by default, 1000 at most), after_id, has_more. Discovery read it once with no
limit and ignored has_more, so on a workspace that advertises 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.

This walks the pages, 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 (#680), 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 and model-provider-service walks
in the same module.

Verification

Unit tests (tests/test_databricks.py, 6 added): multi-page collection, a family that only
appears on a later page, last_id used as the cursor when the gateway sends one, a repeated
cursor 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:

Page size Result
1000 (the new default) 9 models, 1 request
2, forced 9 models over 5 pages — same set, same family selection
2, single unpaged read (the old behaviour) 2 of 9, has_more: true, last_id: null

uv 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 unmodified
main and are unrelated.

This pull request and its description were written by Isaac.

`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>
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.

1 participant