Files
llmx/sdk/typescript
pranavdesh 53504a38d2 Expand TypeScript SDK README (#4779)
## Summary
- expand the TypeScript SDK README with streaming, architecture, and API
docs
- refresh quick start examples and clarify thread management options

## Testing
- Not Run (docs only)

---------

Co-authored-by: pakrym-oai <pakrym@openai.com>
2025-10-05 21:43:34 +00:00
..
2025-10-04 19:55:33 -07:00
2025-10-04 19:55:33 -07:00
2025-10-01 12:39:04 -07:00
2025-10-01 12:39:04 -07:00
2025-10-05 21:43:34 +00:00
2025-10-01 12:39:04 -07:00
2025-09-29 13:27:13 -07:00

Codex SDK

Embed the Codex agent in your workflows and apps.

The TypeScript SDK wraps the bundled codex binary. It spawns the CLI and exchanges JSONL events over stdin/stdout.

Installation

npm install @openai/codex-sdk

Requires Node.js 18+.

Quickstart

import { Codex } from "@openai/codex-sdk";

const codex = new Codex();
const thread = codex.startThread();
const turn = await thread.run("Diagnose the test failure and propose a fix");

console.log(turn.finalResponse);
console.log(turn.items);

Call run() repeatedly on the same Thread instance to continue that conversation.

const nextTurn = await thread.run("Implement the fix");

Streaming responses

run() buffers events until the turn finishes. To react to intermediate progress—tool calls, streaming responses, and file diffs—use runStreamed() instead, which returns an async generator of structured events.

const { events } = await thread.runStreamed("Diagnose the test failure and propose a fix");

for await (const event of events) {
  switch (event.type) {
    case "item.completed":
      console.log("item", event.item);
      break;
    case "turn.completed":
      console.log("usage", event.usage);
      break;
  }
}

Resuming an existing thread

Threads are persisted in ~/.codex/sessions. If you lose the in-memory Thread object, reconstruct it with resumeThread() and keep going.

const savedThreadId = process.env.CODEX_THREAD_ID!;
const thread = codex.resumeThread(savedThreadId);
await thread.run("Implement the fix");

Working directory controls

Codex runs in the current working directory by default. To avoid unrecoverable errors, Codex requires the working directory to be a Git repository. You can skip the Git repository check by passing the skipGitRepoCheck option when creating a thread.

const thread = codex.startThread({
  workingDirectory: "/path/to/project",
  skipGitRepoCheck: true,
});