solveTask
Create a CAPTCHA task and receive its result in one request with solveTask, which waits up to 80 seconds and charges exactly as createTask does.
solveTask takes the createTask body, waits up to 80 seconds for the task to finish, and answers with the getTaskResult body. It charges exactly as createTask does.
https://api.anysolver.com /solveTaskSync or async
solveTask creates the same task createTask would, with the same charge, routing, Auto Retry, Auto Fallback and limits. Only the way you collect the result changes:
- POST /createTaskreturnstaskIdanswers at once
- POST /getTaskResultreturnsprocessingrepeat, as often as every 0.5 s
- POST /getTaskResultreturnsready + solutionon the first poll after the solve
- POST /solveTaskreturnsconnection heldwhile the task runs
- same requestreturnsready + solutionthe moment the task finishes
- after about 80 sreturnsprocessing + taskIdthen poll getTaskResult
| Flow | Use it when |
|---|---|
createTask, then getTaskResult | By default. No connection stays open while a task runs, a network drop or restart on your side loses nothing, and any HTTP client timeout works. |
solveTask | A user or a browser session waits on the solve. The answer arrives when the task finishes, with no polling interval added. |
Authentication
Send your API key as clientKey in the JSON body, with the header Content-Type: application/json. A missing clientKey returns VALIDATION_ERROR, and an unknown key returns ERROR_KEY_DOES_NOT_EXIST.
Request body
The body is the same as for createTask. Every field, settings option and proxy format works as described on createTask, and each task type's fields are on its page under Tasks.
| Field | Type | Required | Description |
|---|---|---|---|
clientKey* | string | Yes | Your API key. Create one in a workspace of the AnySolver dashboard. |
task* | object | Yes | The task body. Required fields depend on the task type. See Tasks for per-task schemas. |
settings | object | No | Per-request settings for routing, Auto Retry, Auto Fallback, proxy reuse, response statistics and detailed analytics. Each field overrides the API key's value. See Routing modes. |
solveTask accepts a body of up to 32 MiB, the same as createTask (Request size lists every endpoint). A larger body returns VALIDATION_ERROR with Request body exceeds the maximum allowed size., before any charge.
Example
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ReCaptchaV2TokenProxyLess",
"websiteURL": "https://example.com",
"websiteKey": "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI",
"pageTitle": "Example Domain"
}
}Response body
The body is the same as for getTaskResult. Branch on status:
status | Meaning | Next step |
|---|---|---|
ready | The task is solved. solution and cost are set. | Use the solution. |
failed | The task failed, or the request was refused before a task existed. A refused request has no taskId. | Read errorCode; see Errors. |
processing | The wait ended before the task finished; see How long it waits. | Poll getTaskResult with taskId. |
| Field | Type | Required | Description |
|---|---|---|---|
status* | Yes | Task status: "processing", "ready", or "failed". Example: | |
errorId* | Yes |
Example: | |
taskId | string | No | Unique identifier returned when the task was created. Example: |
errorCode | No | Machine-readable error code. Example: | |
errorDescription | string | No | Human-readable error message with resolution hints. Example: |
cost | number | No | Actual cost charged for this task in USD. Example: |
taskType | No | The type of CAPTCHA task to solve. Example: | |
provider | No | Provider that handled this task. While processing, the provider currently solving it. Example: |
How long it waits
solveTask holds the request for up to 80 seconds from its arrival, then answers with status: "processing" and the taskId. The wait also ends early, with the same answer, when the AnySolver server restarts. The task keeps running either way and finishes within the same 30-minute lifetime as any other task.
{
"errorId": 0,
"status": "processing",
"taskId": "01KFNDF328KAN2AJ3BNHCQYE88"
}Set your HTTP client's timeout to at least 90 seconds, so the connection stays open until AnySolver answers.
Set your HTTP timeout to at least 90 seconds
If your client closes the connection before AnySolver answers, you never receive the taskId. The task still runs
and is still charged if it succeeds. Many HTTP clients default to 30 or 60 seconds.
Full example
This program calls solveTask with a 90-second timeout, and polls getTaskResult when the answer is processing:
const API_URL = 'https://api.anysolver.com';
const API_KEY = 'YOUR_API_KEY';
// Longer than solveTask's wait of about 80 seconds, so its answer always arrives.
const SOLVE_TIMEOUT_MS = 90_000;
const POLL_INTERVAL_MS = 1_000;
const POLL_TIMEOUT_MS = 31 * 60_000;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function call(endpoint, params, timeoutMs = 30_000) {
const response = await fetch(`${API_URL}/${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ clientKey: API_KEY, ...params }),
signal: AbortSignal.timeout(timeoutMs),
});
const data = await response.json();
if (data.errorId !== 0) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
return data;
}
async function solve(task) {
let result = await call('solveTask', { task }, SOLVE_TIMEOUT_MS);
// Still running after the wait: continue exactly like the createTask flow.
const deadline = Date.now() + POLL_TIMEOUT_MS;
while (result.status === 'processing' && Date.now() < deadline) {
await sleep(POLL_INTERVAL_MS);
result = await call('getTaskResult', { taskId: result.taskId });
}
if (result.status !== 'ready') throw new Error(`Task ${result.taskId} did not finish in time`);
return result.solution;
}
solve({
type: 'ReCaptchaV2TokenProxyLess',
websiteURL: 'https://www.google.com/recaptcha/api2/demo',
websiteKey: '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-',
pageTitle: 'ReCAPTCHA demo',
}).then((solution) => console.log('Token:', solution.token));Errors
A refused request returns the same codes as createTask, with status: "failed" added and no taskId. A refused request is not charged. A task that fails returns the same codes as getTaskResult, with its taskId. Errors arrive with HTTP 200, so branch on errorId and status. Every code: Error handling.
Related
POSTgetTaskResult
Poll getTaskResult with a taskId to read the task status and, once it is ready, its solution and final cost. Polling is free, only the task is charged.
POSTgetBalance
Read your organization balance in USD with getBalance. One balance pays for tasks on every provider, and checking it is free and needs only your API key.