-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fix: route OpenAI Codex shortcuts to correct endpoint #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f45b904
d5a5237
8c1ba91
a0323f7
1825b6e
06f2c96
a566167
bfca356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,8 @@ const CODEX_ALIAS_MODELS: Record< | |
| type CodexAlias = keyof typeof CODEX_ALIAS_MODELS | ||
| type ReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | ||
|
|
||
| const OPENAI_CODEX_SHORTCUT_ALIASES = new Set(['codexplan', 'codexspark']) | ||
|
|
||
| export type ProviderTransport = 'chat_completions' | 'codex_responses' | ||
|
|
||
| export type ResolvedProviderRequest = { | ||
|
|
@@ -219,6 +221,12 @@ export function isCodexAlias(model: string): boolean { | |
| return base in CODEX_ALIAS_MODELS | ||
| } | ||
|
|
||
| function isOpenAICodexShortcutAlias(model: string): boolean { | ||
| const normalized = model.trim().toLowerCase() | ||
| const base = normalized.split('?', 1)[0] ?? normalized | ||
| return OPENAI_CODEX_SHORTCUT_ALIASES.has(base) | ||
| } | ||
|
|
||
| export function shouldUseCodexTransport( | ||
| model: string, | ||
| baseUrl: string | undefined, | ||
|
|
@@ -363,10 +371,24 @@ export function resolveProviderRequest(options?: { | |
| options?.fallbackModel?.trim() || | ||
| (isGithubMode ? 'github:copilot' : 'gpt-4o') | ||
| const descriptor = parseModelDescriptor(requestedModel) | ||
| const rawBaseUrl = | ||
| asEnvUrl(options?.baseUrl) ?? | ||
| const explicitBaseUrl = asEnvUrl(options?.baseUrl) | ||
| const envBaseUrlRaw = | ||
| asEnvUrl(process.env.OPENAI_BASE_URL) ?? | ||
| asEnvUrl(process.env.OPENAI_API_BASE) | ||
| const envBaseUrl = | ||
| isGithubMode && envBaseUrlRaw && getGithubEndpointType(envBaseUrlRaw) === 'custom' | ||
| ? undefined | ||
| : envBaseUrlRaw | ||
| const rawBaseUrl = explicitBaseUrl ?? envBaseUrl | ||
|
|
||
| const shellModel = process.env.OPENAI_MODEL?.trim() ?? '' | ||
| const isCodexAliasModel = | ||
| isOpenAICodexShortcutAlias(requestedModel) || | ||
| isOpenAICodexShortcutAlias(shellModel) | ||
| const finalBaseUrl = | ||
| !isGithubMode && isCodexAliasModel && !explicitBaseUrl | ||
| ? DEFAULT_CODEX_BASE_URL | ||
| : rawBaseUrl | ||
|
Comment on lines
+408
to
+411
|
||
|
|
||
| const githubEndpointType = isGithubMode | ||
| ? getGithubEndpointType(rawBaseUrl) | ||
|
|
@@ -380,7 +402,7 @@ export function resolveProviderRequest(options?: { | |
| : requestedModel | ||
|
|
||
| const transport: ProviderTransport = | ||
| shouldUseCodexTransport(requestedModel, rawBaseUrl) || | ||
| shouldUseCodexTransport(requestedModel, finalBaseUrl) || | ||
| (isGithubCopilot && shouldUseGithubResponsesApi(githubResolvedModel)) | ||
| ? 'codex_responses' | ||
| : 'chat_completions' | ||
|
|
@@ -404,7 +426,7 @@ export function resolveProviderRequest(options?: { | |
| requestedModel, | ||
| resolvedModel, | ||
| baseUrl: | ||
| (rawBaseUrl ?? | ||
| (finalBaseUrl ?? | ||
| (isGithubCopilot && transport === 'codex_responses' | ||
| ? GITHUB_COPILOT_BASE_URL | ||
| : (isGithubMode | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isCodexAliasModelcurrently considersprocess.env.OPENAI_MODEL(shellModel) even when the caller passes an explicitoptions.model. This can incorrectly forcefinalBaseUrltoDEFAULT_CODEX_BASE_URLfor non-Codex requests (e.g.,resolveProviderRequest({ model: 'gpt-4o' })while the environment hasOPENAI_MODEL=codexplan), which would misroute traffic to the Codex endpoint. Consider basing the Codex-shortcut check only onrequestedModel, or only consultingshellModelwhenoptions?.modelis not provided andrequestedModelcame from the env var.