API Tutorials

Solve Image CAPTCHA with Node.js and CaptchaAI

Image CAPTCHAs display distorted text that users must type. They appear on government sites, legacy forms, and registration pages. CaptchaAI reads the image and returns the text. This guide shows how to do it from Node.js.


Prerequisites

Item Value
CaptchaAI API key From captchaai.com
Node.js 14+
Libraries axios, fs
Image format JPG, PNG, or GIF (100 bytes – 100 KB)

Method A: Base64 submission

const axios = require('axios');
const fs = require('fs');

const API_KEY = 'YOUR_API_KEY';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

// Read and encode the image
const imageB64 = fs.readFileSync('captcha.png').toString('base64');

// Submit to CaptchaAI
const { data: submitData } = await axios.post('https://ocr.captchaai.com/in.php', null, {
  params: {
    key: API_KEY,
    method: 'base64',
    body: imageB64,
    json: 1,
  },
});

if (submitData.status !== 1) throw new Error(submitData.request);
const taskId = submitData.request;
console.log(`Task submitted: ${taskId}`);

Method B: File upload

const FormData = require('form-data');

const form = new FormData();
form.append('key', API_KEY);
form.append('method', 'post');
form.append('json', '1');
form.append('file', fs.createReadStream('captcha.png'));

const { data: submitData } = await axios.post('https://ocr.captchaai.com/in.php', form, {
  headers: form.getHeaders(),
});

const taskId = submitData.request;

Poll for the text result

await sleep(5000);

let captchaText;
for (let i = 0; i < 30; i++) {
  const { data: pollData } = await axios.get('https://ocr.captchaai.com/res.php', {
    params: { key: API_KEY, action: 'get', id: taskId, json: 1 },
  });

  if (pollData.status === 1) {
    captchaText = pollData.request;
    console.log(`CAPTCHA text: ${captchaText}`);
    break;
  }
  if (pollData.request !== 'CAPCHA_NOT_READY') {
    throw new Error(pollData.request);
  }
  await sleep(5000);
}

Accuracy parameters

// Digits only, 4-6 characters
const { data } = await axios.post('https://ocr.captchaai.com/in.php', null, {
  params: {
    key: API_KEY,
    method: 'base64',
    body: imageB64,
    numeric: 1,      // digits only
    min_len: 4,       // minimum length
    max_len: 6,       // maximum length
    json: 1,
  },
});
Parameter Value Purpose
numeric 1 = digits, 2 = letters Limits characters
min_len / max_len Integer Length constraints
calc 1 Computes math expression
regsense 1 Case-sensitive

Complete working example

const axios = require('axios');
const puppeteer = require('puppeteer');
const fs = require('fs');

const API_KEY = 'YOUR_API_KEY';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function solveImageCaptcha() {
  // 1. Load page and screenshot CAPTCHA
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com/register');

  const captchaEl = await page.$('#captcha-image');
  await captchaEl.screenshot({ path: 'captcha.png' });

  // 2. Encode and submit
  const imageB64 = fs.readFileSync('captcha.png').toString('base64');
  const { data: submit } = await axios.post('https://ocr.captchaai.com/in.php', null, {
    params: { key: API_KEY, method: 'base64', body: imageB64, json: 1 },
  });
  const taskId = submit.request;

  // 3. Poll for text
  await sleep(5000);
  let text;
  for (let i = 0; i < 30; i++) {
    const { data: poll } = await axios.get('https://ocr.captchaai.com/res.php', {
      params: { key: API_KEY, action: 'get', id: taskId, json: 1 },
    });
    if (poll.status === 1) { text = poll.request; break; }
    if (poll.request !== 'CAPCHA_NOT_READY') throw new Error(poll.request);
    await sleep(5000);
  }

  // 4. Type and submit
  await page.type('#captcha-input', text);
  await page.click('form [type="submit"]');
  console.log(`Solved: ${text}`);
  await browser.close();
}

solveImageCaptcha().catch(console.error);

Expected output:

Solved: ABC123

Common errors

Error Cause Fix
ERROR_WRONG_FILE_EXTENSION Unsupported format Use JPG, PNG, or GIF
ERROR_TOO_BIG_CAPTCHA_FILESIZE Image > 100 KB Compress first
ERROR_ZERO_CAPTCHA_FILESIZE Image < 100 bytes Verify the image
CAPCHA_NOT_READY Still solving Poll every 5 seconds

FAQ

Can I solve math CAPTCHAs?

Yes. Add calc: 1 to the parameters and CaptchaAI will return the computed result.

How do I report wrong solutions?

Call https://ocr.captchaai.com/res.php?key=KEY&action=reportbad&id=TASK_ID to report incorrect results.

Is base64 or file upload faster?

Performance is the same. Base64 is more convenient when you already have the image in memory.



