diff --git a/README.md b/README.md index f9b5072a..807b01eb 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,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 0976766d..2df0939a 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 */,