Skip to content

List models from the provider instead of a static catalog - #68

Merged
alexey-milovidov merged 7 commits into
mainfrom
live-model-list
Nov 27, 2026
Merged

alexey-milovidov merged 7 commits into
mainfrom
live-model-list

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

supported_models and supports_model answered from a hand-maintained list of model IDs. That list went stale with every model release (keeping it current was part of #64/#67), returned false for valid models, and could not know what a given API key or a custom base_url (OpenRouter, gateways) serves. Requests never consulted it: GenerateOptions::model is forwarded to the API as is.

  • Add Client::list_models → ModelListResult. It asks the provider's models endpoint (GET /v1/models), follows Anthropic's has_more/last_id pagination, and parses errors like completion errors. It uses the same retry policy as other requests, via the new HttpRequestHandler::get.
  • supports_model is now true for every non-empty model name.
  • supported_models stays as the list of well-known names (the models::k* constants) and is documented as such, so existing callers keep compiling.
  • Unit tests run against a local httplib::Server: Anthropic pagination and headers, OpenAI's single page, provider errors, an unexpected response shape. Live integration tests for both providers. A README section.

Bedrock (#38) and the Gemini provider in progress will get their own model listing.

🤖 Generated with Claude Code


Note

Medium Risk
Changes public semantics of supports_model (may surprise callers that relied on false for unknown names) and adds networked GET/pagination on the shared HTTP path used by all HTTP providers.

Overview
Adds Client::list_models() returning ModelListResult, so callers can fetch model IDs from the provider (via HttpRequestHandler::get with the same retry path as POST) instead of relying on a hand-maintained catalog.

OpenAI and Anthropic use BaseProviderClient::list_models against /v1/models, including Anthropic has_more/last_id pagination with a guard against stuck cursors. Gemini implements its own /v1beta/models paging and strips the models/ prefix. Bedrock lists regional foundation models through ModelDiscovery.

supports_model now returns true for any non-empty model string (names are forwarded as-is); supported_models stays as documented models::k* helpers only. README, multi_provider, unit tests (local mock server), and live integration tests are updated accordingly.

Reviewed by Cursor Bugbot for commit a1010fa. Bugbot is set up for automated code reviews on this repo. Configure here.

`supported_models` and `supports_model` answered from a hand-maintained
list that went stale with every model release, returned false for valid
models, and could not know what an API key or a custom `base_url`
(OpenRouter, gateways) serves. Requests never consulted it: model names
are forwarded to the API as is.

- Add `Client::list_models`, which asks the provider's models endpoint
  (`GET /v1/models`) and follows Anthropic's `has_more`/`last_id`
  pagination; errors are parsed like completion errors. It uses the
  same retry policy as other requests (new `HttpRequestHandler::get`).
- `supports_model` is now true for every non-empty model name.
- `supported_models` stays as the list of well-known names (the
  `models::k*` constants) and is documented as such.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexey-milovidov and others added 2 commits November 27, 2026 21:41
Align the Bedrock client, merged in #38, with the rest of this change:
`list_models` returns the foundation model IDs of the Region through
`ModelDiscovery`, and `supports_model` is true for every non-empty
model ID (inference profiles and ARNs are forwarded to Converse as is).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4c476e2. Configure here.

Comment thread src/providers/base_provider_client.cpp Resolved
alexey-milovidov and others added 4 commits November 27, 2026 21:47
- Unit tests (no network): a client is created with a region, accepts any
  non-empty model ID in `supports_model` and rejects "", lists the current
  Claude models in `supported_models`, and requires a region.
- Integration test (skipped without `AI_SDK_IT_BEDROCK`): `list_models`
  returns the foundation models of the Region.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A server or gateway that ignores `after_id` and keeps answering
`has_more` with the same `last_id` made `list_models` page forever.
Report an error when a cursor comes back a second time.

Reported by Cursor Bugbot in #68

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Gemini provider, merged in #69, answers `list_models` from its own
models endpoint: it follows `nextPageToken` (failing if a token
repeats), and reports the IDs without the `models/` prefix, the way
requests take them. The request and error handling of the OpenAI and
Anthropic listing moves to `BaseProviderClient::get_json`, shared by
both implementations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexey-milovidov
alexey-milovidov merged commit 34f02e5 into main Nov 27, 2026
3 checks passed
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