You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-3Lines changed: 12 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -418,9 +418,18 @@ The following runtimes are supported:
418
418
- Vercel Edge Runtime.
419
419
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
420
420
- Nitro v2.6 or greater.
421
-
422
-
> [!WARNING]
423
-
> Web browser runtimes aren't supported. The SDK will throw an error if used in a browser environment.
421
+
- Web browsers: disabled by default to avoid exposing your secret API credentials. Enable browser support by explicitly setting `dangerouslyAllowBrowser` to true'.
422
+
<details>
423
+
<summary>More explanation</summary>
424
+
### Why is this dangerous?
425
+
Enabling the `dangerouslyAllowBrowser` option can be dangerous because it exposes your secret API credentials in the client-side code. Web browsers are inherently less secure than server environments,
426
+
any user with access to the browser can potentially inspect, extract, and misuse these credentials. This could lead to unauthorized access using your credentials and potentially compromise sensitive data or functionality.
427
+
### When might this not be dangerous?
428
+
In certain scenarios where enabling browser support might not pose significant risks:
429
+
- Internal Tools: If the application is used solely within a controlled internal environment where the users are trusted, the risk of credential exposure can be mitigated.
430
+
- Public APIs with Limited Scope: If your API has very limited scope and the exposed credentials do not grant access to sensitive data or critical operations, the potential impact of exposure is reduced.
431
+
- Development or debugging purpose: Enabling this feature temporarily might be acceptable, provided the credentials are short-lived, aren't also used in production environments, or are frequently rotated.
432
+
</details>
424
433
425
434
Note that React Native is not supported at this time.
* By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
78
+
* Only set this option to `true` if you understand the risks and have appropriate mitigations in place.
79
+
*/
80
+
dangerouslyAllowBrowser?: boolean;
75
81
}
76
82
77
83
/**
@@ -95,6 +101,7 @@ export class Anthropic extends Core.APIClient {
95
101
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
96
102
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
97
103
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
104
+
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
98
105
*/
99
106
constructor({
100
107
baseURL =Core.readEnv('ANTHROPIC_BASE_URL'),
@@ -109,9 +116,9 @@ export class Anthropic extends Core.APIClient {
"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.",
121
+
"It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n\nTODO: link!\n",
115
122
);
116
123
}
117
124
@@ -140,6 +147,9 @@ export class Anthropic extends Core.APIClient {
0 commit comments