fix: wildcard model expansion (openai)

This commit is contained in:
Chris 2025-12-01 14:20:26 +08:00
parent 4fffd33ccf
commit 39602c34dc
No known key found for this signature in database
GPG key ID: 05495E5DA0FFEC75

View file

@ -710,14 +710,22 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
if api_key is None:
api_key = get_secret_str("OPENAI_API_KEY")
# Strip api_base to just the base URL (scheme + host + port)
# Strip api_base to just the base URL (scheme + host + port + path)
parsed_url = httpx.URL(api_base)
base_url = f"{parsed_url.scheme}://{parsed_url.host}"
if parsed_url.port:
base_url += f":{parsed_url.port}"
# Preserve the path from api_base to handle subdomains and custom endpoints
if parsed_url.path and parsed_url.path != "/":
base_url += parsed_url.path.rstrip("/")
response = litellm.module_level_client.get(
url=f"{base_url}/v1/models",
url=(
f"{base_url}/models"
if base_url.endswith("/v1") or base_url.endswith("/v1/")
else f"{base_url}/v1/models"
),
headers={"Authorization": f"Bearer {api_key}"},
)