fix: support x-api-key header in Anthropic messages endpoint (Claude Code compat)

Claude Code sends x-api-key instead of Authorization Bearer. Now accepts both.
This commit is contained in:
Zebratic committed 2026-03-18 01:31:58 +00:00
1 parent 4c222c036a
commit 9c9ff51b87
1 file changed
+4 -1
@@ -328,7 +328,10 @@ export async function handleAnthropicMessages(request: Request): Promise<Respons
const isStreaming = input.stream ?? false;
// Authenticate
const auth = await authenticateApiKey(request.headers.get("Authorization"));
// Support both OpenAI-style "Authorization: Bearer <key>" and Anthropic-style "x-api-key: <key>"
const authHeader = request.headers.get("Authorization") ??
(request.headers.get("x-api-key") ? `Bearer ${request.headers.get("x-api-key")}` : null);
const auth = await authenticateApiKey(authHeader);
if (!auth) return invalidApiKey().toResponse();
// Extract client info