jackwener/OpenCLI · error · CommandExecutionError

Failed to upload image to ChatGPT

Error message

Failed to upload image to ChatGPT

What it means

The non-exception counterpart to error 626: uploadChatGPTImages completed but returned { ok: false, reason }, and the command throws CommandExecutionError with that reason (or the generic 'Failed to upload image to ChatGPT' fallback when reason is missing). It indicates ChatGPT/the page reported the upload did not succeed.

Source

Thrown at clis/chatgpt/image.js:111

            throw new ArgumentError(preparedImages.reason);
        }

        // Navigate with full reload to clear React sidebar state before editing the draft.
        if (kwargs.project) {
            await navigateToProject(page, kwargs.project);
        } else {
            await page.goto(`https://${CHATGPT_DOMAIN}/new`, { settleMs: 2000 });
        }
        await clearChatGPTDraft(page);

        if (imagePaths.length) {
            let upload;
            try {
                upload = await uploadChatGPTImages(page, preparedImages.paths);
            } catch (err) {
                throw new CommandExecutionError(`Failed to upload image to ChatGPT: ${err instanceof Error ? err.message : String(err)}`);
            }
            if (!upload?.ok) throw new CommandExecutionError(upload?.reason || 'Failed to upload image to ChatGPT');
        }

        const beforeUrls = await getChatGPTVisibleImageUrls(page);

        // Send an explicit generation/editing prompt so ChatGPT returns image assets.
        const sent = await sendChatGPTMessage(page, buildPrompt(prompt, imagePaths.length));
        if (!sent) {
            throw new CommandExecutionError(
                'Failed to send image prompt to ChatGPT',
                `Open ${await currentChatGPTLink(page)} and verify the composer is ready.`,
            );
        }

        // ChatGPT briefly navigates to /c/{id} after sending, then may
        // redirect back to the home page. Poll until we capture the /c/ URL.
        let convUrl = '';
        for (let ci = 0; ci < 10; ci++) {
            const url = await currentChatGPTLink(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect upload?.reason in the message for the specific failure.
  2. Verify the image renders and is under ChatGPT's size limits; convert exotic formats to PNG/JPG.
  3. Retry — attachment uploads are frequently transient.
  4. Test the same upload manually in the browser to see ChatGPT's rejection message.
  5. If reason is the generic fallback repeatedly, update the library's upload/success-detection logic.

Example fix

// before
opencli chatgpt image "edit" --image ./diagram.tiff   # ChatGPT rejects format, ok:false
// after
# convert to a supported format
magick ./diagram.tiff ./diagram.png
opencli chatgpt image "edit" --image ./diagram.png
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-validate format and size before asking ChatGPT to upload
import fs from 'node:fs';
const ok = (p) => ['png','jpg','jpeg','webp','gif'].includes(p.split('.').pop().toLowerCase())
  && fs.statSync(p).size < 25 * 1024 * 1024;
if (!ok(imagePath)) throw new Error(`Unsupported or oversized image: ${imagePath}`);

Type guard

null

Try / catch

try {
  return await run('chatgpt image', prompt, '--image', imagePath);
} catch (err) {
  if (String(err.message).includes('Failed to upload image to ChatGPT')) {
    // fallback: try a converted copy of the image
    const converted = convertToPng(imagePath);
    return run('chatgpt image', prompt, '--image', converted);
  }
  throw err;
}

Prevention

When it happens

Trigger: `opencli chatgpt image "prompt" --image <path>` where uploadChatGPTImages returns upload.ok === false — e.g. the attachment chip never appeared, ChatGPT rejected the file, or the upload timed out with a structured reason. If the helper returns undefined/null, the fallback message is thrown.

Common situations: Unsupported or oversized file rejected by ChatGPT; upload progress never confirmed before the helper's internal timeout; ChatGPT rate-limiting attachments; UI change so success detection fails and reason is undefined.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/31f4ab16859560c3. Report an issue: GitHub.