on main help sign in
fix(openrouter): fix api key validation for openrouter (#997)

`/models` is accessible for everyone on OpenRouter, without the need for any authorization. The `Authorization: Bearer *` was basically always ignore by their API. Using a different private API to validate the key for OpenRouter.

commit913ea55074c698d26ab2fa69c9298b00e53d69fc authorAndrey Nering <andreynering@users.noreply.github.com> dateMon 8 Sep 2025, 16:35 (1 year ago) parent92552fe
1 file changed+5−1
internal/config/config.go+5−1
internal/config/config.go+5−1
@@ -460,7 +460,11 @@ func (c *ProviderConfig) TestConnection(resolver VariableResolver) error {
460460 if baseURL == "" {
461461 baseURL = "https://api.openai.com/v1"
462462 }
463− testURL = baseURL + "/models"
463+ if c.Name == "OpenRouter" {
464+ testURL = baseURL + "/credits"
465+ } else {
466+ testURL = baseURL + "/models"
467+ }
464468 headers["Authorization"] = "Bearer " + apiKey
465469 case catwalk.TypeAnthropic:
466470 baseURL, _ := resolver.ResolveValue(c.BaseURL)