Recaptcha2 Image Recognition API Integration Guide

This article introduces a Recaptcha2 image recognition API integration guide. It accepts the recognition target entered by the user and a Recaptcha2 CAPTCHA image, and returns the coordinates of the small images that need to be clicked to complete verification.

Application Process

To use the Recaptcha2 Image Recognition API, first go to 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 completed, you will be automatically returned to the current page.

The API Key for a general application can be used for services enabled for the account; the Key for a dedicated application can be used within that application's service scope. 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: Recaptcha2 Image Recognition API →

Basic Usage

First, let's look at the basic usage. We need to capture a Recaptcha2 CAPTCHA image from a website. The URL of the example website here is https://www.google.com/recaptcha/api2/demo, and the page is shown below:

We need to click the CAPTCHA checkbox for the CAPTCHA image to appear. In the image above, the yellow arrow points to a piece of text, which is the value of question below. First, simply pass an image field, which is the actual Recaptcha2 CAPTCHA image pointed to by the red arrow in the image above. You must also resize the image to a standard size (100x100, 300x300, 450x450) so that the service can determine the image type. You need to compress the image yourself. This article recommends a compression website, where you can reduce the image's dimensions and file size. The compressed result is shown below:

You also need to enter the recognition target parameter question related to the CAPTCHA image. We only provide the following content table, which can be used as a reference:

Chinese Content Table

{
  "/m/0pg52": "出租车",
  "/m/01bjv": "巴士",
  "/m/02yvhj": "校车",
  "/m/04_sv": "摩托车",
  "/m/013xlm": "拖拉机",
  "/m/01jk_4": "烟囱",
  "/m/014xcs": "人行横道",
  "/m/015qff": "红绿灯",
  "/m/0199g": "自行车",
  "/m/015qbp": "停车计价表",
  "/m/0k4j": "汽车",
  "/m/015kr": "桥",
  "/m/019jd": "船",
  "/m/0cdl1": "棕榈树",
  "/m/09d_r": "山",
  "/m/01pns0": "消防栓",
  "/m/01lynh": "楼梯"
}

English Content Table

{
  "/m/0pg52": "taxis",
  "/m/01bjv": "bus",
  "/m/02yvhj": "school bus",
  "/m/04_sv": "motorcycles",
  "/m/013xlm": "tractors",
  "/m/01jk_4": "chimneys",
  "/m/014xcs": "crosswalks", // pedestrian crossings 也是一样的
  "/m/015qff": "traffic lights",
  "/m/0199g": "bicycles",
  "/m/015qbp": "parking meters",
  "/m/0k4j": "cars",
  "/m/015kr": "bridges",
  "/m/019jd": "boats",
  "/m/0cdl1": "palm trees",
  "/m/09d_r": "mountains or hills",
  "/m/01pns0": "fire hydrant",
  "/m/01lynh": "stairs"
}

From the above, set the question parameter to /m/01pns0, which corresponds to a fire hydrant. The details are as follows:

As you can see, we have set the Request Headers here, including:

  • 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.

We have also set the Request Body, including:

  • image: The Base64-encoded CAPTCHA image.
  • question: The question ID. Please refer to the table; it starts with /m/.

After making the selections, you can see that the corresponding code has also been generated on the right, as shown below:

Click the "Try" button to test it. As shown above, we get the following result:

{
  "solution": {
    "size": 300,
    "label": "/m/01pns0",
    "confidences": [
      0,
      0.0007,
      1,
      0.0003,
      0.0046,
      1,
      0,
      1,
      0
    ],
    "objects": [
      2,
      5,
      7
    ],
    "type": "multi"
  }
}

The returned result contains several fields, described below:

  • solution: The verification result after processing this Recaptcha2 CAPTCHA image task.
    • size: The dimensions of the Recaptcha2 CAPTCHA image.
    • label: The content recognized in the Recaptcha2 CAPTCHA image.
    • confidences: The confidence levels of the recognition regions in the Recaptcha2 CAPTCHA image. Regions are numbered starting from 0.
    • objects: The regions in the Recaptcha2 CAPTCHA image that match the recognition target. Regions are numbered starting from 0.
    • type: The type of this Recaptcha2 CAPTCHA image task. It is multi when there are multiple regions.
  • started_at, finished_at: The times when this request began processing and produced a result, as Unix timestamps (seconds, floating-point).
  • elapsed: The total processing time for this request (seconds).

As you can see, we have obtained the verification result for processing the Recaptcha2 CAPTCHA image. First, we divide the CAPTCHA image into regions, as shown below:

As you can see, the regions are numbered starting from 0. From objects in the result, we obtained 2, 5, and 7. We only need to simulate clicks on these three regions of the CAPTCHA to pass verification.

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/recognition/recaptcha2' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "question": "/m/01pns0",
  "image": "iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAIAAAD7AWllAAAAAX..."
}'

The Python integration code is as follows:

import requests

url = "https://api.acedata.cloud/captcha/recognition/recaptcha2"

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

payload = {
    "question": "/m/01pns0",
    "image": "iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAIAAAD7AWllAAAAAX..."
}

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 the recognition result has been processed before returning. If you are using multi-solver rotation and want to “receive a task_id immediately after submitting a task, schedule other solvers first, and return later to read the result,” you can pass async: true in the request body.

After you pass async: true, the API immediately returns a task_id without blocking and waiting:

curl -X POST 'https://api.acedata.cloud/captcha/recognition/recaptcha2' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "question": "/m/01pns0",
  "image": "iVBORw0KGgoAAAANSUhEUgAAASoAAAEsCAIAAAD7AWllAAAAAX...",
  "async": true
}'
{
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002",
  "trace_id": "2efa9340-b21b-4e26-9e14-4aac95f343ab"
}

To check progress, 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:

{ "success": true, "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002", "status": "processing" }

When processing is complete, it returns status: ready and the recognition result solution (the field structure is identical to that of synchronous mode):

{
  "success": true,
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002",
  "status": "ready",
  "solution": {
    "size": 300,
    "label": "/m/01pns0",
    "objects": [2, 5, 7],
    "type": "multi"
  }
}

Billing notes: In asynchronous mode, creating a task and reading the “processing” status are not billed; a charge is applied once 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 in advance simply because processing finishes in the background. A task that does not succeed within 120 seconds terminates with HTTP 504 timeout and is not billed. /captcha/tasks is not responsible for advancing the task.

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 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 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.

Example error response

{
  "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 Recaptcha2 image recognition API to have users input the content to be recognized and the Recaptcha2 CAPTCHA image, and finally return the coordinates of the small images that need to be clicked to complete verification. 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.