HeyPuter/puter · error · HttpError
bad_request
bad_request
Error message
`prompt` must be a non-empty string
What it means
CloudflareImageProvider.generate requires a prompt that is a string and non-empty after trim; anything else (undefined, number, empty, whitespace-only) throws HTTP 400 bad_request before doing any work or spending credits.
Source
Thrown at src/backend/drivers/ai-image/providers/cloudflare/CloudflareImageProvider.ts:97
return CLOUDFLARE_IMAGE_GENERATION_MODELS;
}
getDefaultModel(): string {
return DEFAULT_MODEL;
}
async generate(params: IGenerateParams): Promise<string> {
const options = params as CloudflareGenerateParams;
const { prompt, test_mode } = options;
const ratio = this.#normalizeRatio(options.ratio);
const selectedModel = this.#getModel(options.model);
if (test_mode) {
return 'https://puter-sample-data.puter.site/image_example.png';
}
if (typeof prompt !== 'string' || prompt.trim().length === 0) {
throw new HttpError(400, '`prompt` must be a non-empty string', {
legacyCode: 'bad_request',
});
}
const actor = Context.get('actor');
if (!actor) {
throw new HttpError(401, 'actor not found in context', {
legacyCode: 'unauthorized',
});
}
// Canonical `input_images`/`input_image` → Cloudflare's `image` field.
// Cloudflare accepts a single input image; a URL is fetched to base64
// server-side (SSRF-guarded) since the API has no URL field.
const singleInput = resolveSingleInputImage(options, 'Cloudflare');
if (singleInput) {
options.image ??= isHttpUrl(singleInput)
? (await fetchImageAsBase64(singleInput)).base64View on GitHub (pinned to 908ec23eda)
Solutions
- Ensure prompt is a non-empty trimmed string before calling generate().
- Disable the submit UI until a prompt is entered.
- Type-check/guard prompt at the call site.
Example fix
// before
await provider.generate({ prompt: '' });
// after
if (typeof prompt !== 'string' || prompt.trim().length === 0) throw new Error('prompt required');
await provider.generate({ prompt }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof prompt !== 'string' || prompt.trim().length === 0) {
throw new Error('prompt must be a non-empty string');
} Type guard
function isNonEmptyPrompt(p) {
return typeof p === 'string' && p.trim().length > 0;
} Prevention
- Disable the submit action until a non-empty prompt is entered.
- Type-check prompt at the call site.
- Strip and validate before passing to generate().
When it happens
Trigger: Calling Cloudflare image generation with no prompt, an empty prompt, or a non-string prompt (e.g. passing an object or number by mistake).
Common situations: UI submitting before the user typed a prompt; variable not initialized; prompt built from an empty template field.
Related errors
AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12).
Data as JSON: /api/errors/520ada0320ff5b82.
Report an issue: GitHub.