@@ -475,27 +475,15 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
475475}
476476
477477func (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
482− break
483− }
484− }
485−
486− isBearerToken := strings.HasPrefix(apiKey, "Bearer ")
487−
488478 var opts []anthropic.Option
489− if apiKey != "" && !hasBearerAuth {
490− if isBearerToken {
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
494− }
495− }
496479
497− if apiKey != "" {
498− // Use standard 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", "")
483+
484+ headers["Authorization"] = apiKey
485+ } else if apiKey != "" {
486+ // X-Api-Key header
499487 opts = append(opts, anthropic.WithAPIKey(apiKey))
500488 }
501489