createTask
createTask creates a recognition task; task.type says which captcha to solve. Asynchronous types return a taskId that you then pass to getTaskResult; synchronous types return the result directly. The task is charged when it is created successfully, and your balance must be above 10 points.
POST
https://api.yescaptcha.com/createTaskGlobal endpointPOST
https://cn.yescaptcha.com/createTaskChina endpointRequest fields
Section titled “Request fields”| Field | Type | Required | Description |
|---|---|---|---|
clientKey |
string | Yes | Your account key, copied from the yescaptcha.com dashboard |
task |
object | Yes | The task object. It must contain type; other fields depend on the task type (see each task type page) |
softID |
integer | No | A developer ID. Include yours when other people use your software to receive a revenue share; see Developer revenue share |
Request examples
Section titled “Request examples”Read an image captcha (synchronous):
{ "clientKey": "YOUR_CLIENT_KEY", "task": { "type": "ImageToTextTaskOcrBase", "body": "BASE64_IMAGE" }}Get a reCAPTCHA v2 token (asynchronous):
{ "clientKey": "YOUR_CLIENT_KEY", "task": { "type": "NoCaptchaTaskProxyless", "websiteURL": "https://www.google.com/recaptcha/api2/demo", "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" }}The task fields of each type are on the pages under Task types and pricing.
Response
Section titled “Response”Asynchronous types:
{ "errorId": 0, "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006" }Keep the taskId and start calling getTaskResult 5 seconds later.
Synchronous types:
{ "errorId": 0, "status": "ready", "taskId": "2376919c-1863-11ec-a012-94e6f7355a0b", "solution": { "text": "LMResm" }}Failure:
{ "errorId": 1, "errorCode": "ERROR_TASK_NOT_SUPPORTED", "errorDescription": "任务类型不正确或不受支持" }Order of checks
Section titled “Order of checks”The server checks a request in this order and returns the first error it finds. None of these are charged:
- The body is valid JSON:
ERROR_REQUEST_FORMATS clientKeyis present:ERROR_REQUIRED_FIELDSclientKeyexists:ERROR_KEY_DOES_NOT_EXIST- The key is not paused:
ERROR_IP_BLOCKED_5MIN(see Rate limits) - The balance is above 10 points:
ERROR_ZERO_BALANCE taskis present:ERROR_TASK_ABSENTtask.typeexists:ERROR_TASK_NOT_SUPPORTED- All required fields are present:
ERROR_REQUIRED_FIELDS(errorDescriptionnames the missing field) - For image tasks, the image is valid:
ERROR_ZERO_CAPTCHA_FILESIZE,ERROR_IMAGE_TYPE_NOT_SUPPORTEDand others
Complete example
Section titled “Complete example”Create a task and poll for the result (asynchronous type):
curl -s https://api.yescaptcha.com/createTask \ -H 'Content-Type: application/json' \ -d '{ "clientKey": "YOUR_CLIENT_KEY", "task": { "type": "NoCaptchaTaskProxyless", "websiteURL": "https://www.google.com/recaptcha/api2/demo", "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" }}'
# Returns {"errorId":0,"taskId":"..."}; then poll every 5 seconds:curl -s https://api.yescaptcha.com/getTaskResult \ -H 'Content-Type: application/json' \ -d '{"clientKey": "YOUR_CLIENT_KEY", "taskId": "TASK_ID"}'import osimport time
import requests
API = "https://api.yescaptcha.com"CLIENT_KEY = os.environ["YESCAPTCHA_CLIENT_KEY"] # Read the clientKey from an environment variable
def call(method, payload): r = requests.post(f"{API}/{method}", json={"clientKey": CLIENT_KEY, **payload}, timeout=30) data = r.json() if data.get("errorId"): raise RuntimeError(f"{data.get('errorCode')}: {data.get('errorDescription')}") return data
def solve(task): task_id = call("createTask", {"task": task})["taskId"] for _ in range(36): # Poll every 5 seconds, for up to about 3 minutes time.sleep(5) result = call("getTaskResult", {"taskId": task_id}) if result.get("status") == "ready": return result["solution"] raise TimeoutError(task_id)
solution = solve({ "type": "NoCaptchaTaskProxyless", "websiteURL": "https://www.google.com/recaptcha/api2/demo", "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",})print(solution["gRecaptchaResponse"])const API = 'https://api.yescaptcha.com';const CLIENT_KEY = process.env.YESCAPTCHA_CLIENT_KEY; // Read the clientKey from an environment variable
async function call(method, payload) { const res = await fetch(`${API}/${method}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientKey: CLIENT_KEY, ...payload }), }); const data = await res.json(); if (data.errorId) throw new Error(`${data.errorCode}: ${data.errorDescription}`); return data;}
async function solve(task) { const { taskId } = await call('createTask', { task }); for (let i = 0; i < 36; i++) { // Poll every 5 seconds, for up to about 3 minutes await new Promise((r) => setTimeout(r, 5000)); const result = await call('getTaskResult', { taskId }); if (result.status === 'ready') return result.solution; } throw new Error(`timeout: ${taskId}`);}
const solution = await solve({ type: "NoCaptchaTaskProxyless", websiteURL: "https://www.google.com/recaptcha/api2/demo", websiteKey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",});console.log(solution.gRecaptchaResponse);