MCPcopy
hub / github.com/mudler/LocalAI / applyAuthHeader

Function applyAuthHeader

backend/go/cloud-proxy/proxy.go:414–424  ·  view source on GitHub ↗

applyAuthHeader writes the appropriate authorization header for the provider. OpenAI/Anthropic/most providers use Bearer; Anthropic historically uses x-api-key + anthropic-version, but accepts Bearer too via the OpenAI-compatible path. Default to Bearer when provider is empty (passthrough mode where

(req *http.Request, provider, key string)

Source from the content-addressed store, hash-verified

412// is empty (passthrough mode where the operator doesn't claim a
413// provider).
414func applyAuthHeader(req *http.Request, provider, key string) {
415 switch provider {
416 case providerAnthropic:
417 req.Header.Set("x-api-key", key)
418 if req.Header.Get("anthropic-version") == "" {
419 req.Header.Set("anthropic-version", "2023-06-01")
420 }
421 default:
422 req.Header.Set("Authorization", "Bearer "+key)
423 }
424}
425
426// isHopByHopHeader returns true for headers that should not be
427// forwarded from the client request to the upstream (RFC 7230 §6.1

Callers 4

ForwardMethod · 0.85
doOpenAIRequestMethod · 0.85
doAnthropicRequestMethod · 0.85

Calls 2

SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected