From a0c9f2a5b4f24dc0729d6b4e137c3025ab4cff27 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Tue, 16 Jul 2024 13:42:12 +0000 Subject: [PATCH] chore(docs): mention lack of support for web browser runtimes --- README.md | 3 +++ src/index.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 0761e0b5..3993a508 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,9 @@ The following runtimes are supported: - Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time). - Nitro v2.6 or greater. +> [!WARNING] +> Web browser runtimes aren't supported. The SDK will throw an error if used in a browser environment. + Note that React Native is not supported at this time. If you are interested in other runtime environments, please open or upvote an issue on GitHub. diff --git a/src/index.ts b/src/index.ts index 70b7698b..af85fc10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -109,6 +109,12 @@ export class Anthropic extends Core.APIClient { baseURL: baseURL || `https://api.anthropic.com`, }; + if (Core.isRunningInBrowser()) { + throw new Errors.AnthropicError( + "It looks like you're running in a browser-like environment, which is disabled to protect your secret API credentials from attackers. If you have a strong business need for client-side use of this API, please open a GitHub issue with your use-case and security mitigations.", + ); + } + super({ baseURL: options.baseURL!, timeout: options.timeout ?? 600000 /* 10 minutes */,