11/**
2- * Copyright 2022 Google LLC
2+ * Copyright 2025 Google LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1414 * limitations under the License.
1515 */
1616
17+ // [START complete-example]
1718// [START imports]
1819// Dependencies for callable functions.
1920const { onCallGenkit} = require ( "firebase-functions/v2/https" ) ;
21+ // [START import-params]
2022const { defineSecret} = require ( "firebase-functions/params" ) ;
23+ // [END import-params]
2124
25+ // [START import-genkit]
2226// Dependencies for Genkit
2327const { gemini15Flash, googleAI} = require ( "@genkit-ai/googleai" ) ;
2428const { genkit, z} = require ( "genkit" ) ;
29+ // [END import-genkit]
2530// [END imports]
2631
32+ // [START define-secret]
2733// Store the Gemini API key in Cloud Secret Manager
2834const apiKey = defineSecret ( "GOOGLE_GENAI_API_KEY" ) ;
35+ // [END define-secret]
2936
37+ // [START flow]
3038const ai = genkit ( {
3139 plugins : [ googleAI ( ) ] ,
3240 model : gemini15Flash ,
@@ -52,13 +60,21 @@ const jokeTeller = ai.defineFlow({
5260 return ( await aiResponse ) . text ;
5361} ,
5462) ;
63+ // [END flow]
5564
65+ // [START trigger]
5666exports . tellJoke = onCallGenkit ( {
67+ // [START bind-secrets]
5768 // bind the Gemini API key secret parameter to the function
5869 secrets : [ apiKey ] ,
70+ // [END bind-secrets]
71+ // [START auth-policy]
72+ // protect your endpoint with authPolicy
73+ authPolicy : ( auth ) => ! ! auth && auth . token . email_verified ,
74+ // [END auth-policy]
5975} ,
6076// pass in the genkit flow
6177jokeTeller ,
6278) ;
63-
64-
79+ // [END trigger]
80+ // [END complete-example]
0 commit comments