Python Integration
Full Python integration with requests.
Install
pip install requests
Minimal example (submit + poll)
import time, requests
API = "https://api.vexsolver.com"
KEY = "sk_live_..."
HEADERS = {"X-API-Key": KEY, "Content-Type": "application/json"}
TARGET = "https://example.com"
# 1. Submit
r = requests.post(f"{API}/api/solve",
headers=HEADERS,
json={"url": TARGET},
timeout=30)
r.raise_for_status()
task_id = r.json()["taskId"]
# 2. Poll for the result
for _ in range(60):
time.sleep(2)
r = requests.get(f"{API}/api/getTaskResult",
params={"taskId": task_id},
headers={"X-API-Key": KEY},
timeout=30)
data = r.json()
if data.get("status") != "pending":
break
if not data.get("success"):
raise RuntimeError(data.get("error", "solve failed"))
# 3. Use the cookies + UA on your real request
s = requests.Session()
s.headers["Cookie"] = data["cookies"]
s.headers["User-Agent"] = data["user_agent"] # MUST match the solve UA
page = s.get(TARGET)
print(page.status_code, len(page.text))Reusable helper with retries
import time, requests
API = "https://api.vexsolver.com"
KEY = "sk_live_..."
class VexError(Exception):
pass
def solve(url, proxy=None, app_id=None, fresh=False, max_wait=120):
"""Submit a solve and block until it finishes. Returns the full result dict."""
headers = {"X-API-Key": KEY, "Content-Type": "application/json"}
body = {"url": url}
if proxy: body["proxy"] = proxy
if app_id: body["app_id"] = app_id
if fresh: body["fresh"] = True
# Submit
r = requests.post(f"{API}/api/solve", headers=headers, json=body, timeout=30)
if r.status_code == 429:
raise VexError("rate limited")
if r.status_code == 402:
raise VexError("insufficient credits")
r.raise_for_status()
task_id = r.json()["taskId"]
# Poll
deadline = time.time() + max_wait
while time.time() < deadline:
time.sleep(2)
r = requests.get(f"{API}/api/getTaskResult",
params={"taskId": task_id},
headers={"X-API-Key": KEY}, timeout=30)
data = r.json()
if data.get("status") != "pending":
if not data.get("success"):
raise VexError(data.get("error", "solve failed"))
return data
raise VexError(f"timeout after {max_wait}s")
result = solve("https://example.com/", proxy="http://user:pass@proxy:8080")
print("Cookies:", result["cookies"][:80], "...")
print("UA: ", result["user_agent"])
print("Vendor:", result["vendor"])
print("Took: ", result["elapsed_ms"], "ms")Webhook-based (skip polling)
Pass a callback URL and VexSolver POSTs the result to you when done. Best when you control a server and want minimum latency / no idle polling:
r = requests.post("https://api.vexsolver.com/api/solve",
headers={"X-API-Key": "sk_live_...", "Content-Type": "application/json"},
json={
"url": "https://example.com",
"callback": "https://your-server.com/vexsolver-hook"
})
task_id = r.json()["taskId"]
print("submitted, will be POSTed to webhook with taskId=", task_id)
# Your webhook handler (Flask):
from flask import Flask, request
app = Flask(__name__)
@app.post("/vexsolver-hook")
def hook():
data = request.json
if data["success"]:
# store data["cookies"] + data["user_agent"] keyed on data["taskId"]
...
return "", 200Balance check
r = requests.get("https://api.vexsolver.com/api/balance",
headers={"X-API-Key": "sk_live_..."})
print("Credits remaining:", r.json()["credits"])Why poll every 2 seconds (not faster)?
Most solves finish in 1–15 seconds. Polling faster than 1/sec wastes requests against your rate limit without finishing the solve any sooner. The webhook flow above is strictly better for high-volume integrations.