ai namespace

Functions

Function Description
afterGenerateContent(callback) Handles an event triggered after content is generated by an AI model.
afterGenerateContent(options, callback) Handles an event triggered after content is generated by an AI model.
beforeGenerateContent(callback) Handles an event triggered before content is generated by an AI model.
beforeGenerateContent(options, callback) Handles an event triggered before content is generated by an AI model.

Classes

Class Description
HttpsError An explicit error that can be thrown from a handler to send an error to the client that called the function.

Interfaces

Interface Description
AfterGenerateContentData Data payload for afterGenerateContent events.
AIBlockingEvent Event context and metadata delivered to AI blocking handlers.
BeforeGenerateContentData Data payload for beforeGenerateContent events.
GeminiV1BetaGenerateContentRequest Request sent to generateContent endpoint.
GeminiV1BetaGenerateContentResponse Individual response from generateContent.
PromptTemplateInfo Metadata about the server prompt template used, if applicable.
VertexV1Beta1GenerateContentRequest Params used to call the generateContent method.
VertexV1Beta1GenerateContentResponse Response from the model supporting multiple candidates.
WebhookOptions Options for configuring AI webhook triggers.

Variables

Variable Description
afterGenerateEventType Event type for afterGenerate triggers.
beforeGenerateEventType Event type for beforeGenerate triggers.
geminiV1Beta Identifier for the Gemini Developer API (geminiV1Beta).
rpcCodeMap Mapping from FunctionsErrorCode strings to numeric RPC status codes.
vertexV1Beta1 Identifier for the Agent Platform Gemini API (formerly Vertex AI) (vertexV1Beta1).

Type Aliases

Type Alias Description
AIRequest Generic type resolving to the corresponding AI request type based on the API identifier.
AIResponse Generic type resolving to the corresponding AI response type based on the API identifier.
AnyValidAIRequest Union of all valid AI request payloads across supported Gemini API providers.
AnyValidAIResponse Union of all valid AI response payloads across supported Gemini API providers.
AuthType Authentication state for the caller: "app_user", "unauthenticated", or "unknown".
BlockingFunction A function that handles AI blocking events.
SupportedAPI Supported Gemini API providers: Gemini Developer API or Agent Platform Gemini API (formerly Vertex AI).

ai.afterGenerateContent()

Handles an event triggered after content is generated by an AI model.

Signature:

export declare function afterGenerateContent(callback: (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>>): BlockingFunction;

Parameters

Parameter Type Description
callback (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>> Event handler run after content generation.

Returns:

BlockingFunction

A blocking function that can be exported and deployed.

ai.afterGenerateContent()

Handles an event triggered after content is generated by an AI model.

Signature:

export declare function afterGenerateContent(options: WebhookOptions, callback: (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>>): BlockingFunction;

Parameters

Parameter Type Description
options WebhookOptions Configuration options for the webhook.
callback (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>> Event handler run after content generation.

Returns:

BlockingFunction

A blocking function that can be exported and deployed.

ai.beforeGenerateContent()

Handles an event triggered before content is generated by an AI model.

Signature:

export declare function beforeGenerateContent(callback: (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>>): BlockingFunction;

Parameters

Parameter Type Description
callback (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>> Event handler run before content generation.

Returns:

BlockingFunction

A blocking function that can be exported and deployed.

ai.beforeGenerateContent()

Handles an event triggered before content is generated by an AI model.

Signature:

export declare function beforeGenerateContent(options: WebhookOptions, callback: (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>>): BlockingFunction;

Parameters

Parameter Type Description
options WebhookOptions Configuration options for the webhook.
callback (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>> Event handler run before content generation.

Returns:

BlockingFunction

A blocking function that can be exported and deployed.

ai.afterGenerateEventType

Event type for afterGenerate triggers.

Signature:

afterGenerateEventType = "google.firebase.ailogic.v1.afterGenerate"

ai.beforeGenerateEventType

Event type for beforeGenerate triggers.

Signature:

beforeGenerateEventType = "google.firebase.ailogic.v1.beforeGenerate"

ai.geminiV1Beta

Identifier for the Gemini Developer API (geminiV1Beta).

Signature:

geminiV1Beta = "google.ai.generativelanguage.v1beta"

ai.rpcCodeMap

Mapping from FunctionsErrorCode strings to numeric RPC status codes.

Signature:

rpcCodeMap: Record<FunctionsErrorCode, number>

ai.vertexV1Beta1

Identifier for the Agent Platform Gemini API (formerly Vertex AI) (vertexV1Beta1).

Signature:

vertexV1Beta1 = "google.cloud.aiplatform.v1beta1"

ai.AIRequest

Generic type resolving to the corresponding AI request type based on the API identifier.

Signature:

export type AIRequest<API> = string extends API ? AnyValidAIRequest : API extends typeof geminiV1Beta ? GeminiV1BetaGenerateContentRequest : API extends typeof vertexV1Beta1 ? VertexV1Beta1GenerateContentRequest : never;

ai.AIResponse

Generic type resolving to the corresponding AI response type based on the API identifier.

Signature:

export type AIResponse<API> = string extends API ? AnyValidAIResponse : API extends typeof geminiV1Beta ? GeminiV1BetaGenerateContentResponse : API extends typeof vertexV1Beta1 ? VertexV1Beta1GenerateContentResponse : never;

ai.AnyValidAIRequest

Union of all valid AI request payloads across supported Gemini API providers.

Signature:

export type AnyValidAIRequest = GeminiV1BetaGenerateContentRequest | VertexV1Beta1GenerateContentRequest;

ai.AnyValidAIResponse

Union of all valid AI response payloads across supported Gemini API providers.

Signature:

export type AnyValidAIResponse = GeminiV1BetaGenerateContentResponse | VertexV1Beta1GenerateContentResponse;

ai.AuthType

Authentication state for the caller: "app_user", "unauthenticated", or "unknown".

Signature:

export type AuthType = "app_user" | "unauthenticated" | "unknown";

ai.BlockingFunction

A function that handles AI blocking events.

Signature:

export type BlockingFunction = HttpsFunction;

ai.SupportedAPI

Supported Gemini API providers: Gemini Developer API or Agent Platform Gemini API (formerly Vertex AI).

Signature:

export type SupportedAPI = typeof geminiV1Beta | typeof vertexV1Beta1;