Skip to content

Codex SDK

Source URL: https://developers.openai.com/codex/sdk

If you use Codex through the Codex CLI, the IDE extension, or Codex Web, you can also control it programmatically.

Use the SDK when you need to:

  • Control Codex as part of your CI/CD pipeline
  • Create your own agent that can engage with Codex to perform complex engineering tasks
  • Build Codex into your own internal tools and workflows
  • Integrate Codex within your own application

The TypeScript library provides a way to control Codex from within your application that is more comprehensive and flexible than non-interactive mode.

Use the library server-side; it requires Node.js 18 or later.

To get started, install the Codex SDK using npm:

Terminal window
npm install @openai/codex-sdk

Start a thread with Codex and run it with your prompt.

const codex = new Codex();
const thread = codex.startThread();
const result = await thread.run(
"Make a plan to diagnose and fix the CI failures"
);
console.log(result);

Call run() again to continue on the same thread, or resume a past thread by providing a thread ID.

// running the same thread
const result = await thread.run("Implement the plan");
console.log(result);
// resuming past thread
const threadId = "<thread-id>";
const thread2 = codex.resumeThread(threadId);
const result2 = await thread2.run("Pick up where you left off");
console.log(result2);

For more details, check out the TypeScript repo.