From 3555d05d54d5c1dbf8f3d3339e80f466d8d9ada8 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Sun, 19 Oct 2025 06:33:24 +0000 Subject: [PATCH] Add required headers for anthropic api requests. --- src/lib/ai-client.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib/ai-client.ts b/src/lib/ai-client.ts index d840b2d5..17297bd9 100644 --- a/src/lib/ai-client.ts +++ b/src/lib/ai-client.ts @@ -32,6 +32,21 @@ export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: s request = new Request(request, { headers }); } + // Add Anthropic-specific headers + // https://docs.anthropic.com/en/api/versioning + if (provider.id === 'anthropic') { + const headers = new Headers(request.headers); + headers.set('anthropic-version', '2023-06-01'); + // Required header for direct browser access + headers.set('anthropic-dangerous-direct-browser-access', 'true'); + // Anthropic expects x-api-key header instead of Authorization: Bearer + if (provider.apiKey) { + headers.set('x-api-key', provider.apiKey); + headers.delete('authorization'); // Remove the Bearer token that OpenAI client adds + } + request = new Request(request, { headers }); + } + // If Nostr authentication is required and we have a user, use NIP-98 if (provider.nostr && user?.signer) { // Create the NIP98 token