Class OnCallGenkit
java.lang.Object
com.google.genkit.plugins.firebase.functions.OnCallGenkit
- All Implemented Interfaces:
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);
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for authorization policies. -
Method Summary
Modifier and TypeMethodDescriptionconsumeAppCheckToken(boolean consume) Enables App Check token consumption for extra security.enforceAppCheck(boolean enforce) Enables App Check enforcement.static OnCallGenkitCreates an OnCallGenkit handler from a flow action.static OnCallGenkitCreates an OnCallGenkit handler from a flow name.static OnCallGenkit.AuthPolicyPredefined authorization policy that requires a specific claim.voidservice(com.google.cloud.functions.HttpRequest request, com.google.cloud.functions.HttpResponse response) static OnCallGenkit.AuthPolicysignedIn()Predefined authorization policy that requires the user to be signed in.withAuthPolicy(OnCallGenkit.AuthPolicy authPolicy) Sets the authorization policy for this function.Sets the CORS policy.
-
Method Details
-
fromFlow
Creates an OnCallGenkit handler from a flow name.- Parameters:
genkit- the Genkit instanceflowName- the name of the flow to expose- Returns:
- a new OnCallGenkit handler
-
fromFlow
Creates an OnCallGenkit handler from a flow action.- Parameters:
genkit- the Genkit instanceflow- the flow action to expose- Returns:
- a new OnCallGenkit handler
-
withAuthPolicy
Sets the authorization policy for this function.- Parameters:
authPolicy- the authorization policy- Returns:
- this handler for chaining
-
enforceAppCheck
Enables App Check enforcement.- Parameters:
enforce- true to enforce App Check- Returns:
- this handler for chaining
-
consumeAppCheckToken
Enables App Check token consumption for extra security.- Parameters:
consume- true to consume App Check tokens- Returns:
- this handler for chaining
-
withCors
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:
servicein interfacecom.google.cloud.functions.HttpFunction- Throws:
Exception
-
signedIn
Predefined authorization policy that requires the user to be signed in.- Returns:
- an auth policy requiring sign-in
-
hasClaim
Predefined authorization policy that requires a specific claim.- Parameters:
claim- the required claim name- Returns:
- an auth policy requiring the claim
-