siyuan-note/siyuan · error
image prompt is required
Error message
image prompt is required
What it means
Thrown by OpenAIImageAdapter.Generate (kernel/util/openai.go:735) when strings.TrimSpace(request.Prompt) is empty. It is the input-contract guard at the very top of Generate and exists because the OpenAI image API rejects empty prompts with a less obvious upstream error; SiYuan fails fast with a clear message instead.
Source
Thrown at kernel/util/openai.go:735
return "", "", errors.New("generated image is invalid")
}
return mimeType, extension, nil
}
func NewOpenAIImageAdapter(apiKey, apiBaseURL, model string, timeout int) *OpenAIImageAdapter {
if timeout < 1 {
timeout = 30
}
return &OpenAIImageAdapter{
client: NewOpenAIClientWithModel(apiKey, apiBaseURL, model),
model: model,
timeout: time.Duration(timeout) * time.Second,
}
}
func (adapter *OpenAIImageAdapter) Generate(ctx context.Context, request GenerateImageRequest) (GeneratedImage, error) {
if strings.TrimSpace(request.Prompt) == "" {
return GeneratedImage{}, errors.New("image prompt is required")
}
imageRequest := openai.ImageRequest{
Prompt: request.Prompt,
Model: adapter.model,
N: 1,
Size: request.Size,
Quality: request.Quality,
}
if strings.HasPrefix(strings.ToLower(adapter.model), "dall-e") {
imageRequest.ResponseFormat = openai.CreateImageResponseFormatB64JSON
if imageRequest.Quality == "auto" {
imageRequest.Quality = ""
}
} else {
imageRequest.OutputFormat = request.OutputFormat
}
requestCtx, cancel := context.WithTimeout(ctx, adapter.timeout)
defer cancel()View on GitHub (pinned to 251596fc0d)
Solutions
- Validate the prompt at the calling layer (HTTP handler, agent runtime) before invoking Generate, returning a user-facing message.
- Trim and reject prompt == '' on the UI side so the call is never made.
- If an automation pipeline triggers it, audit the prompt construction step.
Example fix
// before
img, err := adapter.Generate(ctx, GenerateImageRequest{Prompt: req.Prompt, Size: req.Size})
// after
prompt := strings.TrimSpace(req.Prompt)
if prompt == "" {
return nil, errors.New("prompt is required")
}
img, err := adapter.Generate(ctx, GenerateImageRequest{Prompt: prompt, Size: req.Size}) Defensive patterns
Strategy: validation
Validate before calling
prompt := strings.TrimSpace(request.Prompt)
if prompt == "" {
return errors.New("image prompt is required")
}
request.Prompt = prompt Try / catch
img, err := adapter.Generate(ctx, request)
if err != nil && err.Error() == "image prompt is required" {
// surface to user as a form-validation issue, not a system error
return promptRequiredError{}
}
if err != nil { return err } Prevention
- Trim and reject empty prompts in the HTTP/agent layer before calling Generate.
- Disable submit until a non-empty prompt is entered in the UI.
- In automation pipelines, assert prompt construction produces non-empty output before dispatch.
When it happens
Trigger: Calling adapter.Generate with a GenerateImageRequest whose Prompt is "", whitespace-only, or accidentally unset (zero value of the struct).
Common situations: Frontend sends the request before the user typed a prompt; an agent/automation pipeline forwards an empty prompt field; a serialization bug drops the prompt key; default struct zero value used unintentionally.
Related errors
- generated image is empty
- generated image exceeds size limit
- unsupported generated image type: %s
- generated image is invalid
- image model returned no image
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/b03f7677580db928.
Report an issue: GitHub.