siyuan-note/siyuan · error

download generated image failed with status

Error message

download generated image failed with status %d

What it means

When the image download request completes but the server answers with a status outside 200–299, the adapter wraps the status code into this error via fmt.Errorf. It means the URL was valid and HTTPS-checked but the actual HTTP GET failed (404, 403, 5xx, etc.).

Solutions

  1. Retry the download promptly after generation before the signed URL expires
  2. Check the status code in the error: 404/403 → URL expiry or auth; 429 → back off and retry; 5xx → provider issue, retry later
  3. Remove/fix proxy environment variables (HTTP_PROXY/HTTPS_PROXY) if they break the download
  4. Call the generation API again to obtain a fresh URL

Example fix

// before
url, _ := genImage(ctx, prompt)
time.Sleep(10 * time.Minute) // signed URL expired -> 403/404
data, err := downloadGeneratedImage(ctx, url)
// after
url, _ := genImage(ctx, prompt)
data, err := downloadGeneratedImage(ctx, url) // download immediately
Defensive patterns

Strategy: retry

Validate before calling

u, err := url.Parse(rawURL)
if err != nil || u.Scheme != "https" { return err } // cheap pre-check before the request

Try / catch

var sErr *statusErr
if errors.As(err, &sErr) && (sErr.code == 429 || sErr.code >= 500) {
    // retry with backoff
}

Prevention

When it happens

Trigger: GET on the provider-returned image URL returns 404 (expired signed URL), 403 (missing auth/hotlink protection), 429 (rate limit), or 5xx from the CDN.

Common situations: Signed image URLs expire within minutes and the app downloads too late; CDN blocks requests without a browser-like User-Agent; proxy environment (http_proxy) intercepts the request; transient CDN 5xx.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/981608f5a6ef4a2c. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai.go:946

	parsed, err := url.Parse(rawURL)
	if err != nil || parsed.Scheme != "https" || parsed.Host == "" {
		return nil, errors.New("generated image URL must use HTTPS")
	}
	if err = CheckHostSSRF(parsed.Hostname()); err != nil {
		return nil, err
	}
	client := generatedImageHTTPClient()
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil)
	if err != nil {
		return nil, err
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, fmt.Errorf("download generated image failed with status %d", resp.StatusCode)
	}
	if resp.ContentLength > maxGeneratedImageBytes {
		return nil, errors.New("generated image exceeds size limit")
	}
	data, err := io.ReadAll(io.LimitReader(resp.Body, maxGeneratedImageBytes+1))
	if err != nil {
		return nil, err
	}
	if len(data) > maxGeneratedImageBytes {
		return nil, errors.New("generated image exceeds size limit")
	}
	return data, nil
}

func generatedImageHTTPClient() *http.Client {
	return &http.Client{
		Transport: &http.Transport{
			Proxy:       httpclient.ProxyFromEnvironment,

View on GitHub (pinned to 9f775e8a12)