{"record":{"id":"9df80e1eff73cbc7","repo":"HeyPuter/puter","slug":"bad-request-9df80e","errorCode":"bad_request","errorMessage":"${providerLabel} supports only a single input image; pass one image via input_image or a single-element input_images.","messagePattern":"(.+?) supports only a single input image; pass one image via input_image or a single-element input_images\\.","errorType":"http","errorClass":"HttpError","httpStatus":400,"severity":"error","filePath":"src/backend/drivers/ai-image/inputImage.ts","lineNumber":48,"sourceCode":"import { secureFetch } from '../../util/secureHttp.js';\nimport type { IGenerateParams } from './types.js';\n\nexport function isHttpUrl(s: string): boolean {\n    return s.startsWith('http://') || s.startsWith('https://');\n}\n\n/**\n * Resolve the single input image for providers that only support one.\n * Throws 400 if `input_images` carries more than one entry. Returns the\n * chosen image string (URL / data-URI / raw base64) or undefined.\n */\nexport function resolveSingleInputImage(\n    params: Pick<IGenerateParams, 'input_image' | 'input_images'>,\n    providerLabel: string,\n): string | undefined {\n    const imgs = params.input_images;\n    if (imgs && imgs.length > 1) {\n        throw new HttpError(\n            400,\n            `${providerLabel} supports only a single input image; pass one image via input_image or a single-element input_images.`,\n            { legacyCode: 'bad_request' },\n        );\n    }\n    return params.input_image ?? imgs?.[0];\n}\n\nconst DATA_URI_PATTERN = /^data:([^;,]+)?(?:;base64)?,(.*)$/s;\n\n/** Parse a `data:<mime>;base64,<payload>` URI into raw base64 + mime. */\nexport function parseDataUri(\n    s: string,\n): { base64: string; mime: string } | null {\n    const m = DATA_URI_PATTERN.exec(s);\n    if (!m) return null;\n    return { base64: m[2] ?? '', mime: m[1] ?? 'image/png' };\n}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-image/inputImage.ts#L30-L66","documentation":"resolveSingleInputImage enforces that providers which only accept one input image (Cloudflare, and others using this helper) get at most one. If params.input_images is an array with length > 1, it throws HTTP 400 bad_request naming the providerLabel. Use input_image (single) or a single-element input_images array instead.","triggerScenarios":"An image-editing/generation call to a single-image provider passes input_images with two or more entries.","commonSituations":"App built for a multi-image provider reused against Cloudflare/other single-image provider; UI that always collects an array of reference images; batch logic that forwards many thumbnails.","solutions":["Pass exactly one image via input_image or input_images: [img].","Switch to a provider that supports multiple input images if you need them.","Validate input length before the call based on the target provider's capability."],"exampleFix":"// before\nawait driver.generate({ prompt, provider: 'cloudflare', input_images: [a, b] });\n// after\nawait driver.generate({ prompt, provider: 'cloudflare', input_image: a });","handlingStrategy":"validation","validationCode":"if (Array.isArray(args.input_images) && args.input_images.length > 1 && isSingleImageProvider(provider)) {\n  throw new Error(`${provider} accepts only one input image`);\n}","typeGuard":"function isSingleInputImageBundle(p) {\n  return Array.isArray(p.input_images) ? p.input_images.length <= 1 : true;\n}","tryCatchPattern":null,"preventionTips":["For single-image providers, pass input_image or a one-element input_images.","Branch on provider capability when collecting reference images in the UI.","Validate array length before the call."],"tags":["ai-image","validation","input-images","bad-request"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}