diff --git a/pkg/config/config.go b/pkg/config/config.go index 1d34f56f3..5ebc022c8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -188,6 +188,7 @@ type ProviderConfig struct { Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"` AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"` ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` //only for Github Copilot, `stdio` or `grpc` + APIFormat string `json:"api_format,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_FORMAT"` // "responses" to use OpenAI Responses API } type GatewayConfig struct { diff --git a/pkg/providers/codex_provider.go b/pkg/providers/codex_provider.go index 6dff3a52e..ea9a5bb89 100644 --- a/pkg/providers/codex_provider.go +++ b/pkg/providers/codex_provider.go @@ -26,8 +26,15 @@ type CodexProvider struct { const defaultCodexInstructions = "You are Codex, a coding assistant." func NewCodexProvider(token, accountID string) *CodexProvider { + return NewCodexProviderWithBase(token, accountID, "https://chatgpt.com/backend-api/codex") +} + +func NewCodexProviderWithBase(token, accountID, baseURL string) *CodexProvider { + if baseURL == "" { + baseURL = "https://chatgpt.com/backend-api/codex" + } opts := []option.RequestOption{ - option.WithBaseURL("https://chatgpt.com/backend-api/codex"), + option.WithBaseURL(baseURL), option.WithAPIKey(token), option.WithHeader("originator", "codex_cli_rs"), option.WithHeader("OpenAI-Beta", "responses=experimental"), diff --git a/pkg/providers/http_provider.go b/pkg/providers/http_provider.go index 4cf2c6db2..1634a600b 100644 --- a/pkg/providers/http_provider.go +++ b/pkg/providers/http_provider.go @@ -246,6 +246,13 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) { if cfg.Providers.OpenAI.AuthMethod == "oauth" || cfg.Providers.OpenAI.AuthMethod == "token" { return createCodexAuthProvider() } + if cfg.Providers.OpenAI.APIFormat == "responses" { + base := cfg.Providers.OpenAI.APIBase + if base == "" { + base = "https://api.openai.com/v1" + } + return NewCodexProviderWithBase(cfg.Providers.OpenAI.APIKey, "", base), nil + } apiKey = cfg.Providers.OpenAI.APIKey apiBase = cfg.Providers.OpenAI.APIBase if apiBase == "" {