API Tutorials

How to Solve Multiple CAPTCHA Types in One Workflow

Most scraping and automation systems encounter different CAPTCHA types across different sites — reCAPTCHA v2 on one, Cloudflare Turnstile on another, and image CAPTCHAs on a third. Instead of writing separate solving logic for each type, you can build a unified workflow that detects the CAPTCHA type and routes to the correct CaptchaAI API method.

This guide shows how to build a CAPTCHA type router that handles reCAPTCHA v2, reCAPTCHA v3, Cloudflare Turnstile, GeeTest v3, and image CAPTCHAs through a single interface.


Architecture

Page HTML → Detect CAPTCHA type → Build API params → Submit to CaptchaAI → Poll → Inject result
                    ↓
         ┌─────────┼─────────┬──────────┬──────────┐
    reCAPTCHA  Turnstile  GeeTest    Image     Cloudflare
       v2/v3                v3       OCR       Challenge

All types use the same submit/poll pattern (in.phpres.php), but each requires different method names and parameters.


Python: Unified CAPTCHA solver

import requests
import time
import base64

API_KEY = "YOUR_API_KEY"


def submit_task(params):
    """Submit a CAPTCHA task and return the task ID."""
    params["key"] = API_KEY
    params["json"] = 1

    response = requests.post(
        "https://ocr.captchaai.com/in.php", data=params
    ).json()

    if response.get("status") != 1:
        raise RuntimeError(f"Submit error: {response.get('request')}")
    return response["request"]


def poll_result(task_id, initial_wait=15, max_attempts=30):
    """Poll for a CAPTCHA result."""
    time.sleep(initial_wait)

    for _ in range(max_attempts):
        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
        if result.get("request") != "CAPCHA_NOT_READY":
            raise RuntimeError(f"Solve error: {result['request']}")
        time.sleep(5)

    raise TimeoutError("Solve timed out")


def solve_recaptcha_v2(sitekey, pageurl, enterprise=False):
    """Solve reCAPTCHA v2 (standard or enterprise)."""
    params = {
        "method": "userrecaptcha",
        "googlekey": sitekey,
        "pageurl": pageurl,
    }
    if enterprise:
        params["enterprise"] = 1
    task_id = submit_task(params)
    result = poll_result(task_id, initial_wait=20)
    return result["request"]


def solve_recaptcha_v3(sitekey, pageurl, action, enterprise=False):
    """Solve reCAPTCHA v3 (standard or enterprise)."""
    params = {
        "method": "userrecaptcha",
        "version": "v3",
        "googlekey": sitekey,
        "pageurl": pageurl,
        "action": action,
    }
    if enterprise:
        params["enterprise"] = 1
    task_id = submit_task(params)
    result = poll_result(task_id, initial_wait=20)
    return result["request"]


def solve_turnstile(sitekey, pageurl):
    """Solve Cloudflare Turnstile."""
    task_id = submit_task({
        "method": "turnstile",
        "sitekey": sitekey,
        "pageurl": pageurl,
    })
    result = poll_result(task_id, initial_wait=10)
    return result["request"]


def solve_geetest_v3(gt, challenge, pageurl, api_server=None):
    """Solve GeeTest v3."""
    params = {
        "method": "geetest",
        "gt": gt,
        "challenge": challenge,
        "pageurl": pageurl,
    }
    if api_server:
        params["api_server"] = api_server
    task_id = submit_task(params)
    result = poll_result(task_id, initial_wait=15)
    return result["request"]  # JSON string with challenge/validate/seccode


def solve_image(image_data):
    """Solve an image CAPTCHA from raw bytes."""
    image_base64 = base64.b64encode(image_data).decode("utf-8")
    task_id = submit_task({
        "method": "base64",
        "body": image_base64,
    })
    result = poll_result(task_id, initial_wait=5, max_attempts=15)
    return result["request"]

Usage example

# Solve whichever CAPTCHA type you encounter:

# reCAPTCHA v2
token = solve_recaptcha_v2("6Le-wvkS...", "https://example.com/page")

