siyuan-note/siyuan · error

generated image exceeds size limit

Error message

generated image exceeds size limit

What it means

ValidateGeneratedImage in kernel/util/openai.go throws this when the generated image byte slice exceeds maxGeneratedImageBytes, the configured maximum size for AI-generated images. Unlike the byte-limit errors elsewhere, this message is a constant with no size values interpolated.

Solutions

  1. Lower the generation resolution or use standard (non-hd) output settings
  2. Regenerate the image with a style/composition that compresses better (less detail, JPEG-friendly)
  3. Increase the maxGeneratedImageBytes configuration if the cap is too strict
  4. Convert/re-encode the delivered image to a smaller format before storing

Example fix

// before: request maximum resolution
req := imageRequest{Size: "1792x1024", Quality: "hd"}
// after: use standard size to stay under the byte cap
req := imageRequest{Size: "1024x1024", Quality: "standard"}
Defensive patterns

Strategy: validation

Validate before calling

cfg, _, _ := image.DecodeConfig(bytes.NewReader(data))
_ = cfg
if len(data) > 8<<20 { return errors.New("requested generation would exceed size cap; lower resolution") }

Prevention

When it happens

Trigger: An AI image API returns an image larger than maxGeneratedImageBytes — e.g. high-resolution generation settings or a PNG of a detailed 2K+ image whose encoded size blows past the cap.

Common situations: Generating at maximum resolution/detailed settings with models like DALL·E or SDXL; large PNG outputs; a lowered size cap in configuration rejecting outputs that previously passed.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at kernel/util/openai.go:841

	if maxBytes > 0 && output.Len() > maxBytes {
		return PreparedImage{}, fmt.Errorf("prepared image exceeds size limit: %d bytes", maxBytes)
	}
	return PreparedImage{
		Data:       output.Bytes(),
		MIMEType:   "image/jpeg",
		Width:      bounds.Dx(),
		Height:     bounds.Dy(),
		SourceSize: len(data),
	}, nil
}

// ValidateGeneratedImage 校验生成图片的格式、尺寸和体积。
func ValidateGeneratedImage(data []byte) (mimeType, extension string, err error) {
	if len(data) == 0 {
		return "", "", errors.New("generated image is empty")
	}
	if len(data) > maxGeneratedImageBytes {
		return "", "", errors.New("generated image exceeds size limit")
	}
	mimeType = mimetype.Detect(data).String()
	switch mimeType {
	case "image/png":
		extension = ".png"
	case "image/jpeg":
		extension = ".jpg"
	case "image/webp":
		extension = ".webp"
	default:
		return "", "", fmt.Errorf("unsupported generated image type: %s", mimeType)
	}
	config, _, decodeErr := image.DecodeConfig(bytes.NewReader(data))
	if decodeErr != nil || config.Width < 1 || config.Height < 1 || config.Width > 16384 || config.Height > 16384 ||
		int64(config.Width)*int64(config.Height) > maxGeneratedImagePixels {
		return "", "", errors.New("generated image is invalid")
	}
	return mimeType, extension, nil

View on GitHub (pinned to 9f775e8a12)