Skip to main content

Requirements

The Codex TypeScript SDK requires:
  • Node.js 18 or higher
  • The @openai/codex CLI installed and available in your PATH

Install the SDK

Install the SDK using your preferred package manager:
npm install @openai/codex-sdk

Verify Installation

Create a simple test script to verify the SDK is installed correctly:
test.ts
import { Codex } from "@openai/codex-sdk";

const codex = new Codex();
const thread = codex.startThread();

console.log("SDK initialized successfully!");
Run the script:
node --loader tsx test.ts

Environment Setup

API Configuration

The SDK requires access to the Codex API. Configure your credentials:
1

Set API Key

Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY="your-api-key"
2

Configure Base URL (Optional)

If you’re using a custom API endpoint, set the base URL:
export OPENAI_BASE_URL="https://custom-endpoint.example.com/v1"
3

Pass Credentials Programmatically

Alternatively, pass credentials directly when creating the client:
const codex = new Codex({
  apiKey: process.env.OPENAI_API_KEY,
  baseUrl: "https://api.openai.com/v1",
});

TypeScript Configuration

Ensure your tsconfig.json is configured for ES modules:
tsconfig.json
{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "node",
    "target": "ES2020",
    "lib": ["ES2020"],
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}
The SDK uses ES module syntax (import/export). Ensure your project is configured to support ES modules.

Package Information

The SDK is published as @openai/codex-sdk with the following characteristics:
Package Name
string
@openai/codex-sdk
Type
string
ES Module (.js files with import/export)
Main Export
string
./dist/index.js
Type Definitions
string
./dist/index.d.ts
License
string
Apache-2.0

Troubleshooting

Ensure you’ve installed the package and that your node_modules is up to date:
rm -rf node_modules package-lock.json
npm install
The SDK requires the codex CLI to be installed. Install it globally:
npm install -g @openai/codex
Or specify a custom path when creating the client:
const codex = new Codex({
  codexPathOverride: "/path/to/codex",
});
Verify you’re using Node.js 18 or higher:
node --version
Upgrade if needed using nvm or download from nodejs.org.

Next Steps

Usage Guide

Learn how to use the SDK with code examples and detailed API documentation

Build docs developers (and LLMs) love