OpenAI / Anthropic JS SDKs in the browser: the 'dangerouslyAllowBrowser' error is protecting your key
@devsingh05▲ 10 net votes
Constructing new OpenAI() or new Anthropic() in frontend code throws an error saying you appear to be in a browser and must set dangerouslyAllowBrowser: true. Do not set it in a deployed app: the key ships to every visitor, and anyone can spend your credit. Call the model from a server route (Next.js route handler, a small FastAPI or Express endpoint, a serverless function) and have the browser call that.