Start solving image CAPTCHAs with CaptchaAI →

Discussions (0)

No comments yet.

Related Posts

Tutorials Node.js Worker Threads for Parallel CAPTCHA Solving
Use Node.js Worker Threads for true parallel CAPTCHA solving with Captcha AI.

Use Node.js Worker Threads for true parallel CAPTCHA solving with Captcha AI. Offload solving to separate thre...

Automation Image OCR DevOps
Mar 11, 2026
API Tutorials Solve Grid Image CAPTCHA with Node.js and CaptchaAI
Step-by-step Node.js tutorial for solving grid image CAPTCHAs using the Captcha AI API with Puppeteer.

Step-by-step Node.js tutorial for solving grid image CAPTCHAs using the Captcha AI API with Puppeteer. Include...

Automation Image OCR Grid Image
Feb 12, 2026
API Tutorials Solving CAPTCHAs with Swift and CaptchaAI API
Complete guide to solving re CAPTCHA, Turnstile, and image CAPTCHAs in Swift using Captcha AI's HTTP API with URLSession, async/await, and Alamofire.

Complete guide to solving re CAPTCHA, Turnstile, and image CAPTCHAs in Swift using Captcha AI's HTTP API with...

Automation Cloudflare Turnstile reCAPTCHA v2
Apr 05, 2026
Tutorials CAPTCHA Solving Fallback Chains
Implement fallback chains for CAPTCHA solving with Captcha AI.

Implement fallback chains for CAPTCHA solving with Captcha AI. Cascade through solver methods, proxy pools, an...

Python Automation Cloudflare Turnstile
Apr 06, 2026
Troubleshooting Common Grid Image CAPTCHA Errors and Fixes
Fix common grid image CAPTCHA solving errors.

Fix common grid image CAPTCHA solving errors. Covers image quality issues, wrong cell selection, timeout error...

Automation Image OCR Grid Image
Mar 29, 2026
API Tutorials Batch Image CAPTCHA Solving: Processing 1000+ Images
Process thousands of image CAPTCHAs efficiently with Captcha AI using async queues, worker pools, and rate-aware batching in Python and Node.js.

Process thousands of image CAPTCHAs efficiently with Captcha AI using async queues, worker pools, and rate-awa...

Python Automation Image OCR
Mar 21, 2026
Tutorials Node.js Playwright + CaptchaAI Complete Integration
Complete guide to integrating Captcha AI with Node.js Playwright.

Complete guide to integrating Captcha AI with Node.js Playwright. Solve re CAPTCHA, Turnstile, and image CAPTC...

Automation Cloudflare Turnstile Node.js
Apr 05, 2026
Tutorials Node.js CAPTCHA Solving with Retry and Error Handling
Build robust CAPTCHA solving in Node.js with retry logic, exponential backoff, circuit breakers, and proper error classification for Captcha AI.

Build robust CAPTCHA solving in Node.js with retry logic, exponential backoff, circuit breakers, and proper er...

Automation All CAPTCHA Types Node.js
Apr 04, 2026
Tutorials Python Multiprocessing for Parallel CAPTCHA Solving
Use Python multiprocessing to solve CAPTCHAs in parallel with Captcha AI.

Use Python multiprocessing to solve CAPTCHAs in parallel with Captcha AI. Process Pool Executor, Pool, and hyb...

Python Automation Image OCR
Apr 01, 2026
Tutorials Solving GeeTest v3 with Node.js and CaptchaAI API
Complete Node.js tutorial for solving Gee Test v 3 slide puzzles with Captcha AI.

Complete Node.js tutorial for solving Gee Test v 3 slide puzzles with Captcha AI. Extract gt/challenge paramet...

Automation Testing GeeTest v3
Apr 01, 2026
API Tutorials Case-Sensitive CAPTCHA API Parameter Guide
How to use the regsense parameter for case-sensitive CAPTCHA solving with Captcha AI.

How to use the regsense parameter for case-sensitive CAPTCHA solving with Captcha AI. Covers when to use, comm...

Python Web Scraping Image OCR
Apr 09, 2026
API Tutorials How to Solve reCAPTCHA v2 Enterprise with Python
Solve re CAPTCHA v 2 Enterprise using Python and Captcha AI API.

Solve re CAPTCHA v 2 Enterprise using Python and Captcha AI API. Complete guide with sitekey extraction, task...

Python Automation reCAPTCHA v2
Apr 08, 2026
API Tutorials Graceful Degradation When CAPTCHA Solving Fails
Keep your automation running when CAPTCHA solving fails — fallback strategies, queue-based retries, and degraded-mode patterns.

Keep your automation running when CAPTCHA solving fails — fallback strategies, queue-based retries, and degrad...

Python Automation All CAPTCHA Types
Apr 06, 2026