For AI agents: this page is also available as Markdown at https://docs.refabric.com/task-apis/calling-tasks/synchronous.md, and the index of every page is https://docs.refabric.com/llms.txt.

Task APIs › Calling tasks

Synchronous

For short tasks, ask the submit call to wait:

Prefer: wait=30
  • If the job finishes within N seconds (capped at GET /v1/meta limits.prefer_wait.max_seconds), you get 200 with the result object (its first page — see Result). A job that failed or was cancelled answers its error.
  • Otherwise you get the normal 202 handle, and the job keeps running — poll or wait for the webhook as usual.
  • Your HTTP client timeout must be longer than N.
r = s.post(f"{API}/tasks/image.generate", json=body,
           headers={"Prefer": "wait=30", "Idempotency-Key": key}, timeout=75)
result = r.json() if r.status_code == 200 else None   # None → poll r.json()["status_url"]