Cloudflare Turnstile Protocol Recognition API Integration Guide

This article introduces how to integrate the Cloudflare Turnstile protocol recognition API, which allows users to complete verification without recognizing and clicking on a Turnstile CAPTCHA, by simply submitting the Website Key for automatic decoding in the background.

Application Process

To use the Cloudflare Turnstile protocol recognition API, first visit the Ace Data Cloud Console to obtain your API Token for later use.

If you have not yet logged in or registered, you will be automatically redirected to the login page to register and log in. Once finished, you will be automatically returned to the current page.

A general-purpose application's API Key can be used for services enabled for the account; a dedicated application's Key can be used within the scope of that application's services. Please check the Key's permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for this request. Available trial credits are subject to what is displayed in your account; if the balance is insufficient, click the "Recharge" button.

📘 Full documentation: Cloudflare Turnstile Protocol Recognition API →

Basic Usage

First, let's look at the basic usage: enter the URL of the website whose Turnstile CAPTCHA needs to be processed, and you can obtain the processed result. First, you need to pass a website_url field. Our example website is https://react-turnstile.vercel.app. We need to obtain the website_key from the website_url page. First, open the webpage, press F12 to open the developer tools, and search globally for cf-turnstile on the Elements tab. You can find the container element hosting Turnstile, where the string corresponding to data-sitekey is the value of website_key.

The Request Headers to set include:

  • accept: The format in which you want to receive the response. Enter application/json here, meaning JSON format.
  • authorization: The key used to call the API. After obtaining it, you can select it directly from the drop-down list.

Also set the Request Body, including:

  • website_url: The URL of the website whose CAPTCHA needs to be processed.
  • website_key: The website key identifier (sitekey) in Cloudflare Turnstile.
  • action: An optional parameter, required only when the target website has set a custom action for the Turnstile component.
  • cdata: An optional parameter, required only when the target website has set a custom cData for the Turnstile component.

Click the "Try" button to test it. Here, we obtain the following result:

{
  "token": "0.mNQ2f9uP6mQ0y3H5Q8bqO7iM......",
  "started_at": 1784885653.0,
  "finished_at": 1784885665.4,
  "elapsed": 12.4
}

The returned result contains several fields, described as follows:

  • token: The verification result after processing this Cloudflare Turnstile CAPTCHA task.
  • started_at, finished_at: The times at which this request started processing and produced a result, as Unix timestamps (seconds, floating-point).
  • elapsed: The total time taken for this processing operation (seconds).

As you can see, we obtained the verification result for the Turnstile CAPTCHA, which we can then use in a POST request or simulated submission to the target website. It is for one-time use and is valid for 120s; use within 60s is recommended. When submitting, this token is typically sent to the target website as the cf-turnstile-response parameter. The corresponding Python code for submitting the token for verification is as follows:

import requests

token = '{token}'

data = {
    'cf-turnstile-response': token
}

response = requests.post('https://react-turnstile.vercel.app', data=data)

if response.status_code == 200:
    print(response.text)

Also, if you want to generate the corresponding integration code, you can copy the generated code directly. For example, the CURL code is as follows:

curl -X POST 'https://api.acedata.cloud/captcha/token/turnstile' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "website_key": "0x4AAAAAAADnPIDROrmt1Wwj",
  "website_url": "https://react-turnstile.vercel.app"
}'

The Python integration code is as follows:

import requests

url = "https://api.acedata.cloud/captcha/token/turnstile"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "website_key": "0x4AAAAAAADnPIDROrmt1Wwj",
    "website_url": "https://react-turnstile.vercel.app"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

Asynchronous Mode (async)

By default, the API is synchronous and blocking: a request waits until token processing is complete before returning. If you are implementing multi-solver rotation and want to "receive a task_id immediately after submitting a task, schedule other solvers first, and return later to retrieve the result," you can pass async: true in the request body.

After you pass async: true, the endpoint immediately returns a task_id instead of blocking and waiting:

{
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002",
  "trace_id": "2efa9340-b21b-4e26-9e14-4aac95f343ab"
}

To check progress proactively, you can use the task_id to query POST /captcha/tasks (once every 3–5 seconds is recommended). This endpoint does not trigger or advance task processing; the server will continue processing even if you do not query, lose your network connection, or exit the client:

curl -X POST 'https://api.acedata.cloud/captcha/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002"
}'

While processing, it returns status: processing; once processing is complete, it returns status: ready and the token:

{
  "success": true,
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002",
  "status": "ready",
  "token": "0.mNQ2f9uP6mQ0y3H5Q8bqO7iM......"
}

Billing: In asynchronous mode, creating a task and reading the "processing" status are not charged; a one-time charge is applied when the client first reads a successful result (consistent with existing behavior and synchronous-mode pricing). The server advances the task independently, but does not charge early simply because it finishes in the background first. If a task does not succeed within 120 seconds, it terminates with HTTP 504 timeout and is not charged. /captcha/tasks is not responsible for advancing the task.

Note: Cloudflare Turnstile does not currently support Bring Your Own Proxy, so this endpoint does not accept a proxy parameter; passing one will return 400 invalid_proxy.

Error Handling

When calling the API, if an error occurs, the API returns the corresponding error code and message. For example:

  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 invalid_proxy: Bad request, proxy is not supported for this captcha type.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Error Response Example

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

Conclusion

Through this document, you have learned how to use the Cloudflare Turnstile protocol recognition API to allow users to complete verification without having to recognize or click on a Turnstile CAPTCHA, simply by submitting the Website Key for automatic decoding in the background. We hope this document helps you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.