jackwener/OpenCLI · error · CommandExecutionError

Failed to send image prompt to ChatGPT

Error message

Failed to send image prompt to ChatGPT

What it means

After uploading attachments (if any), the command sends the prompt via sendChatGPTMessage; if it returns falsy, the composer submit did not register and the command throws CommandExecutionError('Failed to send image prompt to ChatGPT') with remediation pointing at the current conversation URL. It guards against silently generating nothing.

Source

Thrown at clis/chatgpt/image.js:119

        }
        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);
            if (url.includes('/c/')) { convUrl = url; break; }
            await page.sleep(2);
        }
        if (!convUrl) {
            convUrl = await currentChatGPTLink(page);
        }

        const urls = await waitForChatGPTImages(page, beforeUrls, timeout, convUrl);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Follow the error's hint: open the printed URL and verify the composer works manually.
  2. Retry — first-load hydration races commonly cause a one-off failure.
  3. Re-login / refresh the session cookie, then retry.
  4. Clear any leftover draft/dialog state in the persistent browser profile.
  5. If it never sends, the composer selectors changed — update the library.

Example fix

// before
opencli chatgpt image "a lighthouse"   # sends immediately after goto with 2s settle
// after
# warm up the page first in the persistent session, then retry
opencli chatgpt image "a lighthouse"   # second attempt after composer confirmed ready
Defensive patterns

Strategy: retry

Validate before calling

// Verify the session is logged in and the composer is usable before sending
await run('chatgpt history', '--limit', '1'); // throws/logs if the session is dead

Type guard

null

Try / catch

async function sendWithRetry(prompt, attempt = 0) {
  try {
    return await run('chatgpt image', prompt);
  } catch (err) {
    if (String(err.message).includes('Failed to send image prompt to ChatGPT') && attempt < 2) {
      await sleep(20_000 * (attempt + 1));
      return sendWithRetry(prompt, attempt + 1);
    }
    throw err;
  }
}

Prevention

When it happens

Trigger: `opencli chatgpt image "prompt"` where sendChatGPTMessage returns false — composer not ready, send button disabled, text insertion failed, a modal/dialog intercepting input, or the page navigated at the moment of submit.

Common situations: Composer still loading after page.goto('/new') with only 2s settle; leftover draft or an unread dialog covering the composer; ChatGPT rate limits / usage cap disabling the send button; stale session showing a login interstitial; UI change altering the submit control.

Related errors


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