diff --git a/agent/llm/providers/openai/openai.go b/agent/llm/providers/openai/openai.go index 52d0afa4..264b5a80 100644 --- a/agent/llm/providers/openai/openai.go +++ b/agent/llm/providers/openai/openai.go @@ -129,17 +129,11 @@ type Provider struct { adapters []adapters.CapabilityAdapter } -// buildAPIURL builds the complete API URL from host and endpoint -// If host ends with /, it's used as-is (user has specified full path) -// Otherwise, /v1 prefix is added automatically (standard for OpenAI-compatible APIs) +// buildAPIURL builds the complete API URL from host and endpoint. +// Delegates to the shared connector.BuildAPIURL for consistent URL building +// across the agent LLM path and the sandbox proxy path. func buildAPIURL(host, endpoint string) string { - // If host ends with /, use it as-is (user has specified full path like /v1/ or /api/) - // Otherwise, add /v1 prefix (standard for OpenAI-compatible APIs) - if !strings.HasSuffix(host, "/") { - endpoint = "/v1" + endpoint - } - host = strings.TrimSuffix(host, "/") - return host + endpoint + return connector.BuildAPIURL(host, endpoint) } // New create a new OpenAI provider with capability adapters diff --git a/agent/sandbox/claude/command.go b/agent/sandbox/claude/command.go index 7736206f..e2e4648d 100644 --- a/agent/sandbox/claude/command.go +++ b/agent/sandbox/claude/command.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/yaoapp/gou/connector" agentContext "github.com/yaoapp/yao/agent/context" ) @@ -355,11 +356,9 @@ func BuildProxyConfig(opts *Options) ([]byte, error) { return nil, fmt.Errorf("options is required") } - // Build backend URL - ensure it ends with /chat/completions - backendURL := opts.ConnectorHost - if !strings.HasSuffix(backendURL, "/chat/completions") { - backendURL = strings.TrimSuffix(backendURL, "/") + "/chat/completions" - } + // Build backend URL using the shared connector.BuildAPIURL helper + // so that the /v1 prefix is applied consistently with the agent LLM path. + backendURL := connector.BuildAPIURL(opts.ConnectorHost, "/chat/completions") config := map[string]interface{}{ "backend": backendURL,