Add required headers for anthropic api requests.

This commit is contained in:
Chad Curtis committed 2025-10-19 06:33:24 +00:00
1 parent 97f312c3d3
commit 3555d05d54
1 file changed
+15
+15
View File
@@ -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