Skip to main content

crewai-twocaptcha

PyPI Python CI License: MIT

Languages: English · Русский

TwoCaptchaSolverTool — a CrewAI tool that solves captchas through the 2Captcha service and returns the solution token (e.g. g-recaptcha-response) to your agent.

Supported captcha types

captcha_type 2Captcha method Required input fields Verified end-to-end
recaptcha_v2 userrecaptcha website_url, sitekey ✔
recaptcha_v3 userrecaptcha + version=v3 website_url, sitekey, action (optional min_score) ✔
turnstile turnstile website_url, sitekey (optional action) ✔
image base64 body (base64-encoded image) ✔
geetest geetest website_url, gt, challenge unit-tested; live requires fresh challenge

End-to-end verification is performed against the official 2Captcha demo pages; reproduce it yourself with scripts/live_check.py (see below).

Installation

pip install crewai-twocaptcha

Or with uv:

uv add crewai-twocaptcha

Quick example

Set your 2Captcha API key:

export TWOCAPTCHA_API_KEY="your-2captcha-api-key"

Then use it like any other CrewAI tool:

from crewai_twocaptcha import TwoCaptchaSolverTool

tool = TwoCaptchaSolverTool()

token = tool.run(
    captcha_type="recaptcha_v2",
    website_url="https://example.com/login",
    sitekey="6Lc_aCMTAAAAABx7u2N0D1XVhC2VB3b7C3oFqOAx",
)

print(token)  # -> g-recaptcha-response value

Arguments

Constructor

  • api_key (str, optional): 2Captcha API key. Falls back to the TWOCAPTCHA_API_KEY environment variable.
  • config (TwoCaptchaConfig | dict, optional): polling/timeouts override.

Config fields (with defaults):

Field Default Description
poll_interval 10 Seconds between result polls
max_attempts 30 Maximum number of polls (≈5 min total by default)
timeout 20 Per-request HTTP timeout, seconds
api_base https://2captcha.com Base API URL

Environment variables

  • TWOCAPTCHA_API_KEY — your 2Captcha API key.

Examples per captcha type

reCAPTCHA v2

tool.run(
    captcha_type="recaptcha_v2",
    website_url="https://example.com/login",
    sitekey="6Lc_aCMTAAAAABx7u2N0D1XVhC2VB3b7C3oFqOAx",
)

reCAPTCHA v3

tool.run(
    captcha_type="recaptcha_v3",
    website_url="https://example.com/submit",
    sitekey="6Lc_aCMTAAAAABx7u2N0D1XVhC2VB3b7C3oFqOAx",
    action="submit",
    min_score=0.7,
)

Cloudflare Turnstile

tool.run(
    captcha_type="turnstile",
    website_url="https://example.com/",
    sitekey="0x4AAAAAAAA1bXxxxxxxxxxx",
    action="login",  # optional
)

Image (text) captcha

import base64

with open("captcha.png", "rb") as fh:
    body = base64.b64encode(fh.read()).decode()

tool.run(captcha_type="image", body=body)

GeeTest

tool.run(
    captcha_type="geetest",
    website_url="https://example.com/",
    gt="f2ae6cadcf7886856696502e1d55e00c",
    challenge="12345678abcdefghij",
)

Using inside a CrewAI agent

from crewai import Agent, Crew, Task
from crewai_twocaptcha import TwoCaptchaSolverTool

solver = TwoCaptchaSolverTool()

scraper = Agent(
    role="Web Scraper",
    goal="Log into protected pages that require captcha solving.",
    backstory="An expert at automating captcha-gated workflows.",
    tools=[solver],
)

task = Task(
    description=(
        "Solve the reCAPTCHA on https://example.com/login with sitekey "
        "6Lc_aCMTAAAAABx7u2N0D1XVhC2VB3b7C3oFqOAx and return the token."
    ),
    expected_output="The g-recaptcha-response token as a plain string.",
    agent=scraper,
)

Crew(agents=[scraper], tasks=[task]).kickoff()

Error handling

The tool raises exceptions instead of returning error strings (which would otherwise be indistinguishable from a real token for the agent):

  • ValueError — missing TWOCAPTCHA_API_KEY.
  • pydantic.ValidationError — the input doesn't match the selected captcha_type (e.g. recaptcha_v3 without action).
  • crewai_twocaptcha.TwoCaptchaError — the 2Captcha API returned an error (ERROR_WRONG_USER_KEY, ERROR_CAPTCHA_UNSOLVABLE, …) or we exceeded config.max_attempts * config.poll_interval seconds.
  • requests.HTTPError — non-2xx HTTP response from the API.

Reproducing the end-to-end check

The repository ships with scripts/live_check.py, which runs every captcha type against 2Captcha's official demo pages:

export TWOCAPTCHA_API_KEY="your-key"
python scripts/live_check.py

Total cost is roughly $0.01–0.02 per full run. Use --no-image to skip the image case or --geetest GT CHALLENGE to test GeeTest with a fresh challenge copied from your browser DevTools.

Links

License

MIT — see LICENSE.

Metadata

Release files for crewai-twocaptcha 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crewai-twocaptcha 0.1.1
File Size Uploaded
crewai_twocaptcha-0.1.1.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crewai-twocaptcha 0.1.1
File Interpreter ABI Platform
crewai_twocaptcha-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / crewai_twocaptcha-0.1.1.tar.gz

Download URL crewai_twocaptcha-0.1.1.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7adf945a6f83917c8eb1307b2ccd629efaea9abb4858126cd21c3d4bb0744992
BLAKE2b-256 checksum
How to use checksums
e0e697a259c9289a930693d1cef67dcb3763eef315cf1128ffcbe86b649e76e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / crewai_twocaptcha-0.1.1-py3-none-any.whl

Download URL crewai_twocaptcha-0.1.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c6bedbfc6d9215f7bb54e01deb00346f302ce81626571cfa483e4a95a99f6d6
BLAKE2b-256 checksum
How to use checksums
8030d3ead59688c1a21ca9f80d09597d09fe77f2b50943d1ef5da04b771b9279
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page