import time, requests
class UnlockAPI:
def __init__(self, key, base="https://unlock-api.com"):
self.key, self.base = key, base
def _post(self, method, **body):
r = requests.post(f"{self.base}/{method}", json={"clientKey": self.key, **body}, timeout=30).json()
if r.get("errorId"):
raise RuntimeError(r.get("errorCode")) # failed tasks are refunded
return r
def balance(self):
return self._post("getBalance")["balance"]
def solve(self, task, timeout=300):
task_id = self._post("createTask", task=task)["taskId"]
end = time.time() + timeout
while time.time() < end:
time.sleep(5)
r = self._post("getTaskResult", taskId=task_id)
if r["status"] == "ready":
return r["solution"]
raise TimeoutError(task_id)Usage
api = UnlockAPI("YOUR_API_KEY")
sol = api.solve({"type": "TurnstileTaskProxyless", "websiteURL": "https://example.com", "websiteKey": "0x4AAAA..."})
print(sol["token"])Using a library you already have
Most solver libraries let you change the server address. Set it to unlock-api.com (or https://unlock-api.com/in.php for the form API) and use your UNLOCK API key. Task names and answers are the same.