siyuan-note/siyuan · error
MiniMax image dimensions must be positive integers
Error message
MiniMax image dimensions must be positive integers
What it means
After splitting input.Size on "x" and confirming two parts, the transport converts both with strconv.Atoi and requires successful parses and strictly positive values. Non-numeric parts, negatives, or zero are rejected because MiniMax's width/height API fields must be positive integers.
Solutions
- Pass plain decimal positive integers: "1024x768" — no units, decimals, signs, or separators
- Sanitize the size string before the call: trim spaces, strip "px", parse with strconv.Atoi yourself and clamp to > 0
- Validate at config/UI entry time so invalid sizes never reach the request
- Fall back to "" (default 1:1 aspect ratio) when the value cannot be parsed into positive integers
Example fix
// before
size := "1024px x 768px"
// after
size = strings.NewReplacer("px", "", " ", "").Replace(size)
w, err1 := strconv.Atoi(strings.SplitN(size, "x", 2)[0])
h, err2 := strconv.Atoi(strings.SplitN(size, "x", 2)[1])
if err1 != nil || err2 != nil || w <= 0 || h <= 0 {
size = "" // default 1:1
} Defensive patterns
Strategy: validation
Validate before calling
parts := strings.Split(size, "x")
if len(parts) == 2 {
w, e1 := strconv.Atoi(strings.TrimSpace(parts[0]))
h, e2 := strconv.Atoi(strings.TrimSpace(parts[1]))
if e1 != nil || e2 != nil || w <= 0 || h <= 0 { size = "" }
} Try / catch
if err != nil && strings.Contains(err.Error(), "must be positive integers") {
return nil, fmt.Errorf("reject image size %q: use positive integer WxH like 1024x768", size)
} Prevention
- Sanitize size inputs: trim whitespace, strip units like px, reject floats and signs
- Clamp or reject zero/negative dimensions at UI/config entry time
- Use a shared size parser for all AI image providers so formats stay consistent
- Default to "" (1:1 aspect ratio) whenever parsed dimensions fail validation
When it happens
Trigger: Requesting a MiniMax image with size like "abcx1024", "0x0", "-100x100", "1024.5x768" (float string), or a size containing whitespace/units such as "1024pxx768px".
Common situations: Sizes copied from CSS or px-suffixed values; user-entered config values never sanitized; zero/negative dimensions from broken template defaults; locale-formatted numbers with separators like "1,024x768".
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- MiniMax image size must be WIDTHxHEIGHT
- MiniMax image generation failed
- MiniMax image model returned no image
- MiniMax image request failed with HTTP status
- 346
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1fbc2a9e2e96ab3d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/minimax_image.go:75
req.Body.Close()
if err != nil {
return nil, err
}
payload := map[string]any{
"model": input.Model, "prompt": input.Prompt, "n": input.N,
"response_format": "url", "prompt_optimizer": true,
}
if input.Size == "" || input.Size == "auto" {
payload["aspect_ratio"] = "1:1"
} else {
dimensions := strings.Split(input.Size, "x")
if len(dimensions) != 2 {
return nil, errors.New("MiniMax image size must be WIDTHxHEIGHT")
}
width, widthErr := strconv.Atoi(dimensions[0])
height, heightErr := strconv.Atoi(dimensions[1])
if widthErr != nil || heightErr != nil || width <= 0 || height <= 0 {
return nil, errors.New("MiniMax image dimensions must be positive integers")
}
payload["width"], payload["height"] = width, height
}
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
converted := req.Clone(req.Context())
converted.URL.Path = strings.TrimSuffix(req.URL.Path, "/images/generations") + "/image_generation"
converted.URL.RawPath = ""
converted.Body = io.NopCloser(bytes.NewReader(body))
converted.ContentLength = int64(len(body))
converted.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(body)), nil }
resp, err := t.base.Do(converted)
if err != nil {
return nil, err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {View on GitHub (pinned to 9f775e8a12)