48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
claude "github.com/Wei-Shaw/sub2api/internal/pkg/claude"
|
|
)
|
|
|
|
func applyClaudeRuntimeOptionalHeaders(req *http.Request) {
|
|
if req == nil {
|
|
return
|
|
}
|
|
for key, value := range claude.OptionalAPIHeaders() {
|
|
if strings.TrimSpace(value) == "" {
|
|
continue
|
|
}
|
|
setHeaderRaw(req.Header, resolveWireCasing(key), value)
|
|
}
|
|
}
|
|
|
|
func attributionOptionsForRequest(account *Account, tokenType string) attributionBlockOptions {
|
|
return attributionBlockOptions{
|
|
Entrypoint: claude.CurrentEntrypoint(),
|
|
Workload: claude.CurrentWorkload(),
|
|
OmitCCH: shouldOmitAttributionCCH(account, tokenType),
|
|
}
|
|
}
|
|
|
|
func shouldOmitAttributionCCH(account *Account, tokenType string) bool {
|
|
if strings.EqualFold(strings.TrimSpace(tokenType), "bedrock") {
|
|
return true
|
|
}
|
|
if account == nil {
|
|
return false
|
|
}
|
|
if account.Type == AccountTypeBedrock {
|
|
return true
|
|
}
|
|
for _, key := range []string{"provider", "upstream_provider"} {
|
|
switch strings.ToLower(strings.TrimSpace(account.GetExtraString(key))) {
|
|
case "bedrock", "anthropicaws", "anthropic_aws", "mantle":
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|