{"record":{"id":"b21186ee8508e8b9","repo":"siyuan-note/siyuan","slug":"generated-image-exceeds-size-limit","errorCode":null,"errorMessage":"generated image exceeds size limit","messagePattern":"generated image exceeds size limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":841,"sourceCode":"\tif maxBytes > 0 && output.Len() > maxBytes {\n\t\treturn PreparedImage{}, fmt.Errorf(\"prepared image exceeds size limit: %d bytes\", maxBytes)\n\t}\n\treturn PreparedImage{\n\t\tData:       output.Bytes(),\n\t\tMIMEType:   \"image/jpeg\",\n\t\tWidth:      bounds.Dx(),\n\t\tHeight:     bounds.Dy(),\n\t\tSourceSize: len(data),\n\t}, nil\n}\n\n// ValidateGeneratedImage 校验生成图片的格式、尺寸和体积。\nfunc ValidateGeneratedImage(data []byte) (mimeType, extension string, err error) {\n\tif len(data) == 0 {\n\t\treturn \"\", \"\", errors.New(\"generated image is empty\")\n\t}\n\tif len(data) > maxGeneratedImageBytes {\n\t\treturn \"\", \"\", errors.New(\"generated image exceeds size limit\")\n\t}\n\tmimeType = mimetype.Detect(data).String()\n\tswitch mimeType {\n\tcase \"image/png\":\n\t\textension = \".png\"\n\tcase \"image/jpeg\":\n\t\textension = \".jpg\"\n\tcase \"image/webp\":\n\t\textension = \".webp\"\n\tdefault:\n\t\treturn \"\", \"\", fmt.Errorf(\"unsupported generated image type: %s\", mimeType)\n\t}\n\tconfig, _, decodeErr := image.DecodeConfig(bytes.NewReader(data))\n\tif decodeErr != nil || config.Width < 1 || config.Height < 1 || config.Width > 16384 || config.Height > 16384 ||\n\t\tint64(config.Width)*int64(config.Height) > maxGeneratedImagePixels {\n\t\treturn \"\", \"\", errors.New(\"generated image is invalid\")\n\t}\n\treturn mimeType, extension, nil","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L823-L859","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Lower the generation resolution or use standard (non-hd) output settings","Regenerate the image with a style/composition that compresses better (less detail, JPEG-friendly)","Increase the maxGeneratedImageBytes configuration if the cap is too strict","Convert/re-encode the delivered image to a smaller format before storing"],"exampleFix":"// before: request maximum resolution\nreq := imageRequest{Size: \"1792x1024\", Quality: \"hd\"}\n// after: use standard size to stay under the byte cap\nreq := imageRequest{Size: \"1024x1024\", Quality: \"standard\"}","handlingStrategy":"validation","validationCode":"cfg, _, _ := image.DecodeConfig(bytes.NewReader(data))\n_ = cfg\nif len(data) > 8<<20 { return errors.New(\"requested generation would exceed size cap; lower resolution\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer standard quality/resolution settings over hd/high for generated images","Know your maxGeneratedImageBytes value and pick model size parameters accordingly","Watch PNG outputs of detailed images — they inflate fast; prefer JPEG output when offered","Raise the cap only if storage/display constraints actually allow it"],"tags":["image","size-limit","ai","generated-content"],"backgroundTag":"payload-too-large","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}