Codex SDK (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.
Paste this into your coding agent:
Help me set up the Respan gateway with the Codex SDK integration.
Follow https://www.respan.ai/docs/integrations/gateway/codex-sdk.mdSetup
Install packages
npm install @openai/codex-sdkSet 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.
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 OpenAI model. Codex talks to the gateway’s Responses API route, which serves OpenAI models only, so Claude and Gemini are not available here.
const thread = codex.startThread({
workingDirectory: process.cwd(),
skipGitRepoCheck: true,
sandboxMode: "read-only",
approvalPolicy: "never",
model: "gpt-5-mini",
});See the full model list .