Skip to content
On this page

Cloudflare: solving Turnstile

TIP

Create the task with the createTask method and get the result with the getTaskResult method.

DANGER

ℹ️This task type require your own proxies.

Supported

We support most cloudflare protected sites, including 5s challenge, turnstile, captcha and other sites with verification mode. But since the site mode can be customized, if your site does not support please contact us.

The Turnstile/Challenge verification code is another attempt to replace reCaptcha/hCaptcha. We automatically support all of its subtypes:

  • turnstile
    • Manually
    • Non-Interactive
    • InVisible
  • challenge
    • 5s challenge
    • Non-Interactive turnstile
    • Non-Interactive hCaptcha

There is no need to specify subtypes during your call. It is not necessary to provide your own custom User-Agent yet, we will ignore this parameter.

TypeNoteState
img.pngturnstilestable
img_2.pngchallengestable
img_1.pngchallenge + hcaptchabeta
img_3.pngchallenge + turnstilebeta

The task type type is as follows

  • AntiCloudflareTask Proxy required

Create Task

Create the task with the createTask.

In the process of using turnstile, we must input websiteURL,websiteKey,proxy other parameters are optional.

Task Object Structure

PropertiesTypeRequiredDescription
typeStringRequiredAntiCloudflareTask
websiteURLStringRequiredThe address of the target page.
websiteKeyStringRequiredTurnstile website key.
metadataMap<String,String>RequiredTurnstile extra data . Turnstile Documentation
metadata.typeStringRequiredchallenge or turnstile fixed value.
metadata.actonStringOptionalThe value of the data-action attribute of the Turnstile element if it exists.
metadata.cdataStringOptionalThe value of the data-cdata attribute of the Turnstile element if it exists.
proxyStringRequiredLearn using proxies

Example request

text
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
json
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "AntiCloudflareTask",
    "websiteURL": "https://peet.ws/turnstile-test/non-interactive.html",
    "websiteKey": "0x4AAAAAAABS7vwvV6VFfMcD",
    "metadata": {
      "type": "turnstile",
      //optional
      "action": "login",
      //optional
      "cdata": "0000-1111-2222-3333-example-cdata"
    },
    "proxy": "socks5:158.120.100.23:334:user:pass"
  }
}

Example response

json
{
  "errorId": 0,
  "status": "idle",
  // record taskId
  "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}

Getting Result

Use the getTaskResult method to get the recognition results

Depending on the system load, you will get the results within the interval of 1s to 20s

Example request

text
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
json
{
  "clientKey": "YOUR_API_KEY",
  "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}

Example response

json
{
  "errorId": 0,
  "errorCode": null,
  "errorDescription": null,
  "solution": {
    "token": "0.mF74FV8wEufAWOdvOak_xFaVy3lqIDel7SwNhw3GgpICSWwTjYfrQB8mRT1dAJJBEoP7N1sESdp6WH9cTS1T0catWLecG3ayNcjwxVtr3hWfS-dmcBGRTx4xYwI64sAVboYGpIyuDBeMIRC3W8dK35v1nDism9xa595Da5VlXKM7hk7pIXg69lodfiftasIkyD_KUGkxBwxvrmz7dBo10-Y5zvro9hD4QKRjOx7DYj9sumnkyYCDx0m4ImDIIkNswfVTWI2V22wlnpHdvMgdtKYgOIIAU28y9gtdrdDkpkH0GHcDyd15sxQGd9VjwhGZA_mpusUKMsEoGgst2rJ3zA.UWfZupqLlGvlATkPo3wdaw.38d55cd0163610d8ce8c42fcff7b62d8981495cc1afacbb2f14e5a23682a4e13",
    "type": "turnstile",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
  },
  "status": "ready"
}

Use SDK Request

python
#pip install --upgrade capsolver
#export CAPSOLVER_API_KEY='...'

import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
          "type": "AntiCloudflareTask",
          "websiteURL": "https://peet.ws/turnstile-test/non-interactive.html",
          "websiteKey": "0x4AAAAAAABS7vwvV6VFfMcD",
          "metadata": {
            "type": "turnstile",
            "action": "login",
            "cdata": "0000-1111-2222-3333-example-cdata"
      },
    })
golang
package main

import (
	"fmt"
	capsolver_go "github.com/capsolver/capsolver-go"
	"log"
)

func main() {
	// first you need to install sdk
	//go get github.com/capsolver/capsolver-go
	//export CAPSOLVER_API_KEY='...' or
	//capSolver := CapSolver{apiKey:"..."}

	capSolver := capsolver_go.CapSolver{}
	solution, err := capSolver.Solve(map[string]any{
		"type":       "AntiCloudflareTask",
		"websiteURL": "https://peet.ws/turnstile-test/non-interactive.html",
		"websiteKey": "0x4AAAAAAABS7vwvV6VFfMcD",
		"metadata": map[string]any{
			"type":   "turnstile",
			"action": "login",
			"cdata":  "0000-1111-2222-3333-example-cdata",
		},
	})
	if err != nil {
		log.Fatal(err)
		return
	}
	fmt.Println(solution)
}