FirebaseAI
public final class FirebaseAI : SendableThe Firebase AI SDK provides access to Gemini models directly from your app.
-
Creates an instance of
FirebaseAI.Declaration
Swift
public static func firebaseAI(app: FirebaseApp? = nil, backend: Backend = .googleAI(), useLimitedUseAppCheckTokens: Bool = false) -> FirebaseAIParameters
appA custom
FirebaseAppused for initialization; if not specified, uses the defaultFirebaseApp.backendThe backend API for the Firebase AI SDK; if not specified, uses the default
googleAI()(Gemini Developer API).useLimitedUseAppCheckTokensWhen sending tokens to the backend, this option enables the usage of App Check's limited-use tokens instead of the standard cached tokens. Learn more about limited-use tokens, including their nuances, when to use them, and best practices for integrating them into your app.
Return Value
A
FirebaseAIinstance, configured with the customFirebaseApp. -
generativeModel(modelName:generationConfig:safetySettings:tools:toolConfig:systemInstruction:requestOptions:)
Initializes a generative model with the given parameters.
Note
Refer to Gemini models for guidance on choosing an appropriate model for your use case.
Declaration
Swift
public func generativeModel(modelName: String, generationConfig: GenerationConfig? = nil, safetySettings: [SafetySetting]? = nil, tools: [GenerativeModel.Tool]? = nil, toolConfig: ToolConfig? = nil, systemInstruction: ModelContent? = nil, requestOptions: RequestOptions = RequestOptions()) -> GenerativeModelParameters
modelNameThe name of the model to use; see available model names for a list of supported model names.
generationConfigThe content generation parameters your model should use.
safetySettingsA value describing what types of harmful content your model should allow.
toolsA list of
Toolobjects that the model may use to generate the next response.toolConfigTool configuration for any
Toolspecified in the request.systemInstructionInstructions that direct the model to behave a certain way; currently only text content is supported.
requestOptionsConfiguration parameters for sending requests to the backend.
-
[Public Preview] Initializes a new
TemplateGenerativeModel.Warning
This API is a public preview and may be subject to change.
Server prompt templates let you store prompts, schemas, tools, and configurations on the server, decoupling prompt iteration from app release cycles.
Note
If your Firebase project enforces template-only mode, all Gemini requests in the project must use server prompt templates via
templateGenerativeModel; standard requests will be rejected with an unauthorized (403) error.Declaration
Swift
public func templateGenerativeModel(tools: [TemplateTool]? = nil, toolConfig: TemplateToolConfig? = nil, requestOptions: RequestOptions = RequestOptions()) -> TemplateGenerativeModelParameters
toolsAn optional list of
TemplateTools that the model may use to generate responses. Tools must be declared in the template's frontmatter. In client code, passfunctionDeclarations(_:)to provide or override schema definitions for functions declared in the template, orgoogleMaps()to enable Grounding with Google Maps.toolConfigTool configuration for tools specified in the request (such as providing a
RetrievalConfigwith user location and language code for Grounding with Google Maps).requestOptionsConfiguration parameters for sending requests to the backend.
Return Value
A new
TemplateGenerativeModelinstance. -
[Public Preview] Initializes a
LiveGenerativeModelwith the given parameters.Note
Refer to the Firebase docs on the Live API for guidance on choosing an appropriate model for your use case.Warning
Using the Firebase AI Logic SDKs with the Gemini Live API is in Public Preview, which means that the feature is not subject to any SLA or deprecation policy and could change in backwards-incompatible ways.
Declaration
Swift
@available(watchOS, unavailable) public func liveModel(modelName: String, generationConfig: LiveGenerationConfig? = nil, tools: [GenerativeModel.Tool]? = nil, toolConfig: ToolConfig? = nil, systemInstruction: ModelContent? = nil, requestOptions: RequestOptions = RequestOptions()) -> LiveGenerativeModelParameters
modelNameThe name of the model to use.
generationConfigThe content generation parameters your model should use.
toolsA list of
Toolobjects that the model may use to generate the next response.toolConfigTool configuration for any
Toolspecified in the request.systemInstructionInstructions that direct the model to behave a certain way; currently only text content is supported.
requestOptionsConfiguration parameters for sending requests to the backend.