import json, requests
API_KEY = "sk-..."
BASE = "https://core.cyberun.cloud/api/v1/r"
with requests.get(
f"{BASE}/tasks/{task_id}/events",
headers={"Authorization": f"Bearer {API_KEY}"},
stream=True,
) as stream:
event_type = None
for line in stream.iter_lines(decode_unicode=True):
if not line:
continue
if line.startswith("event:"):
event_type = line[6:].strip()
elif line.startswith("data:"):
data = json.loads(line[5:].strip())
if event_type == "progress":
pct = int(data["progress"] * 100)
print(f"{pct}% ({data['step_current']}/{data['step_total']})")
elif event_type in ("completed", "failed", "cancelled"):
print(event_type, data)
break