on main help sign in
fix: initial api key load (#1672)
commit1c5443358e99bb196bdd812969109126cb99937f authorKujtim Hoxha <kujtimii.h@gmail.com> dateFri 19 Dec 2025, 13:22 (1 year ago) parent4f6d0e9
2 files changed+5−9
internal/agent/coordinator.go+4−6 internal/config/config.go+1−3
internal/agent/coordinator.go+4−6
@@ -516,14 +516,13 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
516516 }, nil
517517}
518518
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) {
520520 var opts []anthropic.Option
521521
522− if strings.HasPrefix(apiKey, "Bearer ") {
522+ if isOauth {
523523 // NOTE: Prevent the SDK from picking up the API key from env.
524524 os.Setenv("ANTHROPIC_API_KEY", "")
525−
526− headers["Authorization"] = apiKey
525+ headers["Authorization"] = fmt.Sprintf("Bearer %s", apiKey)
527526 } else if apiKey != "" {
528527 // X-Api-Key header
529528 opts = append(opts, anthropic.WithAPIKey(apiKey))
@@ -541,7 +540,6 @@ func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map
541540 httpClient := log.NewHTTPClient()
542541 opts = append(opts, anthropic.WithHTTPClient(httpClient))
543542 }
544−
545543 return anthropic.New(opts...)
546544}
547545
@@ -722,7 +720,7 @@ func (c *coordinator) buildProvider(providerCfg config.ProviderConfig, model con
722720 case openai.Name:
723721 return c.buildOpenaiProvider(baseURL, apiKey, headers)
724722 case anthropic.Name:
725− return c.buildAnthropicProvider(baseURL, apiKey, headers)
723+ return c.buildAnthropicProvider(baseURL, apiKey, headers, providerCfg.OAuthToken != nil)
726724 case openrouter.Name:
727725 return c.buildOpenrouterProvider(baseURL, apiKey, headers)
728726 case azure.Name:
internal/config/config.go+1−3
@@ -550,13 +550,12 @@ func (c *Config) RefreshOAuthToken(ctx context.Context, providerID string) error
550550
551551 slog.Info("Successfully refreshed OAuth token", "provider", providerID)
552552 providerConfig.OAuthToken = newToken
553+ providerConfig.APIKey = newToken.AccessToken
553554
554555 switch providerID {
555556 case string(catwalk.InferenceProviderAnthropic):
556− providerConfig.APIKey = fmt.Sprintf("Bearer %s", newToken.AccessToken)
557557 providerConfig.SetupClaudeCode()
558558 case string(catwalk.InferenceProviderCopilot):
559− providerConfig.APIKey = newToken.AccessToken
560559 providerConfig.SetupGitHubCopilot()
561560 }
562561
@@ -595,7 +594,6 @@ func (c *Config) SetProviderAPIKey(providerID string, apiKey any) error {
595594 providerConfig.OAuthToken = v
596595 switch providerID {
597596 case string(catwalk.InferenceProviderAnthropic):
598− providerConfig.APIKey = fmt.Sprintf("Bearer %s", v.AccessToken)
599597 providerConfig.SetupClaudeCode()
600598 case string(catwalk.InferenceProviderCopilot):
601599 providerConfig.SetupGitHubCopilot()