Docs / Guides
Examples
Use createTask and getTaskResult with PowerShell, Python and Node.js examples. Follow per-service Playwright scripts to apply solutions and check responses.
There is no official SDK: the API is three POST endpoints with a JSON body, and every snippet on this site is plain HTTP or a standard library. The examples on this page are generated from the same source as the ones in the API reference, so they never describe a different request than the reference does.
The variants
- PowerShell — the two calls with
Invoke-RestMethod; the reply hands you thetaskIdyou continue with. - Python —
requests, a smallcall()helper that raises onerrorId: 1, then asolve()function that polls. - Node.js —
fetchandnode:timers/promises, no dependencies. - Playwright — shown for the services that have an integration script. It takes its settings from the constants listed at the top, finds the site key and script URLs on the live page, solves the task, applies the result in a fresh browser context and checks that the site accepted it.
Replace the example API key, the websiteURL, the site key and any proxy placeholders in
the first three with your own values before running one. The Playwright script needs one
edit: paste your key into the constant at the top and run it.
Applying the solution
Tokens are single-use and short-lived: read them from solution and put them into the
request that the page makes immediately. Cookie-producing types are different — the
cookie is bound to the IP and user agent that earned it, so replay it from the same
proxy session. Proxies lists the modes per type.
Where the per-type examples live
Open POST /createTask in the API reference: its right-hand panel carries a
request example for every task type, each with the exact fields that type
takes. The same data is available as JSON — GET /v1/task-types (public, no key) lists
every accepted name with its proxy mode, its required and optional fields and the keys the
solution returns. The guides explain the flow around them.
A complete example
Every tab is generated from the same source as the examples in theAPI reference. The PowerShell, Python and Node.js tabs run against https://api.sursolver.com once your key and the fields for your site are in place (GET /v1/task-types lists them); the Playwright tab, where there is one, declares every setting as a constant at the top of the script.
$api = 'https://api.sursolver.com'
$key = 'sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# 1/2 Create the task. API errors are HTTP 200 with errorId 1; a thrown request is a transport failure.
$task = @{
type = 'ReCaptchaV3TokenProxyLess'
websiteURL = 'https://example.com/login'
websiteKey = '6Le...'
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36'
}
$request = @{ clientKey = $key; task = $task } | ConvertTo-Json -Depth 10
$created = Invoke-RestMethod -Method Post -Uri "$api/createTask" -ContentType 'application/json' -Body $request
if ($created.errorId -ne 0) { Write-Error $created.errorDescription; exit 1 }
# 2/2 Poll getTaskResult until the task is ready (60 tries, 3 s apart).
for ($attempt = 0; $attempt -lt 60; $attempt += 1) {
$poll = @{ clientKey = $key; taskId = $created.taskId } | ConvertTo-Json -Depth 10
$result = Invoke-RestMethod -Method Post -Uri "$api/getTaskResult" -ContentType 'application/json' -Body $poll
if ($result.errorId -ne 0) { Write-Error $result.errorDescription; exit 1 }
if ($result.status -eq 'ready') { $result.solution; exit 0 }
Start-Sleep -Seconds 3
}
Write-Error "task $($created.taskId) was not ready after 60 polls"
exit 1import time
import requests
CLIENT_KEY = "sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
API = "https://api.sursolver.com"
POLL_ATTEMPTS = 60
def call(path, body):
# API errors are HTTP 200 with errorId 1; anything else is a transport failure.
response = requests.post(f"{API}{path}", json=body, timeout=30)
response.raise_for_status()
data = response.json()
if data["errorId"] != 0:
raise RuntimeError(f'{data["errorCode"]}: {data["errorDescription"]}')
return data
def solve(task):
created = call("/createTask", {"clientKey": CLIENT_KEY, "task": task})
for _ in range(POLL_ATTEMPTS):
result = call("/getTaskResult", {"clientKey": CLIENT_KEY, "taskId": created["taskId"]})
if result["status"] == "ready":
return result["solution"]
time.sleep(3)
raise TimeoutError(f'task {created["taskId"]} was not ready in {POLL_ATTEMPTS} polls')
solution = solve({
"type": "ReCaptchaV3TokenProxyLess",
"websiteURL": "https://example.com/login",
"websiteKey": "6Le...",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36",
})
print(solution)const { setTimeout: sleep } = require('node:timers/promises');
const CLIENT_KEY = 'sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const API = 'https://api.sursolver.com';
const POLL_ATTEMPTS = 60;
// API errors are HTTP 200 with errorId 1; anything else is a transport failure.
async function call(path, body) {
const res = await fetch(`${API}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.errorId !== 0) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
return data;
}
async function solve(task) {
const created = await call('/createTask', { clientKey: CLIENT_KEY, task });
for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt += 1) {
const result = await call('/getTaskResult', {
clientKey: CLIENT_KEY,
taskId: created.taskId,
});
if (result.status === 'ready') return result.solution;
await sleep(3000);
}
throw new Error(`task ${created.taskId} was not ready in ${POLL_ATTEMPTS} polls`);
}
solve({
type: 'ReCaptchaV3TokenProxyLess',
websiteURL: 'https://example.com/login',
websiteKey: '6Le...',
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36',
}).then(
(solution) => console.log(solution),
(error) => {
console.error(error);
process.exitCode = 1;
},
);// recaptcha-v3-playwright.js - solve reCAPTCHA v3 on the live page and submit the form with the
// token.
// Install: npm install playwright && npx playwright install chromium
// Run: node recaptcha-v3-playwright.js
const { chromium } = require('playwright');
const { setTimeout: sleep } = require('node:timers/promises');
// Your SurSolver API key.
const CLIENT_KEY = 'sur_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// The page that renders the widget, with its path and query string.
const TARGET_URL = 'https://example.com/page';
// Optional, read from the page when empty: the render= value of the api.js or enterprise.js
// script URL.
const SITE_KEY = '';
// The action in the page's grecaptcha.execute(key, { action }) call.
const PAGE_ACTION = 'YOUR_PAGE_ACTION';
// Enterprise only: 0.3 or below answers fastest, higher runs a second execute.
const MIN_SCORE = undefined;
// The User-Agent the solve runs with; send the result with this same user agent.
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36';
// The control that submits the form.
const SUBMIT_SELECTOR = '.PASTE_SUBMIT_SELECTOR';
// A selector that matches only after the site accepted the result.
const SUCCESS_SELECTOR = '.PASTE_ACCEPTED_SELECTOR';
const API = 'https://api.sursolver.com';
const POLL_ATTEMPTS = 60;
// API errors are HTTP 200 with errorId 1; anything else is a transport failure.
async function call(path, body) {
const res = await fetch(`${API}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.errorId !== 0) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
return data;
}
async function solve(task) {
const created = await call('/createTask', { clientKey: CLIENT_KEY, task });
for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt += 1) {
const result = await call('/getTaskResult', {
clientKey: CLIENT_KEY,
taskId: created.taskId,
});
if (result.status === 'ready') return result.solution;
await sleep(3000);
}
throw new Error(`task ${created.taskId} was not ready in ${POLL_ATTEMPTS} polls`);
}
// Optional task fields are sent only when they have a value.
function withoutEmpty(fields) {
return Object.fromEntries(
Object.entries(fields).filter(([, value]) => value !== undefined && value !== ''),
);
}
// A value the page did not show must be pasted into its constant at the top.
function need(name, value) {
if (value === undefined || value === null || value === '') {
throw new Error(`Could not read ${name} from the page; fill in the ${name} constant.`);
}
return value;
}
// Opens the page once and reads what the solve needs from it.
async function readPage(browser) {
const page = await browser.newPage({ userAgent: USER_AGENT });
try {
await page.goto(TARGET_URL, {
waitUntil: 'domcontentloaded',
timeout: 45000,
});
// The widget is often added after the page loads; give it a moment to appear.
await page
.waitForFunction(
() =>
!!(() => {
const src = [...document.scripts]
.map((script) => script.src)
.find((url) => /recaptcha\/(api|enterprise)\.js\?.*render=/.test(url));
const key = src ? new URL(src).searchParams.get('render') : null;
const fallback = document.querySelector('[data-sitekey]')?.dataset.sitekey;
return key && key !== 'explicit' ? key : fallback;
})(),
undefined,
{ timeout: 10000 },
)
.catch(() => undefined);
const dom = await page.evaluate(() => ({
websiteKey: (() => {
const src = [...document.scripts]
.map((script) => script.src)
.find((url) => /recaptcha\/(api|enterprise)\.js\?.*render=/.test(url));
const key = src ? new URL(src).searchParams.get('render') : null;
const fallback = document.querySelector('[data-sitekey]')?.dataset.sitekey;
return key && key !== 'explicit' ? key : fallback;
})(),
}));
return {
pageUrl: page.url(),
...dom,
};
} finally {
await page.close();
}
}
async function main() {
const browser = await chromium.launch();
try {
const found = await readPage(browser);
const solution = await solve({
type: 'ReCaptchaV3TokenProxyLess',
websiteURL: found.pageUrl,
websiteKey: need('websiteKey', SITE_KEY || found.websiteKey),
pageAction: PAGE_ACTION,
userAgent: USER_AGENT,
...withoutEmpty({
minScore: MIN_SCORE,
}),
});
// Submit from a fresh session with the user agent the solve ran with.
const context = await browser.newContext({ userAgent: USER_AGENT });
const page = await context.newPage();
await page.goto(found.pageUrl);
// reCAPTCHA defines execute() a moment after the page loads.
await page.waitForFunction(
() => typeof window.grecaptcha?.execute === 'function',
undefined,
{ timeout: 15000 },
);
const applied = await page.evaluate(
({ token }) => {
const api = window.grecaptcha;
if (!api || typeof api.execute !== 'function') return false;
// The page now receives the solved token wherever it calls execute().
api.execute = () => Promise.resolve(token);
for (const field of document.querySelectorAll('[name="g-recaptcha-response"]')) {
field.value = token;
}
return true;
},
{ token: solution.gRecaptchaResponse },
);
if (!applied) {
throw new Error('The page has no reCAPTCHA API; check how it requests the token.');
}
await page.click(SUBMIT_SELECTOR);
await page.locator(SUCCESS_SELECTOR).first().waitFor({ timeout: 15000 });
console.log('The site accepted the token.');
} finally {
await browser.close();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});