feat: add support for /responses background parameter #4751
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Add OpenAI-compatible background mode for the Responses API, allowing responses to be queued for asynchronous processing.
Added
backgroundparameter (bool, default: false)When true, returns immediately with status "queued"
Added
backgroundfield toOpenAIResponseObjectNew status values: "queued", "in_progress", "cancelled"
OpenAI-compatible endpoint for cancelling background responses
Only works for responses created with background=true
Only cancellable when status is "queued" or "in_progress"
agents/models.py: AddedbackgroundtoCreateResponseRequest, newCancelResponseRequestagents/api.py: Addedcancel_openai_responseto Agents protocolagents/fastapi_routes.py: Added cancel routeopenai_responses.py: Addedbackgroundfield to response objectopenai_responses.py: Background processing with_create_background_responseand_process_background_responseresponses_store.py: Addedupdate_response_objectfor status updatescloses #4701
Test Plan
new unit and integration tests (with stainless builds) should pass. The integration tests represent the testing for the new API changes.