Codex SDK (gateway)

Route Codex SDK model calls through the Respan gateway when your Respan key has access to the Codex-compatible endpoint. This page only covers gateway routing and does not install or configure tracing instrumentation.

Setup

1

Install packages

npm install @openai/codex-sdk
2

Set environment variables

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.

3

Point Codex SDK to the Respan gateway

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);

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 model supported by your gateway configuration.

const thread = codex.startThread({
workingDirectory: process.cwd(),
skipGitRepoCheck: true,
sandboxMode: "read-only",
approvalPolicy: "never",
model: "claude-sonnet-4-5-20250929",
});

See the full model list.