getTaskResult
POST /getTaskResult returns a task's status and, once it's ready, its solution.
POST https://api.peak.fo/getTaskResult
Returns whether a task from createTask is still being solved, and its solution once it's ready. Poll it every 3 to 5 seconds.
Request
| Field | Type | Required | Description |
|---|---|---|---|
clientKey | string | Yes | Your API key. Any key on the account that created the task works. |
taskId | number, string | Yes | The taskId from createTask. A number may also be sent as a string. |
curl https://api.peak.fo/getTaskResult \
-H "Content-Type: application/json" \
-d '{"clientKey": "pk_your_api_key", "taskId": 4826153907261}'Response
| Field | Type | Description |
|---|---|---|
errorId | number | 0 if the request worked. |
status | string | processing while solving, ready when the solution is in. |
solution | object | Only when ready. Its fields are below. |
cost | string | Only when ready. What the solve was charged, in USD, as a string. |
createTime | number | Only when ready. When the task was created, as a Unix time in seconds. |
endTime | number | Only when ready. When the solve finished, as a Unix time in seconds. |
solveCount | number | Only when ready. Always 1. |
taskId | string | Only when ready, for CapSolver tasks. The task's id. |
Solution
| Task | solution fields |
|---|---|
| Turnstile | token: the Turnstile token. |
| 5-second challenge, CapMonster code | cf_clearance: the cookie value. userAgent: the user-agent the cookie is bound to. |
| 5-second challenge, CapSolver code | cookies: every cookie set, including cf_clearance. token: the cf_clearance value. userAgent. |
Send the cookie with the same userAgent, through the same proxy you gave the task. Cloudflare checks both.
{
"errorId": 0,
"status": "processing"
}A failed solve isn't charged. errorDescription says why it failed, in the same words as the native API's error. See Error codes for how failures map to errorCode.
Task not found
ERROR_NO_SUCH_CAPCHA_ID (CapSolver code: ERROR_TASKID_INVALID) means one of these:
- The
taskIdis wrong. - The task finished more than 5 minutes ago and was removed.
- Peak Solutions restarted since you created it.
- It belongs to another account.
Create a new task. If the solve had already finished, it was charged.
A complete loop
import time
import requests
API = "https://api.peak.fo"
API_KEY = "pk_your_api_key"
def solve_turnstile(url: str, sitekey: str) -> str:
"""Creates a Turnstile task and polls until it has a token."""
created = requests.post(
f"{API}/createTask",
json={
"clientKey": API_KEY,
"task": {"type": "TurnstileTaskProxyless", "websiteURL": url, "websiteKey": sitekey},
},
timeout=30,
).json()
if created["errorId"] != 0:
raise RuntimeError(f"{created['errorCode']}: {created['errorDescription']}")
for _ in range(40):
time.sleep(3)
result = requests.post(
f"{API}/getTaskResult",
json={"clientKey": API_KEY, "taskId": created["taskId"]},
timeout=30,
).json()
if result["errorId"] != 0:
raise RuntimeError(f"{result['errorCode']}: {result['errorDescription']}")
if result["status"] == "ready":
return result["solution"]["token"]
raise TimeoutError("no result after 2 minutes")
if __name__ == "__main__":
print(solve_turnstile("https://example.com/login", "0x4AAAAAAA..."))