fix(ai): respect codex baseUrl (closes #1244)

This commit is contained in:
Mario Zechner 2026-02-04 12:30:21 +01:00
parent b23e6ea21e
commit 150aeebf7d

View file

@ -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
// ============================================================================