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

1import { Codex } from "@openai/codex-sdk";
2
3const codex = new Codex({
4 apiKey: process.env.RESPAN_API_KEY,
5 baseUrl: process.env.RESPAN_BASE_URL ?? "https://api.respan.ai/api",
6 env: {
7 ...process.env,
8 CODEX_API_KEY: process.env.RESPAN_API_KEY!,
9 OPENAI_API_KEY: process.env.RESPAN_API_KEY!,
10 },
11});
12
13const thread = codex.startThread({
14 workingDirectory: process.cwd(),
15 skipGitRepoCheck: true,
16 sandboxMode: "read-only",
17 approvalPolicy: "never",
18 model: "gpt-5.5",
19});
20
21const result = await thread.run("Explain gateway routing in one short sentence.");
22console.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.

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

See the full model list.