checkAPIKeyRequirement decides whether a provider selection may be saved with no api_key. It mirrors the resolver's precedence (static api_key -> api_key_cmd -> env var), so an already-configured command satisfies the requirement and picking a model for such a provider does not fail and abandon the
(providerName, apiKey, apiKeyCmd string, preset llm.Provider, isPreset bool, entry ProviderEntry)
| 244 | // their credentials come from the environment chain or a dedicated token store |
| 245 | // rather than the config file. |
| 246 | func checkAPIKeyRequirement(providerName, apiKey, apiKeyCmd string, preset llm.Provider, isPreset bool, entry ProviderEntry) error { |
| 247 | if apiKey != "" || strings.TrimSpace(apiKeyCmd) != "" { |
| 248 | return nil |
| 249 | } |
| 250 | switch { |
| 251 | case isPreset && providerUsesExternalCredentials(preset, entry): |
| 252 | return nil |
| 253 | case isPreset && preset.EnvVar != "": |
| 254 | if os.Getenv(preset.EnvVar) == "" { |
| 255 | return fmt.Errorf("API key is required for provider %s (configure it, set providers.%s.api_key_cmd, or set $%s)", providerName, providerName, preset.EnvVar) |
| 256 | } |
| 257 | return nil |
| 258 | default: |
| 259 | return fmt.Errorf("API key is required for provider %s (configure it or set providers.%s.api_key_cmd)", providerName, providerName) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | func providerUsesExternalCredentials(preset llm.Provider, entry ProviderEntry) bool { |
| 264 | if preset.ExternalAuth { |