diff --git a/crates/goose/src/providers/openai.rs b/crates/goose/src/providers/openai.rs index 7a1398cfbfa0..3f493dcd8f6e 100644 --- a/crates/goose/src/providers/openai.rs +++ b/crates/goose/src/providers/openai.rs @@ -121,7 +121,16 @@ impl OpenAiProvider { let url = url::Url::parse(&config.base_url) .map_err(|e| anyhow::anyhow!("Invalid base URL '{}': {}", config.base_url, e))?; - let host = format!("{}://{}", url.scheme(), url.host_str().unwrap_or("")); + let host = if let Some(port) = url.port() { + format!( + "{}://{}:{}", + url.scheme(), + url.host_str().unwrap_or(""), + port + ) + } else { + format!("{}://{}", url.scheme(), url.host_str().unwrap_or("")) + }; let base_path = url.path().trim_start_matches('/').to_string(); let base_path = if base_path.is_empty() { "v1/chat/completions".to_string()