mirror of
https://github.com/vectorize-io/hindsight.git
synced 2026-09-14 19:31:49 +08:00
fix(api): ignore inherited v1 base URL for Codex (#1718)
This commit is contained in:
@@ -110,9 +110,15 @@ class CodexLLM(LLMInterface):
|
||||
"Or use a different provider (openai, anthropic, gemini) with API keys."
|
||||
) from e
|
||||
|
||||
# Use ChatGPT backend API endpoint
|
||||
if not self.base_url:
|
||||
# Use ChatGPT backend API endpoint. Codex auth is tied to
|
||||
# chatgpt.com/backend-api, not the OpenAI-compatible base URL used by
|
||||
# other providers. Deployments often set a global LLM_BASE_URL for an
|
||||
# OpenAI-compatible proxy; ignore that inherited value unless the user
|
||||
# explicitly provides a Codex backend URL.
|
||||
if not self.base_url or self.base_url.rstrip("/").endswith("/v1"):
|
||||
self.base_url = "https://chatgpt.com/backend-api"
|
||||
else:
|
||||
self.base_url = self.base_url.rstrip("/")
|
||||
|
||||
# Normalize model name (strip openai/ prefix if present)
|
||||
if self.model.startswith("openai/"):
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
"""Tests for Codex provider base URL handling."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from hindsight_api.engine.providers.codex_llm import CodexLLM
|
||||
|
||||
|
||||
def _make(base_url: str) -> CodexLLM:
|
||||
with (
|
||||
patch.object(CodexLLM, "_load_codex_auth", return_value=("at", "acct")),
|
||||
patch.object(CodexLLM, "_load_codex_refresh_token", return_value="rt"),
|
||||
):
|
||||
return CodexLLM(
|
||||
provider="openai-codex",
|
||||
api_key="ignored",
|
||||
base_url=base_url,
|
||||
model="gpt-5.4-mini",
|
||||
)
|
||||
|
||||
|
||||
def test_codex_uses_chatgpt_backend_when_base_url_empty():
|
||||
assert _make("").base_url == "https://chatgpt.com/backend-api"
|
||||
|
||||
|
||||
def test_codex_ignores_inherited_openai_compatible_v1_base_url():
|
||||
assert _make("https://newapi.example.com/v1").base_url == "https://chatgpt.com/backend-api"
|
||||
|
||||
|
||||
def test_codex_preserves_explicit_codex_backend_base_url_without_trailing_slash():
|
||||
assert _make("https://chatgpt.example.com/backend-api/").base_url == "https://chatgpt.example.com/backend-api"
|
||||
Reference in New Issue
Block a user