fix(claude): handle X-CPA-CLAUDE-1M header and ensure proper beta merging logic
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/textproto"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -783,11 +784,21 @@ func applyClaudeHeaders(r *http.Request, auth *cliproxyauth.Auth, apiKey string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge extra betas from request body
|
hasClaude1MHeader := false
|
||||||
if len(extraBetas) > 0 {
|
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)
|
existingSet := make(map[string]bool)
|
||||||
for _, b := range strings.Split(baseBetas, ",") {
|
for _, b := range strings.Split(baseBetas, ",") {
|
||||||
existingSet[strings.TrimSpace(b)] = true
|
betaName := strings.TrimSpace(b)
|
||||||
|
if betaName != "" {
|
||||||
|
existingSet[betaName] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, beta := range extraBetas {
|
for _, beta := range extraBetas {
|
||||||
beta = strings.TrimSpace(beta)
|
beta = strings.TrimSpace(beta)
|
||||||
@@ -796,6 +807,9 @@ func applyClaudeHeaders(r *http.Request, auth *cliproxyauth.Auth, apiKey string,
|
|||||||
existingSet[beta] = true
|
existingSet[beta] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if hasClaude1MHeader && !existingSet["context-1m-2025-08-07"] {
|
||||||
|
baseBetas += ",context-1m-2025-08-07"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
r.Header.Set("Anthropic-Beta", baseBetas)
|
r.Header.Set("Anthropic-Beta", baseBetas)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user