fix(ai): Fix browser compatibility for Anthropic OAuth tokens

- Check if process exists before modifying process.env
- Prevents errors in browser environments
- Maintains OAuth token functionality in Node.js
This commit is contained in:
Mario Zechner 2025-09-01 21:46:22 +02:00
parent add1b76b6c
commit cf35215686
2 changed files with 89 additions and 86 deletions

View file

@ -48,7 +48,10 @@ export class AnthropicLLM implements LLM<AnthropicLLMOptions> {
"anthropic-beta": "oauth-2025-04-20,fine-grained-tool-streaming-2025-05-14",
};
process.env.ANTHROPIC_API_KEY = undefined;
// Clear the env var if we're in Node.js to prevent SDK from using it
if (typeof process !== "undefined" && process.env) {
process.env.ANTHROPIC_API_KEY = undefined;
}
this.client = new Anthropic({ apiKey: null, authToken: apiKey, baseURL: model.baseUrl, defaultHeaders });
this.isOAuthToken = true;
} else {