@@ -46,7 +46,7 @@ import {
4646 * @returns A promise that resolves to an array of Model objects.
4747 */
4848export async function listModels (
49- apiKey : string ,
49+ apiKey : string | undefined ,
5050 clientOptions ?: ClientOptions
5151) : Promise < Model [ ] > {
5252 const url = getGoogleAIUrl ( {
@@ -75,7 +75,7 @@ export async function listModels(
7575 * @throws {Error } If the API request fails or the response cannot be parsed.
7676 */
7777export async function generateContent (
78- apiKey : string ,
78+ apiKey : string | undefined ,
7979 model : string ,
8080 generateContentRequest : GenerateContentRequest ,
8181 clientOptions ?: ClientOptions
@@ -108,7 +108,7 @@ export async function generateContent(
108108 * @throws {Error } If the API request fails.
109109 */
110110export async function generateContentStream (
111- apiKey : string ,
111+ apiKey : string | undefined ,
112112 model : string ,
113113 generateContentRequest : GenerateContentRequest ,
114114 clientOptions ?: ClientOptions
@@ -140,7 +140,7 @@ export async function generateContentStream(
140140 * @throws {Error } If the API request fails or the response cannot be parsed.
141141 */
142142export async function embedContent (
143- apiKey : string ,
143+ apiKey : string | undefined ,
144144 model : string ,
145145 embedContentRequest : EmbedContentRequest ,
146146 clientOptions ?: ClientOptions
@@ -162,7 +162,7 @@ export async function embedContent(
162162}
163163
164164export async function imagenPredict (
165- apiKey : string ,
165+ apiKey : string | undefined ,
166166 model : string ,
167167 imagenPredictRequest : ImagenPredictRequest ,
168168 clientOptions ?: ClientOptions
@@ -185,7 +185,7 @@ export async function imagenPredict(
185185}
186186
187187export async function veoPredict (
188- apiKey : string ,
188+ apiKey : string | undefined ,
189189 model : string ,
190190 veoPredictRequest : VeoPredictRequest ,
191191 clientOptions ?: ClientOptions
@@ -208,7 +208,7 @@ export async function veoPredict(
208208}
209209
210210export async function veoCheckOperation (
211- apiKey : string ,
211+ apiKey : string | undefined ,
212212 operation : string ,
213213 clientOptions ?: ClientOptions
214214) : Promise < VeoOperation > {
@@ -265,7 +265,7 @@ export function getGoogleAIUrl(params: {
265265
266266function getFetchOptions ( params : {
267267 method : 'POST' | 'GET' ;
268- apiKey : string ;
268+ apiKey : string | undefined ;
269269 body ?: string ;
270270 clientOptions ?: ClientOptions ;
271271} ) {
@@ -310,7 +310,7 @@ function getAbortSignal(
310310 * @returns {HeadersInit } An object containing the headers to be included in the request.
311311 */
312312function getHeaders (
313- apiKey : string ,
313+ apiKey ? : string ,
314314 clientOptions ?: ClientOptions
315315) : HeadersInit {
316316 let customHeaders = { } ;
@@ -322,10 +322,13 @@ function getHeaders(
322322 const headers : HeadersInit = {
323323 ...customHeaders ,
324324 'Content-Type' : 'application/json' ,
325- 'x-goog-api-key' : apiKey ,
326325 'x-goog-api-client' : getGenkitClientHeader ( ) ,
327326 } ;
328327
328+ if ( apiKey ) {
329+ headers [ 'x-goog-api-key' ] = apiKey ;
330+ }
331+
329332 return headers ;
330333}
331334
0 commit comments