Repository navigation
[Feature] create_and_wait helpers for Flows generations and template runs - #889
brandonrule11 wants to merge 2 commits into
Conversation
client.flows.{image,video,text_to_speech}.create_and_wait and
client.flows.templates.runs.create_and_wait (sync and async) start the
work, then poll the GET endpoint, waiting the server's Retry-After (with
a minimum interval and jitter) between checks, until the status is
completed or failed. An optional timeout raises FlowsWaitTimeoutError
carrying the id so callers can resume with get.
FLO-350
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR SummaryLow Risk Overview The main capability is
Reviewed by Cursor Bugbot for commit 3782630. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dd0db64. Configure here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

FLO-350: quickstarts should get a Flows result in one call, without a hand-written poll loop or webhook plumbing (like OpenAI's
create_and_poll)._should_retryonly covers 408/409/429/5xx, so an in-progress 200 returns straight away. JS counterpart: elevenlabs/elevenlabs-js#469.Usage
Design
src/elevenlabs/flows_custom.py, added to.fernignore. Subclasses of the generated flows, templates, runs, image, video and TTS clients, sync and async.client.pysetsself._flowsto the wrapper, the same pattern as music/STT/speech engine.with_raw_response, so the create response'sRetry-After(FLO-349 sets it on creates too) sets the first wait.core.http_client._parse_retry_afterand_add_positive_jitter: max(Retry-Afteror min, min) × (1 + 0–20%). A missing, unparseable or0header falls back tomin_poll_interval(default 1s). Transport retries still handle 429s.completed/failedare terminal. Afailedresult is returned, not raised.timeout(seconds), the last sleep is cut short at the deadline and one final GET runs. If the work still isn't finished, it raisesFlowsWaitTimeoutError(id,template_id,last_response). With no timeout set, it waits indefinitely, like OpenAI.Notes
FlowsWaitTimeoutErroris a plainException, notApiError, because no HTTP status applies. Import it fromelevenlabs.flows_custom, since the package__init__is generated.ruff formaton the test file: ruff rewrites it to parenthesized context managers, which aren't valid on Python 3.8 (python = "^3.8").flows_template_runappears in the API definition.Testing
tests/test_flows_create_and_wait.py: covers Retry-After pacing and jitter, the min fallback, failed generations returned rather than raised, timeout errors carrying the id (andtemplate_idfor runs), the no-poll path when create returns a terminal status, and the async image and run paths. Uses httpxMockTransportwith sleeps patched.pytest tests/test_flows_create_and_wait.py: 10/10 pass.mypyon the new and changed files is clean.🤖 Generated with Claude Code