What is Cloudflare Turnstile and how to recognise it
Turnstile is a challenge a site embeds in its own page — a login, signup or checkout form — instead of an image puzzle. Verification is usually silent, and depending on the mode the site configured (managed, non-interactive or invisible) it may show a single checkbox. A page that renders Turnstile usually contains a cf-turnstile element and loads the Turnstile script from challenges.cloudflare.com/turnstile/v0/api.js.

Do not confuse it with a Cloudflare challenge page. The element lives on a page that loads normally; a challenge page is the full-page interstitial served instead of the page you asked for, and it takes different inputs and returns a different result. If the first request comes back with HTTP 403 and a page that only says "Just a moment…", you are looking at a challenge page, not this element.
Solving Turnstile returns a token of up to 2048 characters. The token is single-use and expires after about five minutes, so it is meant to be used immediately in the request you are about to send.
How to find the Turnstile sitekey
Open the page in a browser and inspect the element that renders the challenge. The sitekey is the data-sitekey attribute of the cf-turnstile element, or the sitekey argument of the turnstile.render(...) call when the page renders it from JavaScript. Sitekeys always start with 0x.

If the same element carries data-action or data-cdata, copy those values exactly as they appear — they are optional, and a verifier that checks them rejects a token that was solved for a different value. When the page renders the challenge from JavaScript, the same values are the action and cData arguments of turnstile.render. chlPageData is not supported by this task; use the Cloudflare Challenge guide for a full-page interstitial.
The page URL you send must be the page that renders the element, including its path — not the site root.
Where the token goes
Place the returned token in the page and submit the form. Most sites use a hidden input named cf-turnstile-response; a site that enabled reCAPTCHA-compatibility mode uses g-recaptcha-response instead. Some pages never create the field and instead pass a callback to turnstile.render: in that case invoke the callback with the token.

In a browser-automation script, set the field with page.evaluate() or the equivalent DOM call and then submit, using the user agent you sent in the task. Submit promptly: the token is single-use.
Common mistakes
The most common failure is solving a challenge page with the Turnstile task: the two are different products with different inputs and outputs. The second is sending a guessed action or cData — a verifier that checks them rejects the token, and guessing is worse than omitting the field. A token that was already submitted, or one that sat unused for more than a few minutes, comes back as timeout-or-duplicate from the site's own verification.
Invisible mode is easy to misread: the page shows no checkbox, so a form that fails silently usually means the token field was empty when the submit ran. Check that the field is populated before submitting, and check the submit path — a redirect or a retry can redeem the token twice.
Pooling or pre-solving tokens does not work for Turnstile. Solve inline, with the same parameters the page declares, and send the result immediately. Caller proxies are not supported for this task; both accepted names use SurSolver-managed egress.
Solve it with SurSolver
Send the page URL, the sitekey and your browser userAgent to createTask with the task type TurnstileTokenProxyLess or TurnstileToken, then poll getTaskResult until the status is ready. Neither name uses a caller proxy. The solution carries the token. Both calls are plain HTTP with a JSON body — the accepted names and parameters are listed by the public catalog (GET /v1/task-types).
Examples in your language
The official client wraps createTask and polling in one solve call. Each language tab is the Quick start of that client: it creates the client, solves the Turnstile task and returns solution.token, which you submit as the cf-turnstile-response form field. The Playwright, Puppeteer and Selenium tabs run the whole flow in a browser instead: they read the sitekey from the page, solve, fill the field and submit.
import { SurSolver, TaskType } from 'sursolver';
const API_KEY = 'YOUR_API_KEY';
const USER_AGENT =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36';
const client = new SurSolver(API_KEY);
const { solution } = await client.solve({
type: TaskType.TurnstileTokenProxyLess,
websiteURL: 'https://example.com/login',
websiteKey: '0x4AAAA...',
userAgent: USER_AGENT,
});
console.log(solution.token);
from sursolver import SurSolver, TaskType
API_KEY = "YOUR_API_KEY"
USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36"
)
client = SurSolver(API_KEY)
result = client.solve(
{
"type": TaskType.TurnstileTokenProxyLess,
"websiteURL": "https://example.com/login",
"websiteKey": "0x4AAAA...",
"userAgent": USER_AGENT,
}
)
print(result.solution["token"])
package main
import (
"context"
"fmt"
"log"
sursolver "github.com/sursolver/sursolver-go"
)
const (
APIKey = "YOUR_API_KEY"
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36"
)
func main() {
client, err := sursolver.New(APIKey)
if err != nil {
log.Fatal(err)
}
result, err := client.Solve(context.Background(), sursolver.Task{
"type": sursolver.TaskTypeTurnstileTokenProxyLess,
"websiteURL": "https://example.com/login",
"websiteKey": "0x4AAAA...",
"userAgent": UserAgent,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Solution["token"])
}
use serde_json::json;
use sursolver::{Client, task_types};
const API_KEY: &str = "YOUR_API_KEY";
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36";
#[tokio::main]
async fn main() -> Result<(), sursolver::Error> {
let client = Client::new(API_KEY)?;
let result = client
.solve(&json!({
"type": task_types::TURNSTILE_TOKEN_PROXY_LESS,
"websiteURL": "https://example.com/login",
"websiteKey": "0x4AAAA...",
"userAgent": USER_AGENT,
}))
.await?;
println!("{}", result.solution["token"]);
Ok(())
}
<?php
require __DIR__ . '/vendor/autoload.php';
use SurSolver\Client;
use SurSolver\TaskTypes;
const API_KEY = 'YOUR_API_KEY';
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36';
$client = new Client(API_KEY);
$result = $client->solve([
'type' => TaskTypes::TURNSTILE_TOKEN_PROXY_LESS,
'websiteURL' => 'https://example.com/login',
'websiteKey' => '0x4AAAA...',
'userAgent' => USER_AGENT,
]);
echo $result->solution['token'];
require "sursolver"
API_KEY = "YOUR_API_KEY"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36"
client = SurSolver::Client.new(API_KEY)
result = client.solve(
"type" => SurSolver::TaskTypes::TURNSTILE_TOKEN_PROXY_LESS,
"websiteURL" => "https://example.com/login",
"websiteKey" => "0x4AAAA...",
"userAgent" => USER_AGENT
)
puts result.solution["token"]
import com.sursolver.SolveResult;
import com.sursolver.SurSolverClient;
import com.sursolver.TaskTypes;
import java.util.Map;
public class QuickStart {
static final String API_KEY = "YOUR_API_KEY";
static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36";
public static void main(String[] args) throws InterruptedException {
SurSolverClient client = SurSolverClient.create(API_KEY);
SolveResult result = client.solve(Map.of(
"type", TaskTypes.TurnstileTokenProxyLess,
"websiteURL", "https://example.com/login",
"websiteKey", "0x4AAAA...",
"userAgent", USER_AGENT));
System.out.println(result.solution().get("token"));
}
}
using System.Text.Json.Nodes;
using SurSolver;
const string ApiKey = "YOUR_API_KEY";
const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36";
var client = new SurSolverClient(ApiKey);
var result = await client.SolveAsync(new JsonObject
{
["type"] = TaskTypes.TurnstileTokenProxyLess,
["websiteURL"] = "https://example.com/login",
["websiteKey"] = "0x4AAAA...",
["userAgent"] = UserAgent,
});
Console.WriteLine(result.Solution["token"]);
// turnstile-playwright.js - solve Turnstile on the live page and submit the form with the
// token.
// Install: npm install playwright && npx playwright install chromium
// Run: node turnstile-playwright.js
const { chromium } = require('playwright');
const { setTimeout: sleep } = require('node:timers/promises');
// Your SurSolver API key.
const CLIENT_KEY = 'sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// The page that renders the widget, with its path and query string.
const TARGET_URL = 'https://example.com/page';
// Optional, read from the page when empty: data-sitekey on the .cf-turnstile element, or the
// sitekey of turnstile.render().
const SITE_KEY = '';
// Optional, read from the page when empty: data-action on the same element; leave unset when it
// has none.
const ACTION = '';
// Optional, read from the page when empty: data-cdata on the same element; leave unset when it
// has none.
const CDATA = '';
// The User-Agent the solve runs with; send the result with this same user agent.
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36';
// The control that submits the form.
const SUBMIT_SELECTOR = '.PASTE_SUBMIT_SELECTOR';
// A selector that matches only after the site accepted the result.
const SUCCESS_SELECTOR = '.PASTE_ACCEPTED_SELECTOR';
const API = 'https://api.sursolver.com';
const POLL_ATTEMPTS = 60;
// API errors are HTTP 200 with errorId 1; anything else is a transport failure.
async function call(path, body) {
const res = await fetch(`${API}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.errorId !== 0) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
return data;
}
async function solve(task) {
const created = await call('/createTask', { clientKey: CLIENT_KEY, task });
for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt += 1) {
const result = await call('/getTaskResult', {
clientKey: CLIENT_KEY,
taskId: created.taskId,
});
if (result.status === 'ready') return result.solution;
await sleep(3000);
}
throw new Error(`task ${created.taskId} was not ready in ${POLL_ATTEMPTS} polls`);
}
// Optional task fields are sent only when they have a value.
function withoutEmpty(fields) {
return Object.fromEntries(
Object.entries(fields).filter(([, value]) => value !== undefined && value !== ''),
);
}
// A value the page did not show must be pasted into its constant at the top.
function need(name, value) {
if (value === undefined || value === null || value === '') {
throw new Error(`Could not read ${name} from the page; fill in the ${name} constant.`);
}
return value;
}
// Opens the page once and reads what the solve needs from it.
async function readPage(browser) {
const page = await browser.newPage({ userAgent: USER_AGENT });
try {
await page.goto(TARGET_URL, {
waitUntil: 'domcontentloaded',
timeout: 45000,
});
// The widget is often added after the page loads; give it a moment to appear.
await page
.waitForFunction(
() =>
!!document.querySelector('.cf-turnstile[data-sitekey]')?.dataset.sitekey,
undefined,
{ timeout: 10000 },
)
.catch(() => undefined);
const dom = await page.evaluate(() => ({
websiteKey: document.querySelector('.cf-turnstile[data-sitekey]')?.dataset.sitekey,
action: document.querySelector('.cf-turnstile')?.dataset.action,
cData: document.querySelector('.cf-turnstile')?.dataset.cdata,
}));
return {
pageUrl: page.url(),
...dom,
};
} finally {
await page.close();
}
}
async function main() {
const browser = await chromium.launch();
try {
const found = await readPage(browser);
const solution = await solve({
type: 'TurnstileTokenProxyLess',
websiteURL: found.pageUrl,
websiteKey: need('websiteKey', SITE_KEY || found.websiteKey),
userAgent: USER_AGENT,
...withoutEmpty({
action: ACTION || found.action,
cData: CDATA || found.cData,
}),
});
// Submit from a fresh session with the user agent the solve ran with.
const context = await browser.newContext({ userAgent: USER_AGENT });
const page = await context.newPage();
await page.goto(found.pageUrl);
const applied = await page.evaluate(
({ token }) => {
let filled = false;
for (const name of ['cf-turnstile-response', 'g-recaptcha-response']) {
for (const field of document.querySelectorAll(`[name="${name}"]`)) {
field.value = token;
filled = true;
}
}
const callback = document.querySelector('.cf-turnstile')?.dataset.callback;
if (callback && typeof window[callback] === 'function') {
window[callback](token);
filled = true;
}
return filled;
},
{ token: solution.token },
);
if (!applied) {
throw new Error('The page has no token field or callback; check how it passes the token.');
}
await page.click(SUBMIT_SELECTOR);
await page.locator(SUCCESS_SELECTOR).first().waitFor({ timeout: 15000 });
console.log('The site accepted the token.');
} finally {
await browser.close();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
// turnstile-puppeteer.js - solve Turnstile on the live page and submit the form with the token.
// Install: npm install puppeteer
// Run: node turnstile-puppeteer.js
const puppeteer = require('puppeteer');
const { setTimeout: sleep } = require('node:timers/promises');
// Your SurSolver API key.
const CLIENT_KEY = 'sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// The page that renders the widget, with its path and query string.
const TARGET_URL = 'https://example.com/page';
// Optional, read from the page when empty: data-sitekey on the .cf-turnstile element, or the
// sitekey of turnstile.render().
const SITE_KEY = '';
// Optional, read from the page when empty: data-action on the same element; leave unset when it
// has none.
const ACTION = '';
// Optional, read from the page when empty: data-cdata on the same element; leave unset when it
// has none.
const CDATA = '';
// The User-Agent the solve runs with; send the result with this same user agent.
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36';
// The control that submits the form.
const SUBMIT_SELECTOR = '.PASTE_SUBMIT_SELECTOR';
// A selector that matches only after the site accepted the result.
const SUCCESS_SELECTOR = '.PASTE_ACCEPTED_SELECTOR';
const API = 'https://api.sursolver.com';
const POLL_ATTEMPTS = 60;
// API errors are HTTP 200 with errorId 1; anything else is a transport failure.
async function call(path, body) {
const res = await fetch(`${API}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.errorId !== 0) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
return data;
}
async function solve(task) {
const created = await call('/createTask', { clientKey: CLIENT_KEY, task });
for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt += 1) {
const result = await call('/getTaskResult', {
clientKey: CLIENT_KEY,
taskId: created.taskId,
});
if (result.status === 'ready') return result.solution;
await sleep(3000);
}
throw new Error(`task ${created.taskId} was not ready in ${POLL_ATTEMPTS} polls`);
}
// Optional task fields are sent only when they have a value.
function withoutEmpty(fields) {
return Object.fromEntries(
Object.entries(fields).filter(([, value]) => value !== undefined && value !== ''),
);
}
// A value the page did not show must be pasted into its constant at the top.
function need(name, value) {
if (value === undefined || value === null || value === '') {
throw new Error(`Could not read ${name} from the page; fill in the ${name} constant.`);
}
return value;
}
// Opens the page once and reads what the solve needs from it.
async function readPage(browser) {
const page = await browser.newPage();
await page.setUserAgent(USER_AGENT);
try {
await page.goto(TARGET_URL, {
waitUntil: 'domcontentloaded',
timeout: 45000,
});
// The widget is often added after the page loads; give it a moment to appear.
await page
.waitForFunction(
() =>
!!document.querySelector('.cf-turnstile[data-sitekey]')?.dataset.sitekey,
{ timeout: 10000 },
)
.catch(() => undefined);
const dom = await page.evaluate(() => ({
websiteKey: document.querySelector('.cf-turnstile[data-sitekey]')?.dataset.sitekey,
action: document.querySelector('.cf-turnstile')?.dataset.action,
cData: document.querySelector('.cf-turnstile')?.dataset.cdata,
}));
return {
pageUrl: page.url(),
...dom,
};
} finally {
await page.close();
}
}
async function main() {
const browser = await puppeteer.launch();
try {
const found = await readPage(browser);
const solution = await solve({
type: 'TurnstileTokenProxyLess',
websiteURL: found.pageUrl,
websiteKey: need('websiteKey', SITE_KEY || found.websiteKey),
userAgent: USER_AGENT,
...withoutEmpty({
action: ACTION || found.action,
cData: CDATA || found.cData,
}),
});
// Submit from a fresh page with the user agent the solve ran with.
const page = await browser.newPage();
await page.setUserAgent(USER_AGENT);
await page.goto(found.pageUrl);
const applied = await page.evaluate(
({ token }) => {
let filled = false;
for (const name of ['cf-turnstile-response', 'g-recaptcha-response']) {
for (const field of document.querySelectorAll(`[name="${name}"]`)) {
field.value = token;
filled = true;
}
}
const callback = document.querySelector('.cf-turnstile')?.dataset.callback;
if (callback && typeof window[callback] === 'function') {
window[callback](token);
filled = true;
}
return filled;
},
{ token: solution.token },
);
if (!applied) {
throw new Error('The page has no token field or callback; check how it passes the token.');
}
await page.click(SUBMIT_SELECTOR);
await page.waitForSelector(SUCCESS_SELECTOR, { timeout: 15000 });
console.log('The site accepted the token.');
} finally {
await browser.close();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
# turnstile-selenium.py - solve Turnstile on the live page and submit the form with the token.
# Install: pip install requests selenium
# Run: python turnstile-selenium.py
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# Your SurSolver API key.
CLIENT_KEY = "sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# The page that renders the widget, with its path and query string.
TARGET_URL = "https://example.com/page"
# Optional, read from the page when empty: data-sitekey on the .cf-turnstile element, or the
# sitekey of turnstile.render().
SITE_KEY = None
# Optional, read from the page when empty: data-action on the same element; leave unset when it
# has none.
ACTION = None
# Optional, read from the page when empty: data-cdata on the same element; leave unset when it
# has none.
CDATA = None
# The User-Agent the solve runs with; send the result with this same user agent.
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36"
# The control that submits the form.
SUBMIT_SELECTOR = ".PASTE_SUBMIT_SELECTOR"
# A selector that matches only after the site accepted the result.
SUCCESS_SELECTOR = ".PASTE_ACCEPTED_SELECTOR"
API = "https://api.sursolver.com"
POLL_ATTEMPTS = 60
def call(path, body):
# API errors are HTTP 200 with errorId 1; anything else is a transport failure.
response = requests.post(f"{API}{path}", json=body, timeout=30)
response.raise_for_status()
data = response.json()
if data["errorId"] != 0:
raise RuntimeError(f'{data["errorCode"]}: {data["errorDescription"]}')
return data
def solve(task):
created = call("/createTask", {"clientKey": CLIENT_KEY, "task": task})
for _ in range(POLL_ATTEMPTS):
result = call("/getTaskResult", {"clientKey": CLIENT_KEY, "taskId": created["taskId"]})
if result["status"] == "ready":
return result["solution"]
time.sleep(3)
raise TimeoutError(f'task {created["taskId"]} was not ready in {POLL_ATTEMPTS} polls')
def without_empty(fields):
# Optional task fields are sent only when they have a value.
return {name: value for name, value in fields.items() if value not in (None, "")}
def need(name, value):
# A value the page did not show must be pasted into its constant at the top.
if value in (None, ""):
raise SystemExit(f"Could not read {name} from the page; fill in the {name} constant.")
return value
def new_driver(user_agent=None):
options = webdriver.ChromeOptions()
options.add_argument("--headless=new") # remove this line to watch the browser
driver = webdriver.Chrome(options=options)
if user_agent:
# Present the user agent the solve ran with.
driver.execute_cdp_cmd("Network.setUserAgentOverride", {"userAgent": user_agent})
return driver
READ_SCRIPT = r"""
return {
websiteKey: document.querySelector('.cf-turnstile[data-sitekey]')?.dataset.sitekey,
action: document.querySelector('.cf-turnstile')?.dataset.action,
cData: document.querySelector('.cf-turnstile')?.dataset.cdata,
};
"""
APPLY_SCRIPT = r"""
const [token] = arguments;
let filled = false;
for (const name of ['cf-turnstile-response', 'g-recaptcha-response']) {
for (const field of document.querySelectorAll(`[name="${name}"]`)) {
field.value = token;
filled = true;
}
}
const callback = document.querySelector('.cf-turnstile')?.dataset.callback;
if (callback && typeof window[callback] === 'function') {
window[callback](token);
filled = true;
}
return filled;
"""
def read_page():
# Opens the page once and reads what the solve needs from its DOM.
driver = new_driver(USER_AGENT)
try:
driver.get(TARGET_URL)
found = driver.execute_script(READ_SCRIPT)
found["pageUrl"] = driver.current_url
return found
finally:
driver.quit()
def main():
found = read_page()
solution = solve({
"type": "TurnstileTokenProxyLess",
"websiteURL": found["pageUrl"],
"websiteKey": need("websiteKey", SITE_KEY or found.get("websiteKey")),
"userAgent": USER_AGENT,
**without_empty({
"action": ACTION or found.get("action"),
"cData": CDATA or found.get("cData"),
}),
})
# Submit from a fresh session with the user agent the solve ran with.
driver = new_driver(USER_AGENT)
try:
driver.get(found["pageUrl"])
applied = driver.execute_script(APPLY_SCRIPT, solution["token"])
if not applied:
raise SystemExit("The page has no token field or callback.")
driver.find_element(By.CSS_SELECTOR, SUBMIT_SELECTOR).click()
WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.CSS_SELECTOR, SUCCESS_SELECTOR))
)
print("The site accepted the token.")
finally:
driver.quit()
if __name__ == "__main__":
main()
The full walkthrough — callback handling, the Puppeteer alternative and the failure modes — is in the Cloudflare Turnstile solver API guide.