From aa731a9596475e231483b92fbf212928ab657d56 Mon Sep 17 00:00:00 2001 From: Spike Wang Date: Tue, 21 Apr 2026 06:10:00 -0700 Subject: [PATCH] Stop load openai fast model for openapi compatible custom endpoint (#8644) --- crates/goose/src/providers/openai.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/goose/src/providers/openai.rs b/crates/goose/src/providers/openai.rs index 330dfb3b..23736f23 100644 --- a/crates/goose/src/providers/openai.rs +++ b/crates/goose/src/providers/openai.rs @@ -72,13 +72,27 @@ pub struct OpenAiProvider { impl OpenAiProvider { pub async fn from_env(model: ModelConfig) -> Result { - let model = model.with_fast(OPEN_AI_DEFAULT_FAST_MODEL, OPEN_AI_PROVIDER_NAME)?; - let config = crate::config::Config::global(); let host: String = config .get_param("OPENAI_HOST") .unwrap_or_else(|_| "https://api.openai.com".to_string()); + // Only apply the default fast model when talking to OpenAI directly. + // Custom/compatible endpoints likely don't serve gpt-4o-mini, so + // leave fast_model unset (complete_fast will fall back to the main model). + // Parse the URL and compare the hostname exactly to avoid false positives + // (e.g. https://api.openai.com.local:8000 or proxy paths containing api.openai.com). + let is_openai = url::Url::parse(&host) + .ok() + .and_then(|u| u.host_str().map(|h| h.to_ascii_lowercase())) + .map(|h| h == "api.openai.com" || h.ends_with(".api.openai.com")) + .unwrap_or(false); + let model = if is_openai { + model.with_fast(OPEN_AI_DEFAULT_FAST_MODEL, OPEN_AI_PROVIDER_NAME)? + } else { + model + }; + let secrets = config .get_secrets("OPENAI_API_KEY", &["OPENAI_CUSTOM_HEADERS"]) .unwrap_or_default();