Flow
Flow execution proxy with execute, streaming, and run methods.
Flow (Sync)
Proxy object for executing a single flow synchronously.
Methods
execute(*, message, ...) -> ExecuteResult | PausedResult
Execute the flow to completion and return the result.
Parameters:
message(str, optional): User message — the flow's primary input. Can be omitted ifparameterscontains all required inputs.parameters(dict, optional): Flat dict of flow-level initial inputs (not nested by block). Default:{}block_overrides(dict, optional): Per-step config overrides, format{"step_id": {"field": value}}. Default:{}attachments(list, optional): Up to 10 media attachments (HTTPS URLs). Default:[]tools(list, optional): OpenAI-format tool definitions. Max 64. Default:[]tool_choice(str or dict, optional):"auto"|"none"|"required"|{"type": "function", "function": {"name": ...}}. Default:Nonetool_handler(callable, optional): Sync function(tool_calls) -> tool_resultsfor auto-resume. Async handlers raiseTypeError. Default:Nonemax_tool_rounds(int, optional): Safety bound on tool-handler loop. Defaults to 10. RaisesToolCallLimitErrorif exceeded.trace(bool, optional): Capture full input/output snapshots in trace. Timing/tokens recorded either way. Default:Falseversion(str or int, optional):"draft"(default),"production", or a published version number (positive int). Default:"draft"timeout(float, optional): Request timeout in seconds. Default:None
Returns:
ExecuteResulton successful completionPausedResultif the flow pauses for tool calls and notool_handleris provided
Raises:
FlowNotFoundError: Flow does not existInsufficientCreditsError: Account balance insufficientFlowExecutionError: Server-side execution failureToolCallLimitError:max_tool_roundsexhaustedValueError: Invalidversionvalue
Examples:
Basic execution:
With parameters and version:
With tools and auto-resume:
steps(*, message, ...) -> Iterator[StepCompleted]
Stream completed steps as they finish. Sync Flow cannot iterate. Use AsyncFlow.steps() instead.
See AsyncFlow.steps() for details and examples.
events(*, message, ...) -> Iterator[StreamEvent]
Stream all execution events. Sync Flow cannot iterate. Use AsyncFlow.events() instead.
See AsyncFlow.events() for details and examples.
run(execution_id) -> Run
Get a proxy to inspect a previous execution.
Parameters:
execution_id(str): Execution ID from a previousexecute()result
Returns: Run proxy for tracing and inspection
Example:
AsyncFlow
Async equivalent of Flow. All methods are awaitable.
Methods
async execute(...) -> ExecuteResult | PausedResult
Async version of Flow.execute(). Accepts the same parameters; all are awaitable.
Example:
async for step in steps(*, message, ...)
Stream completed steps as they finish.
Yields: StepCompleted events
Example:
async for event in events(*, message, ...)
Stream all execution events from the flow.
Yields: StreamEvent — discriminated union of RunStarted, StepStarted, StepInput, StepOutput, StepCompleted, StepFailed, StepPaused, ToolCallsRequired, FlowCompleted
Example:
async def run(execution_id) -> AsyncRun
Get an async proxy to inspect a previous execution.
Example:
async def execute_async(*, message, ...) -> Job
Submit the flow to the server queue for asynchronous execution (long-running flows). Returns immediately with a Job handle.
Accepts same parameters as execute() except tool_handler, max_tool_rounds, and attachments are not supported.
Returns: Job with execution_id available immediately
Example:
Streaming Parameters
Both steps() and events() accept the same parameters as execute():
Version Values
The version parameter accepts:
| Value | Behavior |
|---|---|
"draft" (default) | Execute the in-progress draft version |
"production" | Execute the currently promoted production version |
N (int, e.g., 3) | Execute a specific published version number |
Strings other than "draft" and "production" (e.g., "main", "dev") raise ValueError.
"production" is currently not implemented server-side and raises NotImplementedError at runtime. Use "draft" or a pinned version number for now.
Examples: