hCaptcha Image Recognition API Integration Guide

This article introduces an hCaptcha image recognition API integration method that takes the recognition prompt and hCaptcha verification image provided by the user and returns the coordinates of the small image to click to complete verification.

Application Process

To use the hCaptcha image recognition API, first obtain your API Token from the Ace Data Cloud Console and keep it 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 automatically return to the current page.

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

Basic Usage

First, let's look at the basic usage: provide the hCaptcha verification image to be processed, and you can obtain the processed result. First, you need to pass a queries field, which contains the hCaptcha verification image. We need to capture this verification image from a website with hCaptcha verification. An example website is: https://democaptcha.com/demo-form-eng/hcaptcha.html. Click the checkbox to display the complete verification image, as shown below:

The queries field contains a screenshot of the verification image above. The recommended image size is no more than 100 KB. You also need to capture the area indicated by the red arrow in the image above, compress the image yourself, and convert it to Base64 encoding, as shown below:

You also need to provide the question parameter containing the recognition prompt related to the verification image. It supports Chinese and English, so you can directly provide the relevant recognition prompt. From the content indicated by the yellow arrow in the webpage image above, you can see that the input for question should be Please click on the UNIQUE object among the others.. The details are as follows:

You can see that we have set the Request Headers here, including:

  • accept: The desired response format, set here to application/json, meaning JSON format.
  • authorization: The key used to call the API, which can be selected directly from the dropdown after applying.

We also set the Request Body, including:

  • queries: A list of Base64-encoded verification images.
  • question: The recognition prompt related to the verification image, supporting direct input in Chinese or English.

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

Click the “Try” button to run a test. As shown above, we obtained the following result:

{
  "solution": {
    "label": "Please click on the UNIQUE object among the others",
    "box": [
      "360",
      "276"
    ],
    "confidences": 0.6354503631591797
  }
}

The returned result contains multiple fields, described below:

  • solution: The verification result after processing this hCaptcha verification image task.
    • label: The recognized content of the hCaptcha verification image.
    • box: The location information of the hCaptcha verification image recognition result, consisting of image coordinates.
    • confidences: The confidence that the recognized hCaptcha verification image matches the recognition prompt.
  • 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 (seconds).

You can see that we obtained the verification result for the hCaptcha verification image. We only need to simulate a click on the corresponding area of the verification image according to the coordinates in box to pass verification.

Next, we will explain how to click using the location information in the result's box. First, establish a Cartesian coordinate system for the uploaded verification image, with the origin at the bottom-left corner of the image. 360 is the corresponding horizontal coordinate, and 276 is the corresponding vertical coordinate. We only need to simulate a click at the corresponding coordinates on the verification image, as shown below:

Additionally, 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/hcaptcha' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "question": "Please click on the UNIQUE object among the others.",
  "queries": ["iVBORw0KGgoAAAANSU.....eY+85KVlzKHav28uq/WLVhL2kHUlFMKUcZbL31S8bpd0pEPKxNllXAE2wgu3uEfj+BfAzOGelsQNFAAAAAElFTkSuQmCC"]
}'
}'

The Python integration code is as follows:

import requests

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

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

payload = {
    "question": "Please click on the UNIQUE object among the others.",
    "queries": ["iVBORw0KGgoAAAANSU.....eY+85KVlzKHav28uq/WLVhL2kHUlFMKUcZbL31S8bpd0pEPKxNllXAE2wgu3uEfj+BfAzOGelsQNFAAAAAElFTkSuQmCC"]
}

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 finished processing before returning. If you are implementing multi-solver rotation and want to “receive the 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 passing async: true, the API immediately returns a task_id without blocking and waiting:

curl -X POST 'https://api.acedata.cloud/captcha/recognition/hcaptcha' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "question": "Please click on the UNIQUE object among the others.",
  "queries": ["iVBORw0KGgoAAAANSU.....eY+85KVlzKHav28uq/WLVhL2kHUlFMKUcZbL31S8bpd0pEPKxNllXAE2wgu3uEfj+BfAzOGelsQNFAAAAAElFTkSuQmCC"],
  "async": true
}'
{
  "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 (every 3–5 seconds is recommended). This endpoint does not trigger or advance task processing; even if you do not query, disconnect from the network, or exit the client, the server will continue processing:

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, status: processing is returned:

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

Once processing is complete, status: ready and the recognition result solution are returned (the field structure is exactly the same as in synchronous mode):

{
  "success": true,
  "task_id": "61138bb6-19aa-11ec-a9c8-0242ac110002",
  "status": "ready",
  "solution": {
    "label": "Please click on the UNIQUE object among the others",
    "box": ["360", "276"],
    "confidences": 0.6354503631591797
  }
}

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 tasks independently, but does not charge in advance just because processing finishes in the background. A task that does not succeed within 120 seconds terminates with HTTP 504 timeout and is not charged. /captcha/tasks is not responsible for advancing tasks.

Error Handling

When calling the API, if an error occurs, the API will return 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.

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 hCaptcha image recognition API to have users enter the content to be recognized and the hCaptcha image, and finally return the coordinates of the small image that needs 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.