From 21c0bb00cc3585ffc338aaba818cfa681e91c52f Mon Sep 17 00:00:00 2001 From: vlascik Date: Mon, 25 Aug 2025 20:49:31 +0200 Subject: [PATCH] Allows use of a port number for a custom OpenAI provider (#4312) Signed-off-by: V. Lascik --- crates/goose/src/providers/openai.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/goose/src/providers/openai.rs b/crates/goose/src/providers/openai.rs index 7a1398cfbf..3f493dcd8f 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()