Cloudflare Challenge Solver API: cf_clearance Cookie (Beta)
Beta
Solving the Cloudflare challenge page is in beta testing. Parameters and response time may change, and on some sites the cookie may not work. If a site does not let you in, write to support and send the page URL.
The Cloudflare challenge page is the full-screen check that Cloudflare shows before letting you into a site: "Just a moment...", "Checking your browser" or "Verify you are human". When the check passes, Cloudflare sets the cf_clearance cookie, and with it the site opens without the check.
Cap.guru passes this check on its side, through your proxy, and returns the cf_clearance cookie, the other site cookies, and the User-Agent and headers it used. You then open the site with the same cookies, User-Agent, headers and proxy.
This is not the same as a Turnstile widget in a form. A widget in a form is solved with a token: see Turnstile Token API.
How it works
- You send the page URL and your proxy to the API.
- The service opens the page through your proxy and passes the check.
- You get
cf_clearance, all site cookies, the User-Agent and the Client Hints headers. - You make requests to the site through the same proxy with these cookies, User-Agent and headers.
cf_clearance is issued for the IP address from which the check was passed and for the browser's User-Agent. If you change the proxy or the User-Agent, Cloudflare will not accept the cookie.
Sending a task
https://api2.cap.guru/in.php
| Parameter | Type | Required | Description |
|---|---|---|---|
| key | String | Yes | Your API key. You can find it in the dashboard |
| method | String | Yes | cloudflare (also accepted: cf_challenge, cloudflare_challenge) |
| pageurl | String | Yes | Full URL of the page with the check, for example https://site.com/page. You can also send it as url |
| proxy | String | Yes* | Your proxy in one of the formats: login:pass@ip:port, ip:port:login:pass or ip:port |
| proxytype | String | No | HTTP (default), HTTPS, SOCKS4 or SOCKS5 |
| userAgent | String | No | Your User-Agent. Usually it is better not to send it: the service returns the one it used. If you send it, it must be Chrome or Edge on Windows of the same version as the service browser, in the form Chrome/<version>.0.0.0, otherwise you get ERROR_BAD_PARAMETERS |
| json | Number Default: 0 | No | 1: JSON response. Recommended: without it you get only the cf_clearance value, without the User-Agent and headers |
* The task is accepted without a proxy, but then the cookie is issued for the IP of the service, and Cloudflare will not accept it from your IP. Proxies on 127.x and local network addresses are rejected right away with ERROR_PROXY_CONNECTION_FAILED.
Request example:
https://api2.cap.guru/in.php?key=YOUR_APIKEY&method=cloudflare&pageurl=https://site.com/page&proxy=login:pass@1.2.3.4:8080&proxytype=HTTP&json=1Request example in JSON
POST https://api2.cap.guru/in.php
Host: api2.cap.guru
Content-Type: application/json{
"key": "YOUR_API_KEY",
"method": "cloudflare",
"pageurl": "https://site.com/page",
"proxy": "login:pass@1.2.3.4:8080",
"proxytype": "HTTP",
"json": 1
}Response: {"status":1,"request":"123456"}, where 123456 is the task ID. If you did not get a task ID, check the list of errors.
Getting the result
https://api2.cap.guru/res.php?key=YOUR_APIKEY&action=get&id=123456&json=1Make the first request 10–15 seconds after sending the task, then every 5 seconds. While the task is being solved, you get {"status":0,"request":"CAPCHA_NOT_READY"}.
When it is ready:
{
"status": 1,
"request": "<cf_clearance value>",
"useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/<version>.0.0.0 Safari/537.36",
"cookies": {
"cf_clearance": "<value>",
"__cf_bm": "<value>"
},
"headers": {
"user-agent": "<the same User-Agent>",
"sec-ch-ua": "\"Chromium\";v=\"<version>\", ...",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\""
}
}| Field | What it is |
|---|---|
request | The cf_clearance value |
cookies | All cookies the site set, including cf_clearance and __cf_bm. Send all of them |
useragent | The User-Agent with which the check was passed |
headers | User-Agent and Client Hints headers (sec-ch-ua, sec-ch-ua-mobile, sec-ch-ua-platform). Send them with every request |
Other responses:
NO_CHALLENGEinrequest: the site let the service in without a check.cookiescontains the cookies the site set.ERROR_CAPTCHA_UNSOLVABLEor another error code: see API error codes.
If the task was sent with json=1, res.php answers in JSON even without json=1. Without JSON you get only OK|<cf_clearance value>, and that is not enough to use the cookie.
Using the cookie
Send all requests to the site:
- through the same proxy that you sent in the task;
- with all cookies from
cookies; - with all headers from
headers.
Example in Python
import time
import requests
API_KEY = "YOUR_API_KEY"
SERVER = "https://api2.cap.guru" # from Russia: https://api.cap.guru
PAGE = "https://site.com/page"
PROXY = "login:pass@1.2.3.4:8080"
def get_clearance(pageurl: str, proxy: str) -> dict:
r = requests.post(f"{SERVER}/in.php", json={
"key": API_KEY, "method": "cloudflare", "pageurl": pageurl,
"proxy": proxy, "proxytype": "HTTP", "json": 1,
}).json()
if r["status"] != 1:
raise RuntimeError(r["request"])
time.sleep(15)
for _ in range(36): # up to 3 minutes
res = requests.get(f"{SERVER}/res.php", params={
"key": API_KEY, "action": "get", "id": r["request"], "json": 1,
}).json()
if res["status"] == 1:
return res
if res["request"] != "CAPCHA_NOT_READY":
raise RuntimeError(res["request"])
time.sleep(5)
raise TimeoutError("Cloudflare check not passed in time")
result = get_clearance(PAGE, PROXY)
session = requests.Session()
session.proxies = {"http": f"http://{PROXY}", "https": f"http://{PROXY}"}
session.headers.update(result["headers"])
session.cookies.update(result["cookies"])
print(session.get(PAGE).status_code)Cloudflare also checks the TLS fingerprint of the client. If the site still answers with 403 or the check page with the correct cookies, headers and proxy, send the requests with a library that imitates Chrome (for example curl_cffi with impersonate="chrome") or from a Chrome browser with the same User-Agent and proxy.
Example in Playwright
from playwright.sync_api import sync_playwright
from urllib.parse import urlparse
result = get_clearance(PAGE, PROXY) # function from the example above
host = urlparse(PAGE).hostname
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://1.2.3.4:8080", "username": "login", "password": "pass",
})
context = browser.new_context(
user_agent=result["useragent"],
extra_http_headers={k: v for k, v in result["headers"].items() if k != "user-agent"},
)
context.add_cookies([
{"name": name, "value": value, "domain": host, "path": "/"}
for name, value in result["cookies"].items()
])
page = context.new_page()
page.goto(PAGE)Anti-Captcha format
The same result is available in the Anti-Captcha (createTask) format. Send a task with the type TurnstileTask and "cloudflareTaskType": "cf_clearance", or with the type AntiCloudflareTask, plus websiteURL and the proxy fields:
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "TurnstileTask",
"cloudflareTaskType": "cf_clearance",
"websiteURL": "https://site.com/page",
"proxyType": "http",
"proxyAddress": "1.2.3.4",
"proxyPort": 8080,
"proxyLogin": "login",
"proxyPassword": "pass"
}
}getTaskResult returns solution with the fields cf_clearance, cookies, userAgent, headers and url.
How long the cookie lives
The site owner sets the lifetime in the Cloudflare settings. The default is 30 minutes; Cloudflare recommends 15 to 45 minutes. The service does not return the lifetime yet. When the site shows the check again, get a new cookie.
Tips
- The cookie does not work. Check that you use the same proxy as in the task, and send all cookies from
cookiesand all headers fromheaders, not onlycf_clearance. ERROR_PROXY_CONNECTION_FAILED. The proxy is unavailable from the internet or is a local address (127.x,192.168.x). Use an external proxy.ERROR_BAD_PARAMETERS. Most often theuserAgentyou sent does not fit. Do not send it: the service returns the right one.NO_CHALLENGE. Cloudflare did not show the check at that moment. Use the cookies fromcookiesand make requests as usual.- The check appears again after some time. The cookie has expired. Get a new one.
- A Turnstile widget in a form, not a full-screen page. That is a regular widget: use the Turnstile Token API.