diff --git a/pkg/config/config.go b/pkg/config/config.go index 190341224..2bcb002e0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -609,6 +609,9 @@ type ModelConfig struct { MaxTokensField string `json:"max_tokens_field,omitempty"` // Field name for max tokens (e.g., "max_completion_tokens") RequestTimeout int `json:"request_timeout,omitempty"` ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive + + // TLS configuration + InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"` // Skip TLS certificate verification (for development/testing only) } // Validate checks if the ModelConfig has all required fields. diff --git a/pkg/providers/factory_provider.go b/pkg/providers/factory_provider.go index e99e07bc2..23c302c9a 100644 --- a/pkg/providers/factory_provider.go +++ b/pkg/providers/factory_provider.go @@ -86,12 +86,13 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err if apiBase == "" { apiBase = getDefaultAPIBase(protocol) } - return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( + return NewHTTPProviderWithOptions( cfg.APIKey, apiBase, cfg.Proxy, cfg.MaxTokensField, cfg.RequestTimeout, + cfg.InsecureSkipVerify, ), modelID, nil case "litellm", "openrouter", "groq", "zhipu", "gemini", "nvidia", @@ -106,12 +107,13 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err if apiBase == "" { apiBase = getDefaultAPIBase(protocol) } - return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( + return NewHTTPProviderWithOptions( cfg.APIKey, apiBase, cfg.Proxy, cfg.MaxTokensField, cfg.RequestTimeout, + cfg.InsecureSkipVerify, ), modelID, nil case "anthropic": @@ -131,12 +133,13 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err if cfg.APIKey == "" { return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model) } - return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( + return NewHTTPProviderWithOptions( cfg.APIKey, apiBase, cfg.Proxy, cfg.MaxTokensField, cfg.RequestTimeout, + cfg.InsecureSkipVerify, ), modelID, nil case "anthropic-messages": diff --git a/pkg/providers/http_provider.go b/pkg/providers/http_provider.go index 5c328f418..ffe2eca8a 100644 --- a/pkg/providers/http_provider.go +++ b/pkg/providers/http_provider.go @@ -30,6 +30,21 @@ func NewHTTPProviderWithMaxTokensField(apiKey, apiBase, proxy, maxTokensField st func NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( apiKey, apiBase, proxy, maxTokensField string, requestTimeoutSeconds int, +) *HTTPProvider { + return NewHTTPProviderWithOptions( + apiKey, + apiBase, + proxy, + maxTokensField, + requestTimeoutSeconds, + false, + ) +} + +func NewHTTPProviderWithOptions( + apiKey, apiBase, proxy, maxTokensField string, + requestTimeoutSeconds int, + insecureSkipVerify bool, ) *HTTPProvider { return &HTTPProvider{ delegate: openai_compat.NewProvider( @@ -38,6 +53,7 @@ func NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( proxy, openai_compat.WithMaxTokensField(maxTokensField), openai_compat.WithRequestTimeout(time.Duration(requestTimeoutSeconds)*time.Second), + openai_compat.WithInsecureSkipVerify(insecureSkipVerify), ), } } diff --git a/pkg/providers/openai_compat/provider.go b/pkg/providers/openai_compat/provider.go index f97bf3acd..cd74cc418 100644 --- a/pkg/providers/openai_compat/provider.go +++ b/pkg/providers/openai_compat/provider.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "crypto/tls" "encoding/json" "fmt" "io" @@ -54,6 +55,24 @@ func WithRequestTimeout(timeout time.Duration) Option { } } +func WithInsecureSkipVerify(skip bool) Option { + return func(p *Provider) { + if skip { + transport := p.httpClient.Transport + if transport == nil { + transport = &http.Transport{} + } + if tr, ok := transport.(*http.Transport); ok { + if tr.TLSClientConfig == nil { + tr.TLSClientConfig = &tls.Config{} + } + tr.TLSClientConfig.InsecureSkipVerify = true + p.httpClient.Transport = tr + } + } + } +} + func NewProvider(apiKey, apiBase, proxy string, opts ...Option) *Provider { client := &http.Client{ Timeout: defaultRequestTimeout,