feat: add OpenCode Zen provider (opencode/ prefix)

Add opencode/ as a new protocol prefix backed by the OpenAI-compatible
API at https://opencode.ai/zen/v1, following the same pattern as
OpenRouter, Groq, DeepSeek, etc.

- Add "opencode" to the OpenAI-compatible provider switch case
- Register default API base https://opencode.ai/zen/v1
- Add usage example to config.example.json
This commit is contained in:
mqyang56 2026-02-27 16:17:06 +08:00
parent ec6da7a530
commit 94c2daa786
3 changed files with 10 additions and 2 deletions

View file

@ -32,6 +32,11 @@
"model": "deepseek/deepseek-chat",
"api_key": "sk-your-deepseek-key"
},
{
"model_name": "opencode-zen",
"model": "opencode/claude-sonnet-4-5",
"api_key": "your-opencode-zen-api-key"
},
{
"model_name": "loadbalanced-gpt4",
"model": "openai/gpt-5.2",

View file

@ -53,7 +53,7 @@ func ExtractProtocol(model string) (protocol, modelID string) {
// CreateProviderFromConfig creates a provider based on the ModelConfig.
// It uses the protocol prefix in the Model field to determine which provider to create.
// Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli, github-copilot
// Supported protocols: openai, anthropic, opencode, antigravity, claude-cli, codex-cli, github-copilot
// Returns the provider, the model ID (without protocol prefix), and any error.
func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, error) {
if cfg == nil {
@ -88,7 +88,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
case "openrouter", "groq", "zhipu", "gemini", "nvidia",
"ollama", "moonshot", "shengsuanyun", "deepseek", "cerebras",
"volcengine", "vllm", "qwen", "mistral":
"volcengine", "vllm", "qwen", "mistral", "opencode":
// All other OpenAI-compatible HTTP providers
if cfg.APIKey == "" && cfg.APIBase == "" {
return nil, "", fmt.Errorf("api_key or api_base is required for HTTP-based protocol %q", protocol)
@ -188,6 +188,8 @@ func getDefaultAPIBase(protocol string) string {
return "http://localhost:8000/v1"
case "mistral":
return "https://api.mistral.ai/v1"
case "opencode":
return "https://opencode.ai/zen/v1"
default:
return ""
}

View file

@ -108,6 +108,7 @@ func TestCreateProviderFromConfig_DefaultAPIBase(t *testing.T) {
{"vllm", "vllm"},
{"deepseek", "deepseek"},
{"ollama", "ollama"},
{"opencode", "opencode"},
}
for _, tt := range tests {