Skip to content

Commit

Permalink
feat: update via SDK Studio (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Feb 21, 2024
1 parent 5bd9088 commit cbbbe5b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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'),
Expand All @@ -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 */,
Expand Down

0 comments on commit cbbbe5b

Please sign in to comment.