mirror of
https://github.com/openai/codex.git
synced 2026-09-11 20:36:49 +00:00
## Why Applications need to deliver content from other agents, tools, or services with tool-level authority, without treating it as user input or granting authorization. ## What changed - Export `ExternalMessage` for sync and async `run(...)` and `turn(...)`, accepting text or structured content with a tool name and optional namespace. Send it through `toolOutput` and require CLI 0.151.0 or newer. - Support starting a turn or joining an active regular turn while preserving external content as function output in history. Keep external messages separate from user-input lists and `steer(...)`. - Give turn handles independent subscriptions, replaying completed items and latest usage to joining handles. Release consumed transient events and clean up subscriptions on closure, failure, or cancellation. - Document the authority boundary and add sync and async examples. ## Testing Add coverage for wire representations, input validation, runtime compatibility, tool authority across resume, active-turn joins, and tool-output truncation. Add subscription tests for replay, concurrent consumers, early completion, cancellation, and cleanup. GitOrigin-RevId: 6106327085fd9c4bd11b71e20b3d8e74738b8bb5
76 lines
1.9 KiB
Markdown
76 lines
1.9 KiB
Markdown
# OpenAI Codex Python SDK
|
|
|
|
Build Python applications that start Codex threads, run turns, stream progress,
|
|
and control workspace access.
|
|
|
|
## Install
|
|
|
|
Install the SDK:
|
|
|
|
```bash
|
|
pip install openai-codex
|
|
```
|
|
|
|
## Quickstart
|
|
|
|
The SDK reuses your existing Codex authentication when one is already
|
|
available:
|
|
|
|
```python
|
|
from openai_codex import Codex
|
|
|
|
with Codex() as codex:
|
|
thread = codex.thread_start()
|
|
result = thread.run("Explain this repository in three bullets.")
|
|
print(result.final_response)
|
|
```
|
|
|
|
`thread.run(...)` returns a `TurnResult` containing the final response,
|
|
collected items, and token usage.
|
|
|
|
## Authentication
|
|
|
|
Existing Codex authentication is reused automatically. To start ChatGPT
|
|
browser login explicitly:
|
|
|
|
```python
|
|
from openai_codex import Codex
|
|
|
|
with Codex() as codex:
|
|
login = codex.login_chatgpt()
|
|
print(login.auth_url)
|
|
print(login.wait().success)
|
|
```
|
|
|
|
For device-code login:
|
|
|
|
```python
|
|
with Codex() as codex:
|
|
login = codex.login_chatgpt_device_code()
|
|
print(login.verification_url, login.user_code)
|
|
login.wait()
|
|
```
|
|
|
|
For API-key login:
|
|
|
|
```python
|
|
with Codex() as codex:
|
|
codex.login_api_key("sk-...")
|
|
```
|
|
|
|
## Built-In Help
|
|
|
|
Use Python's standard `help(openai_codex)`, `help(Codex)`, or
|
|
`python -m pydoc openai_codex` documentation tools.
|
|
|
|
## Documentation
|
|
|
|
- [Getting started](https://github.com/openai/codex/blob/main/sdk/python/docs/getting-started.md)
|
|
- [API reference](https://github.com/openai/codex/blob/main/sdk/python/docs/api-reference.md)
|
|
- [Untrusted external messages](https://github.com/openai/codex/blob/main/sdk/python/docs/api-reference.md#externalmessage)
|
|
- [FAQ](https://github.com/openai/codex/blob/main/sdk/python/docs/faq.md)
|
|
- [Examples](https://github.com/openai/codex/blob/main/sdk/python/examples/README.md)
|
|
|
|
The package is licensed under the
|
|
[repository Apache License 2.0](https://github.com/openai/codex/blob/main/LICENSE).
|