diff --git a/internal/runtime/executor/claude_executor.go b/internal/runtime/executor/claude_executor.go index 0845d168..75ea04e1 100644 --- a/internal/runtime/executor/claude_executor.go +++ b/internal/runtime/executor/claude_executor.go @@ -13,6 +13,7 @@ import ( "fmt" "io" "net/http" + "net/textproto" "runtime" "strings" "time" @@ -783,11 +784,21 @@ func applyClaudeHeaders(r *http.Request, auth *cliproxyauth.Auth, apiKey string, } } - // Merge extra betas from request body - if len(extraBetas) > 0 { + hasClaude1MHeader := false + if ginHeaders != nil { + if _, ok := ginHeaders[textproto.CanonicalMIMEHeaderKey("X-CPA-CLAUDE-1M")]; ok { + hasClaude1MHeader = true + } + } + + // Merge extra betas from request body and request flags. + if len(extraBetas) > 0 || hasClaude1MHeader { existingSet := make(map[string]bool) for _, b := range strings.Split(baseBetas, ",") { - existingSet[strings.TrimSpace(b)] = true + betaName := strings.TrimSpace(b) + if betaName != "" { + existingSet[betaName] = true + } } for _, beta := range extraBetas { beta = strings.TrimSpace(beta) @@ -796,6 +807,9 @@ func applyClaudeHeaders(r *http.Request, auth *cliproxyauth.Auth, apiKey string, existingSet[beta] = true } } + if hasClaude1MHeader && !existingSet["context-1m-2025-08-07"] { + baseBetas += ",context-1m-2025-08-07" + } } r.Header.Set("Anthropic-Beta", baseBetas)