Skip to main content
Pass background=True to Workflow.arun() to start a detached asynchronous task. Configure a workflow database when you need to poll the persisted run. Combine background=True with stream=True for buffered SSE events that can be resumed after a client disconnects. See Background Execution for the full guide covering polling, resumable streaming, and the /resume endpoint.
Start background execution with .arun(). The polling pattern below requires a workflow database. Call workflow.get_run(run_id) and check .has_completed() on the returned run.

Prerequisites

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

Example

You can also use WebSocket for background workflows. See the Workflow WebSocket examples.

Developer Resources