From 7829270c3fd6f044660bc7ba17cf839dec50e696 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Wed, 21 Feb 2024 01:52:54 +0000 Subject: [PATCH] feat: update via SDK Studio --- src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/index.ts b/src/index.ts index 4def5b5..6f4dcd3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -67,6 +67,12 @@ export interface ClientOptions { * param to `undefined` in request options. */ defaultQuery?: Core.DefaultQuery; + + /** + * By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers. + * Only set this option to `true` if you understand the risks and have appropriate mitigations in place. + */ + dangerouslyAllowBrowser?: boolean; } /** API Client for interfacing with the Groq API. */ @@ -86,6 +92,7 @@ export class Groq extends Core.APIClient { * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. + * @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. */ constructor({ baseURL = Core.readEnv('GROQ_BASE_URL'), @@ -104,6 +111,12 @@ export class Groq extends Core.APIClient { baseURL: baseURL || `https://api.groq.com`, }; + if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) { + throw new Errors.GroqError( + '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 })', + ); + } + super({ baseURL: options.baseURL!, timeout: options.timeout ?? 60000 /* 1 minute */,