Skip to main content
This article will introduce a method for integrating the hCaptcha image recognition API, which can identify the content entered by the user and the hCaptcha verification image, and finally return the coordinates of the small image that needs to be clicked to complete the verification.

Application Process

To use the API, you need to first apply for the corresponding service on the hCaptcha Image Recognition API page. After entering the page, click the “Acquire” button, as shown in the image below: If you are not logged in or registered, you will be automatically redirected to the login page inviting you to register and log in. After logging in or registering, you will be automatically returned to the current page. There is a free quota available for first-time applicants, allowing you to use the API for free.

Basic Usage

First, understand the basic usage method, which is to input the hCaptcha verification image that needs to be processed to obtain the processed result. You need to simply pass a queries field, which is the specific hCaptcha verification image. We need to capture this verification image from a website with hCaptcha verification; an example website link is: https://democaptcha.com/demo-form-eng/hcaptcha.html. Click the checkbox to display the complete verification image, as shown in the image below:

The queries field is a screenshot of the verification image mentioned above. It is recommended that the image size does not exceed 100kb. You also need to take a screenshot of the area indicated by the red arrow in the image above, compress the image size, and convert it to Base64 encoding, as shown in the image below:

You also need to input the recognition content parameter question related to the verification image. This supports translation in both Chinese and English, and you can directly input the relevant recognition content. From the content executed by the yellow arrow in the image above, the question input should be Please click on the UNIQUE object among the others. The specific content is as follows:

Here we can see that we have set the Request Headers, including:
  • accept: the format of the response result you want to receive, here filled in as application/json, which is JSON format.
  • authorization: the key for calling the API, which can be selected directly after application.
Additionally, the Request Body is set, including:
  • queries: a list of Base64 encoded verification images.
  • question: the recognition content parameter related to the verification image, supporting direct input in Chinese and English.
After selection, you can find that the corresponding code is also generated on the right side, as shown in the image below:

Click the “Try” button to conduct a test, as shown in the image above. Here 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 as follows:
  • solution, the verification result after processing the hCaptcha verification image task.
    • label, the content recognized from the hCaptcha verification image.
    • box, the location information of the recognition result of the hCaptcha verification image, which is composed of the coordinate information of the image.
    • confidences, the confidence level of the recognition content satisfied after recognizing the hCaptcha verification image.
We can see that we have obtained the verification result for processing the hCaptcha verification image. We only need to simulate a click in the area corresponding to the coordinates in the box position information of the result to pass the verification. Next, we will introduce how to click based on the position information of the box in the result. First, establish a right-angle coordinate system for the uploaded verification image, where the center origin is at the lower left corner of the image. The value 360 corresponds to the horizontal coordinate, and 276 corresponds to the vertical coordinate. We only need to simulate a click at the coordinates corresponding to the verification code, as shown in the image below:

If you want to generate the corresponding integration code, you can directly copy it, 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)

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 allow users to input the recognized content and the hCaptcha verification image, and finally return the coordinates of the small image that needs to be clicked to complete the verification. We hope this document can help you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.