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.


Discussions (0)

No comments yet.

Related Posts

DevOps & Scaling Ansible Playbooks for CaptchaAI Worker Deployment
Deploy and manage Captcha AI workers with Ansible — playbooks for provisioning, configuration, rolling updates, and health checks across your server fleet.

Deploy and manage Captcha AI workers with Ansible — playbooks for provisioning, configuration, rolling updates...

Automation Python All CAPTCHA Types
Apr 07, 2026
DevOps & Scaling Blue-Green Deployment for CAPTCHA Solving Infrastructure
Implement blue-green deployments for CAPTCHA solving infrastructure — zero-downtime upgrades, traffic switching, and rollback strategies with Captcha AI.

Implement blue-green deployments for CAPTCHA solving infrastructure — zero-downtime upgrades, traffic switchin...

Automation Python All CAPTCHA Types
Apr 07, 2026
Troubleshooting CaptchaAI API Error Handling: Complete Decision Tree
Complete decision tree for every Captcha AI API error.

Complete decision tree for every Captcha AI API error. Learn which errors are retryable, which need parameter...

Automation Python All CAPTCHA Types
Mar 17, 2026
Tutorials Using Fiddler to Inspect CaptchaAI API Traffic
How to use Fiddler Everywhere and Fiddler Classic to capture, inspect, and debug Captcha AI API requests and responses — filters, breakpoints, and replay for tr...

How to use Fiddler Everywhere and Fiddler Classic to capture, inspect, and debug Captcha AI API requests and r...

Automation Python All CAPTCHA Types
Mar 05, 2026
Tutorials CAPTCHA Handling in Mobile Apps with Appium
Handle CAPTCHAs in mobile app automation using Appium and Captcha AI — extract Web sitekeys, solve, and inject tokens on Android and i OS.

Handle CAPTCHAs in mobile app automation using Appium and Captcha AI — extract Web View sitekeys, solve, and i...

Automation Python All CAPTCHA Types
Feb 13, 2026
Tutorials Streaming Batch Results: Processing CAPTCHA Solutions as They Arrive
Process CAPTCHA solutions the moment they arrive instead of waiting for tasks to complete — use async generators, event emitters, and callback patterns for stre...

Process CAPTCHA solutions the moment they arrive instead of waiting for all tasks to complete — use async gene...

Automation Python All CAPTCHA Types
Apr 07, 2026
Reference CaptchaAI CLI Tool: Command-Line CAPTCHA Solving and Testing
A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parameters, and integrate with shell scripts and CI/CD p...

A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parame...

Automation Python All CAPTCHA Types
Feb 26, 2026
DevOps & Scaling Auto-Scaling CAPTCHA Solving Workers
Build auto-scaling CAPTCHA solving workers that adjust capacity based on queue depth, balance, and solve rates.

Build auto-scaling CAPTCHA solving workers that adjust capacity based on queue depth, balance, and solve rates...

Automation Python All CAPTCHA Types
Mar 23, 2026
DevOps & Scaling CaptchaAI Monitoring with Datadog: Metrics and Alerts
Monitor Captcha AI performance with Datadog — custom metrics, dashboards, anomaly detection alerts, and solve rate tracking for CAPTCHA solving pipelines.

Monitor Captcha AI performance with Datadog — custom metrics, dashboards, anomaly detection alerts, and solve...

Automation Python All CAPTCHA Types
Feb 19, 2026
API Tutorials How to Solve reCAPTCHA v2 Callback Using API
how to solve re CAPTCHA v 2 callback implementations using Captcha AI API.

Learn how to solve re CAPTCHA v 2 callback implementations using Captcha AI API. Detect the callback function,...

Automation reCAPTCHA v2 Webhooks
Mar 01, 2026
API Tutorials Solve GeeTest v3 CAPTCHA with Python and CaptchaAI
Step-by-step Python tutorial for solving Gee Test v 3 slide puzzle CAPTCHAs using the Captcha AI API.

Step-by-step Python tutorial for solving Gee Test v 3 slide puzzle CAPTCHAs using the Captcha AI API. Includes...

Automation Python Testing
Mar 23, 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