sdk.md +50 −4
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
30Start a thread with Codex and run it with your prompt.28Start a thread with Codex and run it with your prompt.
31 29
32```ts30```ts
3331import { Codex } from "@openai/codex-sdk";
34 32
35const codex = new Codex();33const codex = new Codex();
36const thread = codex.startThread();34const thread = codex.startThread();
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
96
97async def main() -> None:
98 async with AsyncCodex() as codex:
99 thread = await codex.thread_start(model="gpt-5.4")
100 result = await thread.run("Implement the plan")
101 print(result.final_response)
102
103
104asyncio.run(main())
105```
106
107For more details, check out the [Python repo](https://github.com/openai/codex/tree/main/sdk/python).