Skip to content

Commit cbbbe5b

Browse files
feat: update via SDK Studio (#8)
1 parent 5bd9088 commit cbbbe5b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export interface ClientOptions {
6767
* param to `undefined` in request options.
6868
*/
6969
defaultQuery?: Core.DefaultQuery;
70+
71+
/**
72+
* By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
73+
* Only set this option to `true` if you understand the risks and have appropriate mitigations in place.
74+
*/
75+
dangerouslyAllowBrowser?: boolean;
7076
}
7177

7278
/** API Client for interfacing with the Groq API. */
@@ -86,6 +92,7 @@ export class Groq extends Core.APIClient {
8692
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
8793
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
8894
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
95+
* @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.
8996
*/
9097
constructor({
9198
baseURL = Core.readEnv('GROQ_BASE_URL'),
@@ -104,6 +111,12 @@ export class Groq extends Core.APIClient {
104111
baseURL: baseURL || `https://api.groq.com`,
105112
};
106113

114+
if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) {
115+
throw new Errors.GroqError(
116+
'This 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 Groq({ dangerouslyAllowBrowser: true })',
117+
);
118+
}
119+
107120
super({
108121
baseURL: options.baseURL!,
109122
timeout: options.timeout ?? 60000 /* 1 minute */,

0 commit comments

Comments
 (0)