Repository navigation
List models from the provider instead of a static catalog - #68
Merged
Merged
Conversation
`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>
# Conflicts: # README.md
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
- 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>
# Conflicts: # tests/CMakeLists.txt
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>
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.

supported_modelsandsupports_modelanswered from a hand-maintained list of model IDs. That list went stale with every model release (keeping it current was part of #64/#67), returnedfalsefor valid models, and could not know what a given API key or a custombase_url(OpenRouter, gateways) serves. Requests never consulted it:GenerateOptions::modelis forwarded to the API as is.Client::list_models→ModelListResult. It asks the provider's models endpoint (GET /v1/models), follows Anthropic'shas_more/last_idpagination, and parses errors like completion errors. It uses the same retry policy as other requests, via the newHttpRequestHandler::get.supports_modelis nowtruefor every non-empty model name.supported_modelsstays as the list of well-known names (themodels::k*constants) and is documented as such, so existing callers keep compiling.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()returningModelListResult, so callers can fetch model IDs from the provider (viaHttpRequestHandler::getwith the same retry path as POST) instead of relying on a hand-maintained catalog.OpenAI and Anthropic use
BaseProviderClient::list_modelsagainst/v1/models, including Anthropichas_more/last_idpagination with a guard against stuck cursors. Gemini implements its own/v1beta/modelspaging and strips themodels/prefix. Bedrock lists regional foundation models throughModelDiscovery.supports_modelnow returns true for any non-empty model string (names are forwarded as-is);supported_modelsstays as documentedmodels::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.