Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api-report/genai-node.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@ export class GoogleGenAI {
export interface GoogleGenAIOptions {
apiKey?: string;
apiVersion?: string;
fetchImplementation?: typeof fetch;
googleAuthOptions?: GoogleAuthOptions;
httpOptions?: HttpOptions;
location?: string;
Expand Down
1 change: 1 addition & 0 deletions api-report/genai-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@ export class GoogleGenAI {
export interface GoogleGenAIOptions {
apiKey?: string;
apiVersion?: string;
fetchImplementation?: typeof fetch;
googleAuthOptions?: GoogleAuthOptions;
httpOptions?: HttpOptions;
location?: string;
Expand Down
1 change: 1 addition & 0 deletions api-report/genai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@ export class GoogleGenAI {
export interface GoogleGenAIOptions {
apiKey?: string;
apiVersion?: string;
fetchImplementation?: typeof fetch;
googleAuthOptions?: GoogleAuthOptions;
httpOptions?: HttpOptions;
location?: string;
Expand Down
12 changes: 11 additions & 1 deletion src/_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export interface ApiClientInitOptions {
* This can be used to e.g specify the runtime and its version.
*/
userAgentExtra?: string;
/**
* Optional. A custom fetch implementation to use for all HTTP requests made by the SDK.
*
* @remarks
* If unset, the SDK will use the default `fetch` implementation available in the runtime environment.
*/
fetchImplementation?: typeof fetch;
}

/**
Expand Down Expand Up @@ -630,7 +637,10 @@ export class ApiClient implements GeminiNextGenAPIClientAdapter {
url: string,
requestInit: RequestInit,
): Promise<Response> {
return fetch(url, requestInit).catch((e) => {
return (this.clientOptions.fetchImplementation || fetch)(
url,
requestInit,
).catch((e) => {
throw new Error(`exception ${e} sending request`);
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export interface GoogleGenAIOptions {
* Optional. A set of customizable configuration for HTTP requests.
*/
httpOptions?: HttpOptions;
/**
* Optional. A custom fetch implementation to use for all HTTP requests made by the SDK.
*
* @remarks
* If unset, the SDK will use the default `fetch` implementation available in the runtime environment.
*/
fetchImplementation?: typeof fetch;
}

/**
Expand Down Expand Up @@ -197,6 +204,7 @@ export class GoogleGenAI {
userAgentExtra: LANGUAGE_LABEL_PREFIX + 'cross',
uploader: new CrossUploader(),
downloader: new CrossDownloader(),
fetchImplementation: options.fetchImplementation,
});
this.models = new Models(this.apiClient);
this.live = new Live(this.apiClient, auth, new CrossWebSocketFactory());
Expand Down
1 change: 1 addition & 0 deletions src/node/node_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class GoogleGenAI {
userAgentExtra: LANGUAGE_LABEL_PREFIX + process.version,
uploader: new NodeUploader(),
downloader: new NodeDownloader(),
fetchImplementation: options.fetchImplementation,
});
this.models = new Models(this.apiClient);
this.live = new Live(this.apiClient, auth, new NodeWebSocketFactory());
Expand Down
1 change: 1 addition & 0 deletions src/web/web_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class GoogleGenAI {
userAgentExtra: LANGUAGE_LABEL_PREFIX + 'web',
uploader: new BrowserUploader(),
downloader: new BrowserDownloader(),
fetchImplementation: options.fetchImplementation,
});
this.models = new Models(this.apiClient);
this.live = new Live(this.apiClient, auth, new BrowserWebSocketFactory());
Expand Down