CrewAI tool for solving captchas via the 2Captcha service (reCAPTCHA v2/v3, Cloudflare Turnstile, image, GeeTest).
Project description
crewai-twocaptcha
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 theTWOCAPTCHA_API_KEYenvironment 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— missingTWOCAPTCHA_API_KEY.pydantic.ValidationError— the input doesn't match the selectedcaptcha_type(e.g.recaptcha_v3withoutaction).crewai_twocaptcha.TwoCaptchaError— the 2Captcha API returned an error (ERROR_WRONG_USER_KEY,ERROR_CAPTCHA_UNSOLVABLE, …) or we exceededconfig.max_attempts * config.poll_intervalseconds.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
- 2Captcha API reference: https://2captcha.com/2captcha-api
- Get an API key: https://2captcha.com/enterpage
- CrewAI: https://github.com/crewAIInc/crewAI
- Publishing custom tools guide: https://docs.crewai.com/en/guides/tools/publish-custom-tools
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crewai_twocaptcha-0.1.0.tar.gz.
File metadata
- Download URL: crewai_twocaptcha-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19586335331431e4d105da367a52bfcc97aacb624f7a4eeac02df4e2e5933adc
|
|
| MD5 |
5b2e1ed65d3918c3766dc86d21c8ee55
|
|
| BLAKE2b-256 |
3b1f47d02815c0ddbe6a7cc135ce11a232d7780cf765277b7685042817a4ff3f
|
File details
Details for the file crewai_twocaptcha-0.1.0-py3-none-any.whl.
File metadata
- Download URL: crewai_twocaptcha-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e061e2fc394d38a3f68a631868dd9d3fc6f53c497e0e10a86d67b349beaa2f4d
|
|
| MD5 |
a0db5015b8c53096efceb6dcf1c76b32
|
|
| BLAKE2b-256 |
df92f2adc0f66f6df21a348fb786bceaf459375ce9a7e6cb7c027a2bb58af79c
|