import time
import requests
BASE_URL = "https://api.sixtyfour.ai"
headers = {"x-api-key": "YOUR_API_KEY", "Content-Type": "application/json"}
start = requests.post(
f"{BASE_URL}/search/start-deep-search",
headers=headers,
json={
"query": "VP of Engineering at Series B SaaS startups in New York",
"mode": "people",
"max_results": 500,
},
)
start.raise_for_status()
task_id = start.json()["task_id"]
deadline = time.monotonic() + 20 * 60
while time.monotonic() < deadline:
status = requests.get(f"{BASE_URL}/search/status/{task_id}", headers=headers, timeout=30)
if status.status_code in (429, 503):
time.sleep(int(status.headers.get("Retry-After", "10")))
continue
status.raise_for_status()
data = status.json()
print(data["status"], data.get("progress_message") or "")
if data["status"] == "completed":
resource_handle_id = data["resource_handle_id"]
break
if data["status"] != "running":
raise RuntimeError(data.get("error") or f"Search {data['status']}")
time.sleep(10)
else:
raise TimeoutError(f"Search {task_id} did not finish within 20 minutes")
download = requests.get(
f"{BASE_URL}/search/download",
headers=headers,
params={"resource_handle_id": resource_handle_id},
)
download.raise_for_status()
print(download.json()["url"])