API Tutorials

Solve Image CAPTCHA with Python OCR and CaptchaAI

Image CAPTCHAs (also called normal or text CAPTCHAs) show distorted text that users must type. They are still common on government portals, legacy systems, and registration forms. CaptchaAI accepts the image and returns the recognized text using its OCR engine.

This guide covers both file upload and base64 submission, accuracy tuning parameters, and math CAPTCHA handling.


Prerequisites

Item Value
CaptchaAI API key From captchaai.com
Python 3.7+
Libraries requests
Image format JPG, PNG, or GIF (100 bytes – 100 KB)

Method A: File upload

import requests
import time

API_KEY = "YOUR_API_KEY"

# Submit the image file
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")},
    )

result = response.json()
if result["status"] != 1:
    raise Exception(f"Submit failed: {result['request']}")

task_id = result["request"]
print(f"Task submitted: {task_id}")

Method B: Base64 submission

import base64

# Read and encode the image
with open("captcha.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode()

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"]

Poll for the text result

time.sleep(5)

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

    if result["status"] == 1:
        text = result["request"]
        print(f"CAPTCHA text: {text}")
        break

    if result["request"] != "CAPCHA_NOT_READY":
        raise Exception(f"Error: {result['request']}")

    time.sleep(5)

Accuracy tuning parameters

Add these to the submit request to improve recognition:

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 answer
# Example: digits only, 4-6 characters
response = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "base64",
    "body": img_b64,
    "numeric": 1,
    "min_len": 4,
    "max_len": 6,
    "json": 1,
})

Handling math CAPTCHAs

For images showing math expressions like "3 + 7":

response = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "base64",
    "body": img_b64,
    "calc": 1,  # Tells solver to compute the answer
    "json": 1,
})
# Returns "10" instead of "3 + 7"

Reporting incorrect solutions

If the solution is wrong, report it to improve accuracy and potentially get a refund:

requests.get("https://ocr.captchaai.com/res.php", params={
    "key": API_KEY,
    "action": "reportbad",
    "id": task_id,
})

Complete working example

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

API_KEY = "YOUR_API_KEY"

# 1. Load page and capture CAPTCHA image
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. Encode and submit
with open("captcha.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode()

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

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

# 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()

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 the image
ERROR_ZERO_CAPTCHA_FILESIZE Image < 100 bytes Check the image is valid
CAPCHA_NOT_READY Still processing Poll every 5 seconds

FAQ

How accurate is OCR solving?

Accuracy depends on distortion level. Using hint parameters (numeric, min_len, max_len) significantly improves results.

How fast is image CAPTCHA solving?

Typically 5–15 seconds — faster than token-based CAPTCHAs.

Can I solve colored or noisy CAPTCHAs?

Yes. CaptchaAI's OCR handles noise, color distortion, and overlapping characters.



Start solving image CAPTCHAs with CaptchaAI →

Discussions (0)

No comments yet.

Related Posts

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...

Automation Python reCAPTCHA v2
Apr 06, 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...

Automation Python Image OCR
Apr 01, 2026
Tutorials Image CAPTCHA Confidence Scores: Using CaptchaAI Quality Metrics
how to use Captcha AI's confidence indicators for image CAPTCHA solutions — assess answer quality, implement confidence-based retry logic, and optimize solve ra...

Learn how to use Captcha AI's confidence indicators for image CAPTCHA solutions — assess answer quality, imple...

Automation Python Image OCR
Mar 30, 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...

Automation Python Image OCR
Mar 21, 2026
Use Cases Insurance Quote Comparison Automation with CAPTCHA Handling
Automate insurance quote comparison across carriers with Captcha AI handling re CAPTCHA and image challenges on quote forms.

Automate insurance quote comparison across carriers with Captcha AI handling re CAPTCHA and image challenges o...

Automation Python reCAPTCHA v2
Feb 28, 2026
API Tutorials CaptchaAI API Latency Optimization: Faster Solves
Reduce CAPTCHA solve latency with Captcha AI by optimizing poll intervals, connection pooling, prefetching, and proxy selection.

Reduce CAPTCHA solve latency with Captcha AI by optimizing poll intervals, connection pooling, prefetching, an...

Automation Python reCAPTCHA v2
Feb 27, 2026
Troubleshooting Grid Image Coordinate Errors: Diagnosis and Fix
Fix grid image CAPTCHA coordinate errors when using Captcha AI.

Fix grid image CAPTCHA coordinate errors when using Captcha AI. Covers wrong grid size, cell numbering mismatc...

Automation Python Image OCR
Feb 26, 2026
API Tutorials Solve Grid Image CAPTCHA with Python and CaptchaAI
Step-by-step Python tutorial for solving grid image CAPTCHAs ( re CAPTCHA image challenges) using the Captcha AI API.

Step-by-step Python tutorial for solving grid image CAPTCHAs ( re CAPTCHA image challenges) using the Captcha...

Automation Python Image OCR
Feb 24, 2026
Tutorials Image CAPTCHA Preprocessing: Contrast, Rotation, and Noise Removal
Improve image CAPTCHA solve rates by preprocessing images before sending to Captcha AI — adjust contrast, fix rotation, remove noise, and optimize image quality...

Improve image CAPTCHA solve rates by preprocessing images before sending to Captcha AI — adjust contrast, fix...

Automation Python Image OCR
Feb 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
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...

Automation Python reCAPTCHA v2
Apr 08, 2026
API Tutorials Image CAPTCHA Base64 Encoding Best Practices
Best practices for base 64 encoding CAPTCHA images before submitting to Captcha AI.

Best practices for base 64 encoding CAPTCHA images before submitting to Captcha AI. Covers format, quality, si...

Python Web Scraping Image OCR
Apr 06, 2026