Full working example for solving Cloudflare Challenge using the CaptchaAI API.
Languages: Python, Node.js, PHP, Go, Java, C#, Ruby, Rust, Kotlin, Bash
Note: Cloudflare Challenge is different from Turnstile. It requires a proxy and returns a
cf_clearancecookie +User-Agentstring instead of a token. You must use the same proxy IP and User-Agent for all subsequent requests.
This example accompanies the blog article: How to Solve Cloudflare Challenge Using API
- A CaptchaAI account with API key (get one here)
- A target page protected by Cloudflare Challenge
- A working proxy (HTTP, HTTPS, SOCKS4, or SOCKS5)
- One or more of: Python 3.8+, Node.js 16+, PHP 8.0+, Go 1.21+, Java 11+, .NET 8+, Ruby 3.0+, Rust 1.70+, Kotlin 1.9+, or Bash with curl and jq
-
Clone the repository:
git clone https://github.com/CaptchaAI/CaptchaAI-Examples.git cd CaptchaAI-Examples/articles/how-to-solve-cloudflare-challenge-using-api -
Copy the environment file and add your credentials:
cp .env.example .env
-
Edit
.envwith your API key, target page URL, and proxy details. -
Follow the language-specific setup below.
cd python
pip install -r requirements.txt
python solve.pycd node
npm install
node solve.jscd php
composer install
php solve.phpcd go
go run solve.gocd java
javac Solve.java
java Solvecd csharp
dotnet runcd ruby
ruby solve.rbcd rust
cargo runcd kotlin
kotlinc solve.kt -include-runtime -d solve.jar
java -jar solve.jarcd bash
chmod +x solve.sh
bash solve.sh- The script submits the target page URL and proxy details to the CaptchaAI API.
- CaptchaAI uses the proxy to navigate to the page and solve the Cloudflare Challenge.
- The API returns the
cf_clearancecookie value and theUser-Agentstring used. - You set the
cf_clearancecookie andUser-Agentheader on all subsequent requests, using the same proxy IP that was used to solve the challenge.
| Variable | Required | Description |
|---|---|---|
CAPTCHAAI_API_KEY |
Yes | Your CaptchaAI API key |
CAPTCHA_PAGEURL |
Yes | URL of the Cloudflare-protected page |
PROXY |
Yes | Proxy in login:password@ip:port format |
PROXYTYPE |
No | HTTP (default), HTTPS, SOCKS4, or SOCKS5 |
POLL_INTERVAL |
No | Seconds between polls (default: 5) |
MAX_TIMEOUT |
No | Max seconds to wait (default: 120) |