FirebaseAILogic Framework Reference

FirebaseAI

public final class FirebaseAI : Sendable

The 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) -> FirebaseAI

    Parameters

    app

    A custom FirebaseApp used for initialization; if not specified, uses the default FirebaseApp.

    backend

    The backend API for the Firebase AI SDK; if not specified, uses the default googleAI() (Gemini Developer API).

    useLimitedUseAppCheckTokens

    When 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 FirebaseAI instance, configured with the custom FirebaseApp.

  • 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: [Tool]? = nil,
                                toolConfig: ToolConfig? = nil,
                                systemInstruction: ModelContent? = nil,
                                requestOptions: RequestOptions = RequestOptions())
      -> GenerativeModel

    Parameters

    modelName

    The name of the model to use; see available model names for a list of supported model names.

    generationConfig

    The content generation parameters your model should use.

    safetySettings

    A value describing what types of harmful content your model should allow.

    tools

    A list of Tool objects that the model may use to generate the next response.

    toolConfig

    Tool configuration for any Tool specified in the request.

    systemInstruction

    Instructions that direct the model to behave a certain way; currently only text content is supported.

    requestOptions

    Configuration parameters for sending requests to the backend.

  • Creates a new GenerativeModelSession with the given model.

    Important

    Public Preview - This API is a public preview and may be subject to change.

    Declaration

    Swift

    public func generativeModelSession(model: String,
                                       instructions: String? = nil) -> GenerativeModelSession

    Parameters

    model

    The name of the model to use; see available model names for a list of supported model names.

    instructions

    System instructions that direct the model’s behavior.

  • Initializes an ImagenModel with the given parameters.

    Note

    Refer to Imagen models for guidance on choosing an appropriate model for your use case.

    Declaration

    Swift

    public func imagenModel(modelName: String, generationConfig: ImagenGenerationConfig? = nil,
                            safetySettings: ImagenSafetySettings? = nil,
                            requestOptions: RequestOptions = RequestOptions()) -> ImagenModel

    Parameters

    modelName

    The name of the Imagen 3 model to use.

    generationConfig

    Configuration options for generating images with Imagen.

    safetySettings

    Settings describing what types of potentially harmful content your model should allow.

    requestOptions

    Configuration parameters for sending requests to the backend.

  • Initializes a new TemplateGenerativeModel.

    Declaration

    Swift

    public func templateGenerativeModel() -> TemplateGenerativeModel

    Return Value

    A new TemplateGenerativeModel instance.

  • Initializes a new TemplateImagenModel.

    Declaration

    Swift

    public func templateImagenModel() -> TemplateImagenModel

    Return Value

    A new TemplateImagenModel instance.

  • [Public Preview] Initializes a LiveGenerativeModel with 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: [Tool]? = nil,
                          toolConfig: ToolConfig? = nil,
                          systemInstruction: ModelContent? = nil,
                          requestOptions: RequestOptions = RequestOptions()) -> LiveGenerativeModel

    Parameters

    modelName

    The name of the model to use.

    generationConfig

    The content generation parameters your model should use.

    tools

    A list of Tool objects that the model may use to generate the next response.

    toolConfig

    Tool configuration for any Tool specified in the request.

    systemInstruction

    Instructions that direct the model to behave a certain way; currently only text content is supported.

    requestOptions

    Configuration parameters for sending requests to the backend.

  • Structured content generated by a model.

    Public Preview: This API is a public preview and may be subject to change.

    Declaration

    Swift

    struct GeneratedContent : Sendable
    extension FirebaseAI.GeneratedContent: Equatable
    extension FirebaseAI.GeneratedContent: CustomDebugStringConvertible
  • An identifier for a specific generation.

    Public Preview: This API is a public preview and may be subject to change.

    Declaration

    Swift

    struct GenerationID : Sendable
    extension FirebaseAI.GenerationID: Equatable
    extension FirebaseAI.GenerationID: Hashable
  • Undocumented

    Declaration

    Swift

    struct GenerationSchema : Sendable
    extension FirebaseAI.GenerationSchema: CustomDebugStringConvertible
    extension FirebaseAI.GenerationSchema: Decodable
    extension FirebaseAI.GenerationSchema: Encodable