@@ -129,7 +129,6 @@ func Load(workingDir string, debug bool) (*Config, error) {
129
129
130
130
configureViper ()
131
131
setDefaults (debug )
132
- setProviderDefaults ()
133
132
134
133
// Read global config
135
134
if err := readConfig (viper .ReadInConfig ()); err != nil {
@@ -139,6 +138,8 @@ func Load(workingDir string, debug bool) (*Config, error) {
139
138
// Load and merge local config
140
139
mergeLocalConfig (workingDir )
141
140
141
+ setProviderDefaults ()
142
+
142
143
// Apply configuration to the struct
143
144
if err := viper .Unmarshal (cfg ); err != nil {
144
145
return cfg , fmt .Errorf ("failed to unmarshal config: %w" , err )
@@ -222,7 +223,8 @@ func setDefaults(debug bool) {
222
223
}
223
224
}
224
225
225
- // setProviderDefaults configures LLM provider defaults based on environment variables.
226
+ // setProviderDefaults configures LLM provider defaults based on provider provided by
227
+ // environment variables and configuration file.
226
228
func setProviderDefaults () {
227
229
// Set all API keys we can find in the environment
228
230
if apiKey := os .Getenv ("ANTHROPIC_API_KEY" ); apiKey != "" {
@@ -246,42 +248,44 @@ func setProviderDefaults() {
246
248
// 2. OpenAI
247
249
// 3. Google Gemini
248
250
// 4. Groq
249
- // 5. AWS Bedrock
251
+ // 5. OpenRouter
252
+ // 6. AWS Bedrock
253
+ // 7. Azure
254
+
250
255
// Anthropic configuration
251
- if apiKey := os . Getenv ( "ANTHROPIC_API_KEY" ); apiKey != "" {
256
+ if viper . Get ( "providers.anthropic.apiKey" ) != "" {
252
257
viper .SetDefault ("agents.coder.model" , models .Claude37Sonnet )
253
258
viper .SetDefault ("agents.task.model" , models .Claude37Sonnet )
254
259
viper .SetDefault ("agents.title.model" , models .Claude37Sonnet )
255
260
return
256
261
}
257
262
258
263
// OpenAI configuration
259
- if apiKey := os . Getenv ( "OPENAI_API_KEY" ); apiKey != "" {
264
+ if viper . Get ( "providers.openai.apiKey" ) != "" {
260
265
viper .SetDefault ("agents.coder.model" , models .GPT41 )
261
266
viper .SetDefault ("agents.task.model" , models .GPT41Mini )
262
267
viper .SetDefault ("agents.title.model" , models .GPT41Mini )
263
268
return
264
269
}
265
270
266
271
// Google Gemini configuration
267
- if apiKey := os . Getenv ( "GEMINI_API_KEY" ); apiKey != "" {
272
+ if viper . Get ( "providers.google.gemini.apiKey" ) != "" {
268
273
viper .SetDefault ("agents.coder.model" , models .Gemini25 )
269
274
viper .SetDefault ("agents.task.model" , models .Gemini25Flash )
270
275
viper .SetDefault ("agents.title.model" , models .Gemini25Flash )
271
276
return
272
277
}
273
278
274
279
// Groq configuration
275
- if apiKey := os . Getenv ( "GROQ_API_KEY" ); apiKey != "" {
280
+ if viper . Get ( "providers.groq.apiKey" ) != "" {
276
281
viper .SetDefault ("agents.coder.model" , models .QWENQwq )
277
282
viper .SetDefault ("agents.task.model" , models .QWENQwq )
278
283
viper .SetDefault ("agents.title.model" , models .QWENQwq )
279
284
return
280
285
}
281
286
282
287
// OpenRouter configuration
283
- if apiKey := os .Getenv ("OPENROUTER_API_KEY" ); apiKey != "" {
284
- viper .SetDefault ("providers.openrouter.apiKey" , apiKey )
288
+ if viper .Get ("providers.openrouter.apiKey" ) != "" {
285
289
viper .SetDefault ("agents.coder.model" , models .OpenRouterClaude37Sonnet )
286
290
viper .SetDefault ("agents.task.model" , models .OpenRouterClaude37Sonnet )
287
291
viper .SetDefault ("agents.title.model" , models .OpenRouterClaude35Haiku )
0 commit comments