codex-sdk.md +87 −0
75For example, `codex.startThread({ threadSource: "ci" })` labels the thread75For example, `codex.startThread({ threadSource: "ci" })` labels the thread
76as `ci`. Resuming a thread preserves its original source.76as `ci`. Resuming a thread preserves its original source.
77 77
78Set the model and sandbox when creating a thread:
79
80```typescript
81import { Codex } from "@openai/codex-sdk";
82
83const codex = new Codex();
84const thread = codex.startThread({
85 model: "gpt-6.1-sol",
86 modelReasoningEffort: "low",
87 sandboxMode: "workspace-write",
88});
89const result = await thread.run(
90 "Make a plan to diagnose and fix the CI failures"
91);
92console.log(result.finalResponse);
93```
94
95```python
96from openai_codex import Codex, Sandbox
97
98with Codex() as codex:
99 thread = codex.thread_start(
100 model="gpt-6.1-sol",
101 sandbox=Sandbox.workspace_write,
102 )
103 result = thread.run("Make a plan to diagnose and fix the CI failures")
104 print(result.final_response)
105```
106
107
108The TypeScript SDK is asynchronous. Await the result inside your application's async function:
109
110```typescript
111import { Codex } from "@openai/codex-sdk";
112
113async function main(): Promise<void> {
114 const codex = new Codex();
115 const thread = codex.startThread();
116 const result = await thread.run("Implement the plan");
117 console.log(result.finalResponse);
118}
119await main();
120```
121
122```python
123import asyncio
124from openai_codex import AsyncCodex
125
126
127async def main() -> None:
128 async with AsyncCodex() as codex:
129 thread = await codex.thread_start(model="gpt-6.1-sol")
130 result = await thread.run("Implement the plan")
131 print(result.final_response)
132
133
134asyncio.run(main())
135```
136
137
78### Configuration overrides138### Configuration overrides
79 139
80Pass `config` to set structured Codex configuration. For keys that can't be140Pass `config` to set structured Codex configuration. For keys that can't be
122which must be available to your signed-in account. Otherwise, omit `model` to182which must be available to your signed-in account. Otherwise, omit `model` to
123use your configured default. See [model availability by plan](https://learn.chatgpt.com/docs/pricing#feature-availability).183use your configured default. See [model availability by plan](https://learn.chatgpt.com/docs/pricing#feature-availability).
124 184
185```typescript
186import { Codex } from "@openai/codex-sdk";
187
188const codex = new Codex();
189const thread = codex.startThread({
190 model: "gpt-6.1-sol",
191 modelReasoningEffort: "low",
192 sandboxMode: "workspace-write",
193});
194const result = await thread.run(
195 "Make a plan to diagnose and fix the CI failures"
196);
197console.log(result.finalResponse);
198```
199
125```python200```python
126from openai_codex import Codex, Sandbox201from openai_codex import Codex, Sandbox
127 202
137 212
138Use `AsyncCodex` when your application is already asynchronous:213Use `AsyncCodex` when your application is already asynchronous:
139 214
215```typescript
216import { Codex } from "@openai/codex-sdk";
217
218async function main(): Promise<void> {
219 const codex = new Codex();
220 const thread = codex.startThread();
221 const result = await thread.run("Implement the plan");
222 console.log(result.finalResponse);
223}
224await main();
225```
226
140```python227```python
141import asyncio228import asyncio
142from openai_codex import AsyncCodex229from openai_codex import AsyncCodex