Skip to content

Add Python SDK thread.run convenience methods#15088

Merged
shaqayeq-oai merged 12 commits intomainfrom
dev/shaqayeq/python-sdk-thread-run
Mar 19, 2026
Merged

Add Python SDK thread.run convenience methods#15088
shaqayeq-oai merged 12 commits intomainfrom
dev/shaqayeq/python-sdk-thread-run

Conversation

@shaqayeq-oai
Copy link
Collaborator

TL;DR

Add thread.run(...) / async thread.run(...) convenience methods to the Python SDK for the common case.

  • add RunInput = Input | str and RunResult with final_response, collected items, and optional usage
  • keep thread.turn(...) strict and lower-level for streaming, steering, interrupting, and raw generated Turn access
  • update Python SDK docs, quickstart examples, and tests for the sync and async convenience flows

Validation

  • python3 -m pytest sdk/python/tests/test_public_api_signatures.py sdk/python/tests/test_public_api_runtime_behavior.py
  • python3 -m pytest sdk/python/tests/test_real_app_server_integration.py -k 'thread_run_convenience or async_thread_run_convenience' (skipped in this environment)

@shaqayeq-oai shaqayeq-oai added the oai PRs contributed by OpenAI employees label Mar 18, 2026
Copy link
Collaborator

@owenlin0 owenlin0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API looks super clean in the examples, love to see it!

just a comment about organization, but pre-approving

final_response=_final_assistant_response_from_items(items),
items=items,
usage=usage,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it'd be great to introduce some structure so api.py doesn't become too monolithic (and also so Codex itself can follow a better file structure in future changes!)

Let's keep api.py minimal as the public facade and where the generated Codex / Thread methods live

Codex suggests this:

Extract the handwritten convenience logic into private modules:

  • _inputs.py: TextInput, ImageInput, LocalImageInput, SkillInput, MentionInput, Input, RunInput, _to_wire_input, _normalize_run_input
  • _run.py: RunResult, _collect_run_result, _collect_async_run_result, _raise_for_failed_turn, assistant-text extraction
  • optionally _turn_handles.py: TurnHandle and AsyncTurnHandle if you want the bottom half slimmer too

thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the _turn_handles.py split because it introduced an awkward api.py <-> _turn_handles.py circular typing dependency around AsyncCodex / AsyncTurnHandle. We can make it work with TYPE_CHECKING or a private protocol, but that felt like more complexity than value

@shaqayeq-oai shaqayeq-oai enabled auto-merge (squash) March 19, 2026 00:56
@shaqayeq-oai shaqayeq-oai merged commit 4fd2774 into main Mar 19, 2026
17 checks passed
@shaqayeq-oai shaqayeq-oai deleted the dev/shaqayeq/python-sdk-thread-run branch March 19, 2026 00:57
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

oai PRs contributed by OpenAI employees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants