fix(provider): list models in one page for Anthropic and Gemini

Model discovery used each API's default page size: 20 for Anthropic and
50 for Gemini. A full catalog needed several sequential requests, and at
pod start that overran the 5s warm-fill budget. One replica then
logged "initial discovery ... context deadline exceeded" and went
without that provider's models until the next probe. Every page now
asks for the documented maximum of 1000: Anthropic limit and Gemini
pageSize. Gemini gets pageSize on each page, because it requires the
same parameters across one listing.

Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
2026-09-23 13:46:11 +01:00
parent 28722d983f
commit 8ac20d8d5e
4 changed files with 45 additions and 9 deletions
+12 -2
View File
@@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
@@ -386,6 +387,13 @@ type geminiModelsListPayload struct {
// provider.
const geminiListModelsPageCap = 20
// geminiListModelsPageSize is the pageSize sent on every models.list page:
// the documented maximum (default 50, at most 1000 per page). Gemini
// requires the same parameters on every page of one listing, so it is sent
// with the pageToken too. One request at the maximum returns the whole
// catalog within registry.go's warmFillTimeout.
const geminiListModelsPageSize = 1000
// listModels implements providerAdapter: GET {base}/v1beta/models,
// stripping the "models/" prefix off each entry's "name" to return bare
// model ids, matching the shape openai-type and anthropic-type adapters
@@ -414,10 +422,12 @@ func (a *geminiAdapter) listModels(ctx context.Context) ([]string, error) {
// model ids alongside nextPageToken for listModels' own pagination loop
// above.
func (a *geminiAdapter) listModelsPage(ctx context.Context, pageToken string) (ids []string, nextPageToken string, err error) {
endpoint := a.baseURL + "/v1beta/models"
query := url.Values{}
query.Set("pageSize", strconv.Itoa(geminiListModelsPageSize))
if pageToken != "" {
endpoint += "?pageToken=" + url.QueryEscape(pageToken)
query.Set("pageToken", pageToken)
}
endpoint := a.baseURL + "/v1beta/models?" + query.Encode()
resp, err := upstreamJSON(ctx, a.client, http.MethodGet, endpoint, a.requestHeaders(false), nil, a.retry, a.timeout, a.adapterName)
if err != nil {
return nil, "", err