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)
| 241 | // make it impossible to configure, since the credentials live in the AWS chain |
| 242 | // rather than the config file. |
| 243 | func checkAPIKeyRequirement(providerName, apiKey, apiKeyCmd string, preset llm.Provider, isPreset bool) error { |
| 244 | if apiKey != "" || strings.TrimSpace(apiKeyCmd) != "" { |
| 245 | return nil |
| 246 | } |
| 247 | switch { |
| 248 | case isPreset && preset.AmbientAuth: |
| 249 | return nil |
| 250 | case isPreset && preset.EnvVar != "": |
| 251 | if os.Getenv(preset.EnvVar) == "" { |
| 252 | 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) |
| 253 | } |
| 254 | return nil |
| 255 | default: |
| 256 | return fmt.Errorf("API key is required for provider %s (configure it or set providers.%s.api_key_cmd)", providerName, providerName) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func applyOfficialProviderConfig(configPath string, cfg *Config, result providerTUIResult) error { |
| 261 | if result.provider == "" { |
no outgoing calls