Immutable solution version
Flask/FastAPI: replace Assistants runs-polling with Responses calls
Complete solution
The framework-specific half of the migration: where the polling loop lived in your views, what replaces thread_id in your session store, and the beta-header cleanup. Pair with the concept-map skill.
Assistants to Responses in Flask and FastAPI
Kill the polling loop
Old shape in a view: create a run, then while run.status not in ("completed", "failed"): sleep(1); run = retrieve(run.id). New shape: one client.responses.create(...) call that returns when the model is done, with response.output holding message and tool-call items. Delete the sleep loop; keeping it means double-waiting on an API that already waited.
For long tasks, use background mode (background=True) and poll client.responses.retrieve(response.id) on status, or register a webhook. Do not hold a Flask request open for a 10-minute run.
Replace thread_id in your store
If you stored thread_id per user in your database or session, that column now holds a conversation id or the latest response.id used as previous_response_id on the next call. Migrate the column semantics explicitly:
Option A (server-side state): create a Conversation once per user, pass
conversation=conversation_idon every call.Option B (stateless): pass
previous_response_id=last_response_idand update the stored id after each call.
Do not store both and mix them; pick one per user row.
Header and namespace cleanup
- Remove the
OpenAI-Beta: assistants=v2header from your client setup. - Replace
client.beta.threads.runs.*withclient.responses.*. In FastAPI, the old polling loop often lived in a
BackgroundTask; replace it with a single awaitedAsyncOpenAI().responses.create.
Check before you ship
Search for
threads,runs.create, andassistantsacross the codebase; the only remaining hits should be in the migration notes.Load-test one migrated endpoint: response latency should drop by roughly the old polling interval times the old poll count.
Evidence
OpenAI's migrate-to-responses guide documents replacing run polling with direct responses.create calls and previousresponseid chaining. The assistants migration guide confirms the beta header and beta namespaces are removed.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_HQr5K4HxsyuDue4baXypAg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Flask/FastAPI: replace Assistants runs-polling with Responses calls <span>— Vectle</span></a>