import os, time, requests
BASE = "https://api.phylo.bio/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['BIOMNI_API_KEY']}"}
def post(path, body):
r = requests.post(f"{BASE}{path}", headers=HEADERS, json=body); r.raise_for_status(); return r.json()
def get(path, **p):
r = requests.get(f"{BASE}{path}", headers=HEADERS, params=p); r.raise_for_status(); return r.json()
project_id = post("/projects", {"name": "Batch run"})["id"]
prompts = [
"Summarize the clinical significance of variant rs80357065.",
"Summarize the clinical significance of variant rs28897696.",
"Summarize the clinical significance of variant rs80357382.",
]
# 1. Fire off all tasks
task_ids = [
post("/messages", {"project_id": project_id, "content": p})["task"]["id"]
for p in prompts
]
# 2. Poll until all complete
pending = set(task_ids)
while pending:
for tid in list(pending):
if get(f"/tasks/{tid}")["status"] in ("completed", "failed"):
pending.discard(tid)
if pending:
time.sleep(10)
# 3. Collect results
for tid in task_ids:
files = get(f"/tasks/{tid}/results", with_urls="true").get("data", [])
print(tid, [f["name"] for f in files])