# reCAPTCHA v3
token = solve_recaptcha_v3("6Le-wvkS...", "https://example.com/page", "login")

# Cloudflare Turnstile
token = solve_turnstile("0x4AAAAAAAB...", "https://example.com/page")

# GeeTest v3
solution = solve_geetest_v3("f1ab2cd...", "12345678abc...", "https://example.com")

# Image CAPTCHA
text = solve_image(open("captcha.png", "rb").read())

Node.js: Unified CAPTCHA solver

const API_KEY = "YOUR_API_KEY";

function delay(ms) {
  return new Promise((r) => setTimeout(r, ms));
}

async function submitTask(params) {
  params.key = API_KEY;
  params.json = "1";

  const res = await fetch("https://ocr.captchaai.com/in.php", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams(params),
  });
  const data = await res.json();

  if (data.status !== 1) throw new Error(`Submit error: ${data.request}`);
  return data.request;
}

async function pollResult(taskId, initialWait = 15000, maxAttempts = 30) {
  await delay(initialWait);

  for (let i = 0; i < maxAttempts; i++) {
    const res = await fetch(
      `https://ocr.captchaai.com/res.php?${new URLSearchParams({
        key: API_KEY, action: "get", id: taskId, json: "1",
      })}`
    );
    const data = await res.json();

    if (data.status === 1) return data;
    if (data.request !== "CAPCHA_NOT_READY")
      throw new Error(`Solve error: ${data.request}`);
    await delay(5000);
  }
  throw new Error("Solve timed out");
}

async function solveRecaptchaV2(sitekey, pageurl, enterprise = false) {
  const params = { method: "userrecaptcha", googlekey: sitekey, pageurl };
  if (enterprise) params.enterprise = "1";
  const taskId = await submitTask(params);
  const result = await pollResult(taskId, 20000);
  return result.request;
}

async function solveTurnstile(sitekey, pageurl) {
  const taskId = await submitTask({ method: "turnstile", sitekey, pageurl });
  const result = await pollResult(taskId, 10000);
  return result.request;
}

async function solveImage(imageBase64) {
  const taskId = await submitTask({ method: "base64", body: imageBase64 });
  const result = await pollResult(taskId, 5000, 15);
  return result.request;
}

CAPTCHA type detection hints

Indicator CAPTCHA type CaptchaAI method
grecaptcha.execute / api.js?render= reCAPTCHA v3 userrecaptcha + version=v3
grecaptcha.enterprise.execute reCAPTCHA v3 Enterprise userrecaptcha + version=v3 + enterprise=1
g-recaptcha div / api2/anchor reCAPTCHA v2 userrecaptcha
/enterprise/anchor reCAPTCHA v2 Enterprise userrecaptcha + enterprise=1
turnstile.render / data-sitekey on Turnstile div Cloudflare Turnstile turnstile
"Checking your browser…" interstitial Cloudflare Challenge cloudflare_challenge
initGeetest / geetest.js GeeTest v3 geetest
<img> with distorted text Image/OCR base64 or post

FAQ

Can I detect the CAPTCHA type automatically from page HTML?

Yes. Search the page source for the indicators in the table above. Look for script URLs, div class names, and JS function calls.

What if a page has multiple CAPTCHA types?

Some pages use reCAPTCHA v3 silently and fall back to v2 if the score is low. Solve v3 first, and if the form still shows a v2 challenge, solve that too.

Do all types use the same polling pattern?

Yes. Submit to in.php, then poll res.php with action=get. The difference is the initial wait time and the response format.

What is the fastest CAPTCHA type to solve?

Image/OCR CAPTCHAs are fastest (2–10 seconds). Token-based types like reCAPTCHA and Turnstile take 15–30 seconds.

Can I run multiple solves in parallel?

Yes. Submit multiple tasks to in.php independently and poll all of them. CaptchaAI handles them concurrently.


Solve any CAPTCHA type with CaptchaAI

Get your API key at captchaai.com. One API supports reCAPTCHA, Turnstile, GeeTest, image CAPTCHAs, and more.


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.