@@ -121,7 +121,6 @@ func Load(workingDir string, debug bool) (*Config, error) {
121
121
122
122
configureViper ()
123
123
setDefaults (debug )
124
- setProviderDefaults ()
125
124
126
125
// Read global config
127
126
if err := readConfig (viper .ReadInConfig ()); err != nil {
@@ -131,6 +130,8 @@ func Load(workingDir string, debug bool) (*Config, error) {
131
130
// Load and merge local config
132
131
mergeLocalConfig (workingDir )
133
132
133
+ setProviderDefaults ()
134
+
134
135
// Apply configuration to the struct
135
136
if err := viper .Unmarshal (cfg ); err != nil {
136
137
return cfg , fmt .Errorf ("failed to unmarshal config: %w" , err )
@@ -213,7 +214,8 @@ func setDefaults(debug bool) {
213
214
}
214
215
}
215
216
216
- // setProviderDefaults configures LLM provider defaults based on environment variables.
217
+ // setProviderDefaults configures LLM provider defaults based on provider provided by
218
+ // environment variables and configuration file.
217
219
func setProviderDefaults () {
218
220
// Set all API keys we can find in the environment
219
221
if apiKey := os .Getenv ("ANTHROPIC_API_KEY" ); apiKey != "" {
@@ -228,48 +230,53 @@ func setProviderDefaults() {
228
230
if apiKey := os .Getenv ("GROQ_API_KEY" ); apiKey != "" {
229
231
viper .SetDefault ("providers.groq.apiKey" , apiKey )
230
232
}
233
+ if apiKey := os .Getenv ("OPENROUTER_API_KEY" ); apiKey != "" {
234
+ viper .SetDefault ("providers.openrouter.apiKey" , apiKey )
235
+ }
231
236
232
237
// Use this order to set the default models
233
238
// 1. Anthropic
234
239
// 2. OpenAI
235
240
// 3. Google Gemini
236
241
// 4. Groq
237
- // 5. AWS Bedrock
242
+ // 5. OpenRouter
243
+ // 6. AWS Bedrock
244
+ // 7. Azure
245
+
238
246
// Anthropic configuration
239
- if apiKey := os . Getenv ( "ANTHROPIC_API_KEY" ); apiKey != "" {
247
+ if viper . Get ( "providers.anthropic.apiKey" ) != "" {
240
248
viper .SetDefault ("agents.coder.model" , models .Claude37Sonnet )
241
249
viper .SetDefault ("agents.task.model" , models .Claude37Sonnet )
242
250
viper .SetDefault ("agents.title.model" , models .Claude37Sonnet )
243
251
return
244
252
}
245
253
246
254
// OpenAI configuration
247
- if apiKey := os . Getenv ( "OPENAI_API_KEY" ); apiKey != "" {
255
+ if viper . Get ( "providers.openai.apiKey" ) != "" {
248
256
viper .SetDefault ("agents.coder.model" , models .GPT41 )
249
257
viper .SetDefault ("agents.task.model" , models .GPT41Mini )
250
258
viper .SetDefault ("agents.title.model" , models .GPT41Mini )
251
259
return
252
260
}
253
261
254
262
// Google Gemini configuration
255
- if apiKey := os . Getenv ( "GEMINI_API_KEY" ); apiKey != "" {
263
+ if viper . Get ( "providers.google.gemini.apiKey" ) != "" {
256
264
viper .SetDefault ("agents.coder.model" , models .Gemini25 )
257
265
viper .SetDefault ("agents.task.model" , models .Gemini25Flash )
258
266
viper .SetDefault ("agents.title.model" , models .Gemini25Flash )
259
267
return
260
268
}
261
269
262
270
// Groq configuration
263
- if apiKey := os . Getenv ( "GROQ_API_KEY" ); apiKey != "" {
271
+ if viper . Get ( "providers.groq.apiKey" ) != "" {
264
272
viper .SetDefault ("agents.coder.model" , models .QWENQwq )
265
273
viper .SetDefault ("agents.task.model" , models .QWENQwq )
266
274
viper .SetDefault ("agents.title.model" , models .QWENQwq )
267
275
return
268
276
}
269
277
270
278
// OpenRouter configuration
271
- if apiKey := os .Getenv ("OPENROUTER_API_KEY" ); apiKey != "" {
272
- viper .SetDefault ("providers.openrouter.apiKey" , apiKey )
279
+ if viper .Get ("providers.openrouter.apiKey" ) != "" {
273
280
viper .SetDefault ("agents.coder.model" , models .OpenRouterClaude37Sonnet )
274
281
viper .SetDefault ("agents.task.model" , models .OpenRouterClaude37Sonnet )
275
282
viper .SetDefault ("agents.title.model" , models .OpenRouterClaude35Haiku )
0 commit comments