@@ -475,27 +475,15 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
477func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map[string]string) (fantasy.Provider, error) {
477func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map[string]string) (fantasy.Provider, error) {
478− hasBearerAuth := false
479− for key := range headers {
480− if strings.ToLower(key) == "authorization" {
481− hasBearerAuth = true
486− isBearerToken := strings.HasPrefix(apiKey, "Bearer ")
488 var opts []anthropic.Option
478 var opts []anthropic.Option
489− if apiKey != "" && !hasBearerAuth {
491− slog.Debug("API key starts with 'Bearer ', using as Authorization header")
492− headers["Authorization"] = apiKey
493− apiKey = "" // clear apiKey to avoid using X-Api-Key header
480+ if strings.HasPrefix(apiKey, "Bearer ") {
481+ // NOTE: Prevent the SDK from picking up the API key from env.
482+ os.Setenv("ANTHROPIC_API_KEY", "")
484+ headers["Authorization"] = apiKey
497− if apiKey != "" {
485+ } else if apiKey != "" {
498− // Use standard X-Api-Key header
486+ // X-Api-Key header
499 opts = append(opts, anthropic.WithAPIKey(apiKey))
487 opts = append(opts, anthropic.WithAPIKey(apiKey))