Files
zeekay d26645ed85 gate: x-api-key is a credential, as Bearer is
The Anthropic wire carries its key on x-api-key, and Anthropic SDKs and the
desktop clients built on them send it there. The controller read it, but the
gate's presence check read Authorization alone, so /v1/messages with a valid
sk- key on x-api-key answered 401 before the controller saw it.

controllers.Credential reads Bearer, else x-api-key, the order extractAPIKey
already uses for the rate limit; the gate and the Anthropic controller both
call it, so a request carrying both headers is admitted and billed on one key.

Claude-Session: https://claude.ai/code/session_01M8RoubcPN71KgJuZ8LdBUL
2026-10-15 05:24:17 -07:00

29 lines
1.1 KiB
Go

// Copyright 2023-2025 Hanzo AI Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controllers
import "strings"
// Credential is the key a caller presented: Authorization: Bearer, else
// x-api-key, the header the Anthropic wire and its SDKs carry the key on. The
// router's gate and the Anthropic controller both read it here, so a request
// carrying both headers is admitted and billed on the same key.
func Credential(authorization, apiKey string) string {
if after, ok := strings.CutPrefix(authorization, "Bearer "); ok {
return after
}
return strings.TrimSpace(apiKey)
}