sdk.md +47 −3
1# Codex SDK1# Codex SDK
2 2
3Programmatically control local Codex agents
4
5If you use Codex through the Codex CLI, the IDE extension, or Codex Web, you can also control it programmatically.3If you use Codex through the Codex CLI, the IDE extension, or Codex Web, you can also control it programmatically.
6 4
7Use the SDK when you need to:5Use the SDK when you need to:
13 11
14## TypeScript library12## TypeScript library
15 13
1614The TypeScript library provides a way to control Codex from within your application that is more comprehensive and flexible than non-interactive mode.The TypeScript library provides a way to control Codex from within your application that's more comprehensive and flexible than non-interactive mode.
17 15
18Use the library server-side; it requires Node.js 18 or later.16Use the library server-side; it requires Node.js 18 or later.
19 17
59```57```
60 58
61For more details, check out the [TypeScript repo](https://github.com/openai/codex/tree/main/sdk/typescript).59For more details, check out the [TypeScript repo](https://github.com/openai/codex/tree/main/sdk/typescript).
60
61## Python library
62
63The Python SDK is experimental and controls the local Codex app-server over JSON-RPC. It requires Python 3.10 or later and a local checkout of the open-source Codex repo.
64
65### Installation
66
67From the Codex repo root, install the SDK in editable mode:
68
69```bash
70cd sdk/python
71python -m pip install -e .
72```
73
74For manual local SDK usage, pass `AppServerConfig(codex_bin=...)` to point at a local `codex` binary, or use the repo examples and notebook bootstrap.
75
76### Usage
77
78Start Codex, create a thread, and run a prompt:
79
80```python
81from codex_app_server import Codex
82
83with Codex() as codex:
84 thread = codex.thread_start(model="gpt-5.4")
85 result = thread.run("Make a plan to diagnose and fix the CI failures")
86 print(result.final_response)
87```
88
89Use `AsyncCodex` when your application is already asynchronous:
90
91```python
92import asyncio
93
94from codex_app_server import AsyncCodex
95
96async def main() -> None:
97 async with AsyncCodex() as codex:
98 thread = await codex.thread_start(model="gpt-5.4")
99 result = await thread.run("Implement the plan")
100 print(result.final_response)
101
102asyncio.run(main())
103```
104
105For more details, check out the [Python repo](https://github.com/openai/codex/tree/main/sdk/python).