import requests
import time
BASE_URL = "https://api.origamiagents.com/api/v1"
HEADERS = {"x-origami-key": "your-api-key"}
# 1. Trigger
response = requests.post(
f"{BASE_URL}/workflows/{workflow_id}/runs/async",
headers={**HEADERS, "Content-Type": "application/json"},
json={"nodes": {}}
)
run_id = response.json()["data"]["runId"]
# 2. Poll
while True:
status_response = requests.get(
f"{BASE_URL}/workflows/{workflow_id}/runs/{run_id}/async/status",
headers=HEADERS
)
status = status_response.json()["data"]["status"]
if status == "completed":
break
elif status == "failed":
raise Exception("Workflow failed")
time.sleep(2)
# 3. Get results
result_response = requests.get(
f"{BASE_URL}/workflows/{workflow_id}/runs/{run_id}/async/response",
headers=HEADERS
)
output = result_response.json()["data"]