From 150aeebf7d3217eed6b5d21e877cb465420d572a Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 4 Feb 2026 12:30:21 +0100 Subject: [PATCH] fix(ai): respect codex baseUrl (closes #1244) --- packages/ai/src/providers/openai-codex-responses.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ai/src/providers/openai-codex-responses.ts b/packages/ai/src/providers/openai-codex-responses.ts index 38565b49..3a563d44 100644 --- a/packages/ai/src/providers/openai-codex-responses.ts +++ b/packages/ai/src/providers/openai-codex-responses.ts @@ -26,7 +26,7 @@ import { buildBaseOptions, clampReasoning } from "./simple-options.js"; // Configuration // ============================================================================ -const CODEX_URL = "https://chatgpt.com/backend-api/codex/responses"; +const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api"; const JWT_CLAIM_PATH = "https://api.openai.com/auth" as const; const MAX_RETRIES = 3; const BASE_DELAY_MS = 1000; @@ -147,7 +147,7 @@ export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses" } try { - response = await fetch(CODEX_URL, { + response = await fetch(resolveCodexUrl(model.baseUrl), { method: "POST", headers, body: bodyJson, @@ -288,6 +288,14 @@ function clampReasoningEffort(modelId: string, effort: string): string { return effort; } +function resolveCodexUrl(baseUrl?: string): string { + const raw = baseUrl && baseUrl.trim().length > 0 ? baseUrl : DEFAULT_CODEX_BASE_URL; + const normalized = raw.replace(/\/+$/, ""); + if (normalized.endsWith("/codex/responses")) return normalized; + if (normalized.endsWith("/codex")) return `${normalized}/responses`; + return `${normalized}/codex/responses`; +} + // ============================================================================ // Response Processing // ============================================================================