fix(ai): Add anthropic-dangerous-direct-browser-access header

- Required header for browser-based access to Anthropic API
- Added to both OAuth and regular API key authentication
- Ensures full browser compatibility
This commit is contained in:
Mario Zechner 2025-09-01 22:02:50 +02:00
parent 8324cd4192
commit a62231987c

View file

@ -45,6 +45,7 @@ export class AnthropicLLM implements LLM<AnthropicLLMOptions> {
if (apiKey.includes("sk-ant-oat")) {
const defaultHeaders = {
accept: "application/json",
"anthropic-dangerous-direct-browser-access": "true",
"anthropic-beta": "oauth-2025-04-20,fine-grained-tool-streaming-2025-05-14",
};
@ -61,7 +62,12 @@ export class AnthropicLLM implements LLM<AnthropicLLMOptions> {
});
this.isOAuthToken = true;
} else {
this.client = new Anthropic({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true });
const defaultHeaders = {
accept: "application/json",
"anthropic-dangerous-direct-browser-access": "true",
"anthropic-beta": "fine-grained-tool-streaming-2025-05-14",
};
this.client = new Anthropic({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true, defaultHeaders });
this.isOAuthToken = false;
}
this.modelInfo = model;