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
5 changes: 5 additions & 0 deletions src/_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ export class ApiClient implements GeminiNextGenAPIClientAdapter {
patchedHttpOptions,
prependProjectLocation,
);
if (request.queryParams) {
for (const [key, value] of Object.entries(request.queryParams)) {
url.searchParams.append(key, String(value));
}
}
if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
url.searchParams.set('alt', 'sse');
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit/api_client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ describe('ApiClient', () => {
const timeoutArgs = timeoutSpy.calls.first().args;
expect(timeoutArgs[1]).toEqual(1001);
expect(fetchArgs[0]).toEqual(
'https://custom-client-base-url.googleapis.com/v1alpha/test-path?alt=sse',
'https://custom-client-base-url.googleapis.com/v1alpha/test-path?param1=value1&param2=value2&alt=sse',
);
});
it('should not override the client http options permanently', async () => {
Expand Down Expand Up @@ -2123,7 +2123,7 @@ describe('ApiClient', () => {
const timeoutArgs = timeoutSpy.calls.mostRecent().args;
expect(timeoutArgs[1]).toEqual(1002);
expect(fetchArgs[0]).toEqual(
'https://custom-request-base-url.googleapis.com/v1alpha/test-path?alt=sse',
'https://custom-request-base-url.googleapis.com/v1alpha/test-path?param1=value1&param2=value2&alt=sse',
);

await client.requestStream({
Expand All @@ -2133,7 +2133,7 @@ describe('ApiClient', () => {
});

const secondFetchArgs = fetchSpy.calls.mostRecent().args;
const secondRequestInit = fetchArgs[1] as RequestInit;
const secondRequestInit = secondFetchArgs[1] as RequestInit;
const secondHeaders = secondRequestInit.headers as Headers;
expect(secondHeaders.get('Content-Type')).toBe('application/json');
expect(secondHeaders.get('x-goog-api-key')).toBe('test-api-key');
Expand All @@ -2142,12 +2142,12 @@ describe('ApiClient', () => {
'google-genai-sdk/',
);
expect(secondHeaders.get('google-custom-header')).toBe(
'custom-header-request-value',
'custom-header-value',
);
const secondTimeoutArgs = timeoutSpy.calls.mostRecent().args;
expect(secondTimeoutArgs[1]).toEqual(1000);
expect(secondFetchArgs[0]).toEqual(
'https://custom-client-base-url.googleapis.com/v1beta1/test-path?alt=sse',
'https://custom-client-base-url.googleapis.com/v1beta1/test-path?param1=value1&param2=value2&alt=sse',
);
});
it('should set undici dispatcher on requestInit when timeout is provided for requestStream', async () => {
Expand Down