siyuan-note/siyuan · error
list models HTTP %d
Error message
list models HTTP %d
What it means
ListAvailableModelsWithContext reads up to 64KB of an error response body to enrich the message. When the provider returns a non-2xx status AND reading that body itself fails (connection reset, mid-stream EOF, TLS close mid-read), the error degrades to this status-code-only form without the upstream reason.
Source
Thrown at kernel/util/openai.go:358
endpoint := strings.TrimRight(apiBaseURL, "/") + "/models"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
if apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
resp, err := httpclient.NewUserAgentClient(nil).Do(req)
if err != nil {
logging.LogErrorf("list models [%s] failed: %s", apiBaseURL, err)
return
}
defer resp.Body.Close()
if resp.StatusCode < http.StatusOK || http.StatusBadRequest <= resp.StatusCode {
body, readErr := io.ReadAll(io.LimitReader(resp.Body, 64*1024))
if readErr != nil {
err = fmt.Errorf("list models HTTP %d", resp.StatusCode)
} else {
err = fmt.Errorf("list models HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
}
logging.LogErrorf("list models [%s] failed: %s", apiBaseURL, err)
return
}
payload := &availableModelsPayload{}
if err = json.NewDecoder(resp.Body).Decode(payload); err != nil {
logging.LogErrorf("decode models [%s] failed: %s", apiBaseURL, err)
return
}
for _, item := range payload.Data {
id := strings.TrimSpace(item.ID)
if id == "" {
continue
}
models = append(models, AvailableModel{View on GitHub (pinned to 251596fc0d)
Solutions
- Retry the model-list request once; transient body-read failures usually clear.
- Verify network/proxy stability to the provider.
- If persistent, curl the /models endpoint manually to see the real status and body.
- Confirm apiBaseURL correctness (OpenAI-compatible providers need /v1).
Defensive patterns
Strategy: retry
Validate before calling
var lastErr error
for i := 0; i < 2; i++ {
models, lastErr = util.ListAvailableModelsWithContext(apiKey, base, 30)
if lastErr == nil { break }
if !util.IsNetworkError(lastErr) { break }
} Try / catch
models, err := util.ListAvailableModelsWithContext(key, base, 30)
if err != nil && util.IsNetworkError(err) {
// retry once, then surface to the user
} Prevention
- Retry transient body-read failures
- Validate apiBaseURL format before listing
- Use a stable network path to the provider
When it happens
Trigger: Provider returns 4xx/5xx on GET /models and then the connection drops before the body can be fully read; intermediary (proxy/CDN) closes an idle connection mid-response.
Common situations: Flaky upstream; upstream that sends headers then RST; aggressive proxy/CDN timeout; transient network blip during the models probe.
Related errors
- list models HTTP %d: %s
- rerank HTTP %d: %s
- download generated image failed with status %d
- bazaar is offline
- get bazaar package failed, please check your network
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/7654be772a6b59c8.
Report an issue: GitHub.