API Tutorials

Phrase, MinLen, and MaxLen Parameters for Image CAPTCHA

Constraining the expected answer length and format improves solve accuracy. These parameters eliminate impossible answers before they're returned.


Parameter Reference

Parameter Type Values Description
phrase int 0, 1 0 = single word, 1 = phrase (with spaces)
minLen int 1-20 Minimum answer length
maxLen int 1-20 Maximum answer length

How Length Constraints Help

Without constraints, the solver might return:

  • "ABCD" when the CAPTCHA has 6 characters
  • "ABCDEFGH" when there are only 4
  • Extra noise characters

With minLen=6, maxLen=6, the solver knows exactly how many characters to find.


Fixed-Length CAPTCHAs

Many CAPTCHAs use a consistent character count:

import requests
import base64
import time
import os

API_KEY = os.environ["CAPTCHAAI_API_KEY"]


def solve_fixed_length(image_b64, length):
    """Solve a CAPTCHA with a known fixed character count."""
    resp = requests.post("https://ocr.captchaai.com/in.php", data={
        "key": API_KEY,
        "method": "base64",
        "body": image_b64,
        "minLen": length,
        "maxLen": length,
        "json": 1,
    }, timeout=30)
    return resp.json()


# Common fixed-length patterns:
# 4-character: solve_fixed_length(b64, 4)
# 5-character: solve_fixed_length(b64, 5)
# 6-character: solve_fixed_length(b64, 6)

Variable-Length CAPTCHAs

Set a range when the length varies:

def solve_variable_length(image_b64, min_len, max_len):
    """Solve when character count varies within a range."""
    resp = requests.post("https://ocr.captchaai.com/in.php", data={
        "key": API_KEY,
        "method": "base64",
        "body": image_b64,
        "minLen": min_len,
        "maxLen": max_len,
        "json": 1,
    }, timeout=30)
    return resp.json()


# Examples:
# Banking (4-6 digits): solve_variable_length(b64, 4, 6)
# Forum (5-8 mixed):    solve_variable_length(b64, 5, 8)
# Simple (3-5 chars):   solve_variable_length(b64, 3, 5)

The Phrase Parameter

The phrase parameter handles CAPTCHAs with spaces between words:

def solve_phrase_captcha(image_b64):
    """Solve a CAPTCHA that contains a phrase (words with spaces)."""
    resp = requests.post("https://ocr.captchaai.com/in.php", data={
        "key": API_KEY,
        "method": "base64",
        "body": image_b64,
        "phrase": 1,       # Answer may contain spaces
        "json": 1,
    }, timeout=30)
    return resp.json()


# phrase=0 (default): "hello world" → might return "helloworld"
# phrase=1: "hello world" → returns "hello world" (preserves spaces)

Detecting Length from the Page

# detect_length.py
import re


def detect_captcha_length(page_html):
    """Auto-detect expected CAPTCHA length from page HTML."""
    hints = {}

    # Check input maxlength attribute
    match = re.search(
        r'<input[^>]*captcha[^>]*maxlength="(\d+)"',
        page_html, re.IGNORECASE,
    )
    if match:
        hints["maxLen"] = int(match.group(1))

    # Check minlength
    match = re.search(
        r'<input[^>]*captcha[^>]*minlength="(\d+)"',
        page_html, re.IGNORECASE,
    )
    if match:
        hints["minLen"] = int(match.group(1))

    # Check pattern attribute
    match = re.search(
        r'<input[^>]*captcha[^>]*pattern="([^"]+)"',
        page_html, re.IGNORECASE,
    )
    if match:
        pattern = match.group(1)
        # Pattern like [a-zA-Z0-9]{6} → length is 6
        len_match = re.search(r'\{(\d+)\}', pattern)
        if len_match:
            length = int(len_match.group(1))
            hints["minLen"] = length
            hints["maxLen"] = length
        # Pattern like [a-zA-Z0-9]{4,8} → range 4-8
        range_match = re.search(r'\{(\d+),(\d+)\}', pattern)
        if range_match:
            hints["minLen"] = int(range_match.group(1))
            hints["maxLen"] = int(range_match.group(2))

    # Check for phrase hints
    lower = page_html.lower()
    if "words" in lower or "phrase" in lower or "spaces" in lower:
        hints["phrase"] = 1

    return hints


# Usage
html = '<input id="captcha" maxlength="6" minlength="6">'
hints = detect_captcha_length(html)
# {"maxLen": 6, "minLen": 6}

Combining Parameters

# Common parameter combinations:

# 4-digit PIN CAPTCHA
pin_params = {
    "numeric": 1,
    "minLen": 4,
    "maxLen": 4,
    "phrase": 0,
}

# 6-char mixed CAPTCHA (case-sensitive)
mixed_params = {
    "regsense": 1,
    "minLen": 6,
    "maxLen": 6,
    "phrase": 0,
}

# Two-word phrase CAPTCHA
phrase_params = {
    "phrase": 1,
    "minLen": 6,
    "maxLen": 15,
    "language": 2,
}

