> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/docs/_mcp/server.

# Codex SDK (gateway)

> Set up OpenAI Codex SDK with the Respan gateway.

Route Codex SDK model calls through the Respan gateway. The SDK uses the OpenAI Responses API, which the gateway serves at `https://api.respan.ai/api/responses`, so only your `RESPAN_API_KEY` is needed. This page only covers gateway routing and does not install or configure tracing instrumentation.

## Setup

#### Install packages

```bash
npm install @openai/codex-sdk
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export RESPAN_BASE_URL="https://api.respan.ai/api"
```

No separate provider key is needed when the gateway route is enabled for your Respan key.

#### Point Codex SDK to the Respan gateway

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

const codex = new Codex({
  apiKey: process.env.RESPAN_API_KEY,
  baseUrl: process.env.RESPAN_BASE_URL ?? "https://api.respan.ai/api",
  env: {
    ...process.env,
    CODEX_API_KEY: process.env.RESPAN_API_KEY!,
    OPENAI_API_KEY: process.env.RESPAN_API_KEY!,
  },
});

const thread = codex.startThread({
  workingDirectory: process.cwd(),
  skipGitRepoCheck: true,
  sandboxMode: "read-only",
  approvalPolicy: "never",
  model: "gpt-5.5",
});

const result = await thread.run("Explain gateway routing in one short sentence.");
console.log(result.finalResponse);
```

> **Note**
>
> Codex SDK routing depends on the SDK's Codex-compatible API path. If your key is not enabled for that route, configure gateway access before using this setup.

## Switch models

Change the `model` option on a Codex thread to use another OpenAI model. Codex talks to the gateway's Responses API route, which serves OpenAI models only, so Claude and Gemini are not available here.

```typescript
const thread = codex.startThread({
  workingDirectory: process.cwd(),
  skipGitRepoCheck: true,
  sandboxMode: "read-only",
  approvalPolicy: "never",
  model: "gpt-5-mini",
});
```

See the [full model list](https://platform.respan.ai/platform/models).