on main help sign in
fix: initial api key load (#1672)
1c54433Kujtim Hoxha
internal/agent/coordinator.go+4−6
@@ -516,14 +516,13 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
516 }, nil
516 }, nil
517}
517}
518
518
519−func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map[string]string) (fantasy.Provider, error) {
519+func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map[string]string, isOauth bool) (fantasy.Provider, error) {
520 var opts []anthropic.Option
520 var opts []anthropic.Option
521
521
522− if strings.HasPrefix(apiKey, "Bearer ") {
522+ if isOauth {
523 // NOTE: Prevent the SDK from picking up the API key from env.
523 // NOTE: Prevent the SDK from picking up the API key from env.
524 os.Setenv("ANTHROPIC_API_KEY", "")
524 os.Setenv("ANTHROPIC_API_KEY", "")
525−
526− headers["Authorization"] = apiKey
525+ headers["Authorization"] = fmt.Sprintf("Bearer %s", apiKey)
527 } else if apiKey != "" {
526 } else if apiKey != "" {
528 // X-Api-Key header
527 // X-Api-Key header
529 opts = append(opts, anthropic.WithAPIKey(apiKey))
528 opts = append(opts, anthropic.WithAPIKey(apiKey))
@@ -541,7 +540,6 @@ func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map
541 httpClient := log.NewHTTPClient()
540 httpClient := log.NewHTTPClient()
542 opts = append(opts, anthropic.WithHTTPClient(httpClient))
541 opts = append(opts, anthropic.WithHTTPClient(httpClient))
543 }
542 }
544−
545 return anthropic.New(opts...)
543 return anthropic.New(opts...)
546}
544}
547
545
@@ -722,7 +720,7 @@ func (c *coordinator) buildProvider(providerCfg config.ProviderConfig, model con
722 case openai.Name:
720 case openai.Name:
723 return c.buildOpenaiProvider(baseURL, apiKey, headers)
721 return c.buildOpenaiProvider(baseURL, apiKey, headers)
724 case anthropic.Name:
722 case anthropic.Name:
725− return c.buildAnthropicProvider(baseURL, apiKey, headers)
723+ return c.buildAnthropicProvider(baseURL, apiKey, headers, providerCfg.OAuthToken != nil)
726 case openrouter.Name:
724 case openrouter.Name:
727 return c.buildOpenrouterProvider(baseURL, apiKey, headers)
725 return c.buildOpenrouterProvider(baseURL, apiKey, headers)
728 case azure.Name:
726 case azure.Name:
internal/config/config.go+1−3
@@ -550,13 +550,12 @@ func (c *Config) RefreshOAuthToken(ctx context.Context, providerID string) error
550
550
551 slog.Info("Successfully refreshed OAuth token", "provider", providerID)
551 slog.Info("Successfully refreshed OAuth token", "provider", providerID)
552 providerConfig.OAuthToken = newToken
552 providerConfig.OAuthToken = newToken
553+ providerConfig.APIKey = newToken.AccessToken
553
554
554 switch providerID {
555 switch providerID {
555 case string(catwalk.InferenceProviderAnthropic):
556 case string(catwalk.InferenceProviderAnthropic):
556− providerConfig.APIKey = fmt.Sprintf("Bearer %s", newToken.AccessToken)
557 providerConfig.SetupClaudeCode()
557 providerConfig.SetupClaudeCode()
558 case string(catwalk.InferenceProviderCopilot):
558 case string(catwalk.InferenceProviderCopilot):
559− providerConfig.APIKey = newToken.AccessToken
560 providerConfig.SetupGitHubCopilot()
559 providerConfig.SetupGitHubCopilot()
561 }
560 }
562
561
@@ -595,7 +594,6 @@ func (c *Config) SetProviderAPIKey(providerID string, apiKey any) error {
595 providerConfig.OAuthToken = v
594 providerConfig.OAuthToken = v
596 switch providerID {
595 switch providerID {
597 case string(catwalk.InferenceProviderAnthropic):
596 case string(catwalk.InferenceProviderAnthropic):
598− providerConfig.APIKey = fmt.Sprintf("Bearer %s", v.AccessToken)
599 providerConfig.SetupClaudeCode()
597 providerConfig.SetupClaudeCode()
600 case string(catwalk.InferenceProviderCopilot):
598 case string(catwalk.InferenceProviderCopilot):
601 providerConfig.SetupGitHubCopilot()
599 providerConfig.SetupGitHubCopilot()