Class OnCallGenkit

java.lang.Object
com.google.genkit.plugins.firebase.functions.OnCallGenkit
All Implemented Interfaces:
com.google.cloud.functions.HttpFunction

public class OnCallGenkit extends Object implements com.google.cloud.functions.HttpFunction
Firebase Cloud Functions integration for Genkit flows.

This class provides a way to expose Genkit flows as Firebase Cloud Functions using the Google Cloud Functions Framework. It supports both streaming and non-streaming responses.

Example usage with Cloud Functions:


 public class MyFunction implements HttpFunction {
 	private final Genkit genkit = Genkit.builder().plugin(GoogleGenAIPlugin.create(apiKey)).build();
 
 	@Override
 	public void service(HttpRequest request, HttpResponse response) throws Exception {
 		OnCallGenkit.fromFlow(genkit, "generatePoem").withAuthPolicy(auth -> auth != null && auth.isEmailVerified())
 				.service(request, response);
 	}
 }
 
  • Method Details

    • fromFlow

      public static OnCallGenkit fromFlow(Genkit genkit, String flowName)
      Creates an OnCallGenkit handler from a flow name.
      Parameters:
      genkit - the Genkit instance
      flowName - the name of the flow to expose
      Returns:
      a new OnCallGenkit handler
    • fromFlow

      public static OnCallGenkit fromFlow(Genkit genkit, Action<?,?,?> flow)
      Creates an OnCallGenkit handler from a flow action.
      Parameters:
      genkit - the Genkit instance
      flow - the flow action to expose
      Returns:
      a new OnCallGenkit handler
    • withAuthPolicy

      public OnCallGenkit withAuthPolicy(OnCallGenkit.AuthPolicy authPolicy)
      Sets the authorization policy for this function.
      Parameters:
      authPolicy - the authorization policy
      Returns:
      this handler for chaining
    • enforceAppCheck

      public OnCallGenkit enforceAppCheck(boolean enforce)
      Enables App Check enforcement.
      Parameters:
      enforce - true to enforce App Check
      Returns:
      this handler for chaining
    • consumeAppCheckToken

      public OnCallGenkit consumeAppCheckToken(boolean consume)
      Enables App Check token consumption for extra security.
      Parameters:
      consume - true to consume App Check tokens
      Returns:
      this handler for chaining
    • withCors

      public OnCallGenkit withCors(String cors)
      Sets the CORS policy.
      Parameters:
      cors - the allowed origin(s), or null for default behavior
      Returns:
      this handler for chaining
    • service

      public void service(com.google.cloud.functions.HttpRequest request, com.google.cloud.functions.HttpResponse response) throws Exception
      Specified by:
      service in interface com.google.cloud.functions.HttpFunction
      Throws:
      Exception
    • signedIn

      public static OnCallGenkit.AuthPolicy signedIn()
      Predefined authorization policy that requires the user to be signed in.
      Returns:
      an auth policy requiring sign-in
    • hasClaim

      public static OnCallGenkit.AuthPolicy hasClaim(String claim)
      Predefined authorization policy that requires a specific claim.
      Parameters:
      claim - the required claim name
      Returns:
      an auth policy requiring the claim