NeuroCaptcha

Code examples

Complete clients in Python, Node.js, TypeScript, Go, PHP, C#, Java and cURL: create a task, poll the result, handle errors.

本节内容以英文显示。

本页内容

Each example creates a reCAPTCHA v2 task, polls it every 2 seconds and prints the token. Run them with a test key: it is free and the answer comes in a couple of seconds.

Shell
export API_KEY=0123456789abcdef0123456789abcdef  # your key

Complete examples#

import os
import time

import requests

API = "https://neurocaptcha.com"
KEY = os.environ["API_KEY"]


def call(method, payload):
    data = requests.post(f"{API}/{method}", json={"clientKey": KEY, **payload}, timeout=30).json()
    if data.get("errorId"):
        raise RuntimeError(f'{data["errorCode"]}: {data.get("errorDescription", "")}')
    return data


task = {
    "type": "RecaptchaV2TaskProxyless",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
}

# 1. create the task: its price is held, not charged
task_id = call("createTask", {"task": task})["taskId"]

# 2. poll every 2 s; a failed task raises with its error code and costs nothing
deadline = time.time() + 300
while time.time() < deadline:
    time.sleep(2)
    result = call("getTaskResult", {"taskId": task_id})
    if result["status"] == "ready":
        print(result["solution"]["gRecaptchaResponse"])
        break
else:
    raise TimeoutError("the task was not solved in time")

Requirements#

LanguageNeeds
PythonPython 3.8+, pip install requests
Node.jsNode.js 18+ (built-in fetch); save as .mjs
TypeScriptNode.js 23.6+ runs .mts directly; or tsx, Deno, Bun
GoGo 1.21+, standard library only (the webhook example needs 1.22+)
PHPPHP 7.4+ with the curl extension
C#.NET 6+
JavaJava 11+ and Jackson (com.fasterxml.jackson.core:jackson-databind)
cURLany version; shown as two separate requests

Other task types#

Only the task object changes. For example, reCAPTCHA v3 — the parameters of every type are in Task types:

task
{
  "type": "RecaptchaV3TaskProxyless",
  "websiteURL": "https://example.com/login",
  "websiteKey": "YOUR_SITE_KEY",
  "pageAction": "login",
  "minScore": 0.7
}

Single requests#

Every method page has a ready request in all languages: createTask, getTaskResult, getBalance, getQueueStats, getSpendingStats, getTaskTypes, reports.

Using the token#

Put the token where the page expects it and submit the form the usual way. For reCAPTCHA v2 that is the hidden g-recaptcha-response field; if the widget has data-callback, call that function with the token. For v3 look at how the page sends the token (a form field or a request parameter).

Browser automation (page context)
document.querySelector('[name="g-recaptcha-response"]').value = token;
document.querySelector("form").submit();

Webhook receivers#

Signature checks in Python, Node.js, Go and PHP are on the Webhooks page.