fix(provider): map 'free' model to openrouter/auto for OpenRouter free tier

When using OpenRouter with model set to 'free', the API returns an error
'free is not a valid model ID' because OpenRouter requires specific model
identifiers. This fix maps the 'free' alias to 'openrouter/auto' which
automatically selects the best available free model.

Closes #901
This commit is contained in:
opencode-assistant[bot] 2026-03-01 17:49:44 +08:00
parent f7136b6a5d
commit 352f4005f2

View file

@ -101,6 +101,10 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
} else { } else {
sel.apiBase = "https://openrouter.ai/api/v1" sel.apiBase = "https://openrouter.ai/api/v1"
} }
// Map "free" model alias to openrouter/auto for free tier access
if model == "free" {
sel.model = "openrouter/auto"
}
} }
case "zhipu", "glm": case "zhipu", "glm":
if cfg.Providers.Zhipu.APIKey != "" { if cfg.Providers.Zhipu.APIKey != "" {
@ -304,6 +308,10 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
} else { } else {
sel.apiBase = "https://openrouter.ai/api/v1" sel.apiBase = "https://openrouter.ai/api/v1"
} }
// Map "free" model alias to openrouter/auto for free tier access
if model == "free" {
sel.model = "openrouter/auto"
}
} else { } else {
return providerSelection{}, fmt.Errorf("no API key configured for model: %s", model) return providerSelection{}, fmt.Errorf("no API key configured for model: %s", model)
} }