# 5-8 digit number
number_params = {
    "numeric": 1,
    "minLen": 5,
    "maxLen": 8,
    "phrase": 0,
}

Validation After Solving

# validate.py


def validate_answer(answer, expected_min=None, expected_max=None, is_phrase=False):
    """Validate the solve result matches expectations."""
    if not answer:
        return False

    length = len(answer)

    if expected_min and length < expected_min:
        return False
    if expected_max and length > expected_max:
        return False

    if not is_phrase and " " in answer:
        return False  # Unexpected space

    return True

Troubleshooting

Issue Cause Fix
Answer too short Noise swallowed a character Set minLen to force minimum length
Answer too long Noise read as extra character Set maxLen to cap length
Spaces in answer Phrase CAPTCHA Set phrase=1
No spaces when expected Default phrase=0 Enable phrase=1 for multi-word CAPTCHAs

FAQ

What if I don't know the exact length?

Set a range. If the CAPTCHA usually has 4-6 characters, use minLen=4, maxLen=6. This is better than no constraint.

Can I use minLen and maxLen with token-based CAPTCHAs?

No. These parameters only apply to image/OCR CAPTCHAs (method=base64 or method=post). Token-based CAPTCHAs (reCAPTCHA, Turnstile) ignore them.

Does phrase=1 affect accuracy?

It can. Phrase mode tells the solver to look for word boundaries. Only use it when the CAPTCHA actually contains spaces.



Constrain and conquer — start with CaptchaAI.

Discussions (0)

No comments yet.

Related Posts

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 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
API Tutorials Custom CAPTCHA Types: Submitting Unusual Challenges to CaptchaAI
How to submit non-standard and custom CAPTCHA types to Captcha AI — drag-and-drop, slider, puzzle, audio, and custom interactive challenges.

How to submit non-standard and custom CAPTCHA types to Captcha AI — drag-and-drop, slider, puzzle, audio, and...

Python Web Scraping Image OCR
Feb 07, 2026
Tutorials Grid Image CAPTCHA: Coordinate Mapping and Cell Selection
Map grid image CAPTCHA cells to coordinates, extract the full grid, and solve re CAPTCHA-style image challenges with Captcha AI.

Map grid image CAPTCHA cells to coordinates, extract the full grid, and solve re CAPTCHA-style image challenge...

Python Web Scraping Image OCR
Jan 20, 2026
API Tutorials Improving OCR CAPTCHA Accuracy with CaptchaAI Settings
Optimize OCR CAPTCHA solve accuracy using Captcha AI API parameters — numeric, min Len, max Len, language, regsense, and textinstructions.

Optimize OCR CAPTCHA solve accuracy using Captcha AI API parameters — numeric, min Len, max Len, language, reg...

Python Web Scraping Image OCR
Jan 09, 2026
API Tutorials Math CAPTCHA Solving with CaptchaAI calc Parameter
Solve math CAPTCHAs using Captcha AI's calc parameter.

Solve math CAPTCHAs using Captcha AI's calc parameter. The API reads the equation and returns the computed res...

Python Web Scraping Image OCR
Apr 02, 2026
API Tutorials CAPTCHA Image Preprocessing for Better Solve Rates
Preprocess CAPTCHA images using Python PIL to improve solve rates — grayscale conversion, noise removal, contrast enhancement, and binarization.

Preprocess CAPTCHA images using Python PIL to improve solve rates — grayscale conversion, noise removal, contr...

Python Web Scraping Image OCR
Mar 15, 2026
Use Cases Shipping and Logistics Rate Scraping with CAPTCHA Solving
Scrape shipping rates, tracking data, and logistics information from carrier websites protected by CAPTCHAs using Captcha AI.

Scrape shipping rates, tracking data, and logistics information from carrier websites protected by CAPTCHAs us...

Python reCAPTCHA v2 Cloudflare Turnstile
Jan 25, 2026
API Tutorials Multi-Character Image CAPTCHA Solving Strategies
Strategies for solving multi-character image CAPTCHAs — handling connected letters, overlapping characters, and distorted text with Captcha AI.

Strategies for solving multi-character image CAPTCHAs — handling connected letters, overlapping characters, an...

Python Web Scraping Image OCR
Jan 20, 2026
Use Cases Legal Research Web Scraping with CAPTCHA Handling
Scrape legal databases, court records, and case law from portals protected by CAPTCHAs using Captcha AI for automated legal research.

Scrape legal databases, court records, and case law from portals protected by CAPTCHAs using Captcha AI for au...

Python reCAPTCHA v2 Web Scraping
Jan 17, 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 Solving CAPTCHAs with Kotlin and CaptchaAI API
Complete guide to solving re CAPTCHA, Turnstile, and image CAPTCHAs in Kotlin using Captcha AI's HTTP API with Ok Http, Ktor client, and coroutines.

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

Automation reCAPTCHA v2 Cloudflare Turnstile
Mar 06, 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...

Automation Python All CAPTCHA Types
Apr 06, 2026