fix: respect API base when listing Anthropic models (#151)

This commit is contained in:
pdtkts
2026-03-11 16:55:11 +07:00
committed by GitHub
parent 4f3664674b
commit 44e5d663af
+7 -3
View File
@@ -57,7 +57,7 @@ func (h *ProvidersHandler) handleListProviderModels(w http.ResponseWriter, r *ht
switch p.ProviderType {
case "anthropic_native":
models, err = fetchAnthropicModels(ctx, p.APIKey)
models, err = fetchAnthropicModels(ctx, p.APIKey, p.APIBase)
case "gemini_native":
models, err = fetchGeminiModels(ctx, p.APIKey)
case "bailian":
@@ -88,8 +88,12 @@ func (h *ProvidersHandler) handleListProviderModels(w http.ResponseWriter, r *ht
}
// fetchAnthropicModels calls the Anthropic models API.
func fetchAnthropicModels(ctx context.Context, apiKey string) ([]ModelInfo, error) {
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.anthropic.com/v1/models", nil)
func fetchAnthropicModels(ctx context.Context, apiKey, apiBase string) ([]ModelInfo, error) {
base := strings.TrimRight(apiBase, "/")
if base == "" {
base = "https://api.anthropic.com/v1"
}
req, err := http.NewRequestWithContext(ctx, "GET", base+"/models", nil)
if err != nil {
return nil, err
}