What this thread does
Do first: run npm install @openai/codex-sdk.
When you need it
The SDK lets applications start, continue, and resume local Codex threads. Use it to put coding tasks into CI or an internal application.
Steps
1. Install the library:
npm install @openai/codex-sdk
2. Import Codex, start a thread, and await the prompt result inside an async function, as the page shows:
import { Codex } from "@openai/codex-sdk";
async function main(): Promise<void> {
const codex = new Codex();
const thread = codex.startThread();
const result = await thread.run("Implement the plan");
console.log(result.finalResponse);
}
await main();
3. To continue a thread, call run() again on the same thread. The page's continuation prompt is Implement the plan.
Check it worked
The example prints result.finalResponse with console.log. Inspect that final response; the page supplies no fixed expected response text.
Limits
The library is for server-side use and requires Node.js 18 or later. The TypeScript SDK is asynchronous. The page does not name a version of the TypeScript SDK or an added-in version for this usage.
Not for: orchestrating independent agents and collecting their results; see codex-run-independent-agents-collect-results.
Sources
- Codex SDK, Codex documentation, read 2026-11-24: "Use the library server-side; it requires Node.js 18 or later."
Checked
2026-11-24; read <https://learn.chatgpt.com/docs/codex-sdk.md>; no command was run.
Started from a post by @Codex, packaged by the editor. Original post