API Tutorials

Image CAPTCHA Solving Using API

Image CAPTCHAs (also called normal CAPTCHAs or text CAPTCHAs) show distorted text that users must type. Despite being the oldest CAPTCHA format, they are still used on many legacy systems, government portals, and registration forms.

CaptchaAI solves these by accepting the image and returning the recognized text.


Requirements

Item Value
CaptchaAI API key From captchaai.com
CAPTCHA image File or base64
Language Python 3.7+ or Node.js 14+

Step 1: Capture the CAPTCHA image

Screenshot method (Selenium)

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com/register")

captcha_el = driver.find_element(By.CSS_SELECTOR, "#captcha-image")
captcha_el.screenshot("captcha.png")

Download from URL

import requests
import base64

img_url = "https://example.com/captcha/generate"
img_data = requests.get(img_url).content

# Save to file
with open("captcha.png", "wb") as f:
    f.write(img_data)

# Or convert to base64
img_b64 = base64.b64encode(img_data).decode()

Step 2: Submit to CaptchaAI

Method A: File upload (Python)

import requests
import time

API_KEY = "YOUR_API_KEY"

with open("captcha.png", "rb") as f:
    response = requests.post("https://ocr.captchaai.com/in.php",
        data={"key": API_KEY, "method": "post", "json": 1},
        files={"file": ("captcha.png", f, "image/png")}
    )

data = response.json()
task_id = data["request"]
print(f"Task: {task_id}")

Method B: Base64 (Python)

response = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "base64",
    "body": img_b64,
    "json": 1
})

task_id = response.json()["request"]

Node.js (base64)

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

async function submitImageCaptcha(imagePath) {
  const imageB64 = fs.readFileSync(imagePath).toString('base64');

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

  return data.request;
}

Step 3: Poll for the text result

def get_text_solution(task_id):
    for _ in range(30):
        time.sleep(5)
        result = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": API_KEY, "action": "get", "id": task_id, "json": 1
        }).json()

        if result.get("status") == 1:
            return result["request"]  # The recognized text
        if result.get("request") != "CAPCHA_NOT_READY":
            raise Exception(f"Error: {result['request']}")

    raise Exception("Timeout")

text = get_text_solution(task_id)
print(f"CAPTCHA text: {text}")
async function getSolution(taskId) {
  for (let i = 0; i < 30; i++) {
    await new Promise(r => setTimeout(r, 5000));
    const { data } = await axios.get('https://ocr.captchaai.com/res.php', {
      params: { key: 'YOUR_API_KEY', action: 'get', id: taskId, json: 1 }
    });
    if (data.status === 1) return data.request;
    if (data.request !== 'CAPCHA_NOT_READY') throw new Error(data.request);
  }
  throw new Error('Timeout');
}

Step 4: Submit the text to the form

# Type the solved text into the CAPTCHA input
captcha_input = driver.find_element(By.CSS_SELECTOR, "#captcha-input")
captcha_input.clear()
captcha_input.send_keys(text)

# Submit the form
driver.find_element(By.CSS_SELECTOR, "form").submit()

Optional parameters for better accuracy

Parameter Value Purpose
numeric 1 = digits only, 2 = letters only Limits character set
min_len Integer Minimum text length
max_len Integer Maximum text length
language 0 = any, 1 = Cyrillic, 2 = Latin Character language
calc 1 CAPTCHA is a math expression
phrase 1 CAPTCHA contains spaces
regsense 1 Case-sensitive
response = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "base64",
    "body": img_b64,
    "numeric": 1,       # Digits only
    "min_len": 4,        # At least 4 characters
    "max_len": 6,        # At most 6 characters
    "json": 1
})

Complete Python example

import requests
import time
import base64
from selenium import webdriver
from selenium.webdriver.common.by import By

API_KEY = "YOUR_API_KEY"

# 1. Get the page and capture captcha
driver = webdriver.Chrome()
driver.get("https://example.com/register")

captcha_el = driver.find_element(By.CSS_SELECTOR, "#captcha-image")
captcha_el.screenshot("captcha.png")

# 2. Submit to CaptchaAI
with open("captcha.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode()

resp = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY, "method": "base64", "body": img_b64, "json": 1
}).json()
task_id = resp["request"]

# 3. Get solution
for _ in range(30):
    time.sleep(5)
    result = requests.get("https://ocr.captchaai.com/res.php", params={
        "key": API_KEY, "action": "get", "id": task_id, "json": 1
    }).json()
    if result.get("status") == 1:
        text = result["request"]
        break

# 4. Type and submit
driver.find_element(By.CSS_SELECTOR, "#captcha-input").send_keys(text)
driver.find_element(By.CSS_SELECTOR, "form").submit()
print(f"Solved: {text}")
driver.quit()

FAQ

How accurate is image CAPTCHA solving?

CaptchaAI achieves high accuracy for standard text CAPTCHAs. Using hint parameters (numeric, min_len, max_len) improves accuracy by constraining the character set.

How fast is image CAPTCHA solving?

Typically 5–15 seconds, faster than grid or interactive challenges.

Can I solve math CAPTCHAs?

Yes. Set calc=1 and the solver will compute the result (e.g., "3 + 7" returns "10").

What if the CAPTCHA text is case-sensitive?

Set regsense=1 to preserve letter case. Without this, the solver may return lowercase.

Can I report incorrect solutions?

Yes. Use https://ocr.captchaai.com/res.php?key=KEY&action=reportbad&id=TASK_ID to report an incorrect solution. This helps improve accuracy and may refund the solve cost.


Full Working Code

Complete runnable examples for this article in Python, Node.js, PHP, Go, Java, C#, Ruby, Rust, Kotlin & Bash.

View on GitHub →

Discussions (0)

No comments yet.