FirebaseAILogic Framework Reference

Structures

The following structures are available globally.

  • The model’s response to a generate content request.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructGenerateContentResponse:Sendable
    extensionGenerateContentResponse:Decodable
  • A struct representing a possible reply to a content generation prompt. Each content generationprompt may produce multiple candidate responses.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructCandidate:Sendable
    extensionCandidate:Decodable
  • A collection of source attributions for a piece of content.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructCitationMetadata:Sendable
    extensionCitationMetadata:Decodable
  • A struct describing a source attribution.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructCitation:Sendable,Equatable
    extensionCitation:Decodable
  • A value enumerating possible reasons for a model to terminate a content generation request.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFinishReason:DecodableProtoEnum,Hashable,Sendable
  • A metadata struct containing any feedback the model had on the prompt it was provided.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructPromptFeedback:Sendable
    extensionPromptFeedback:Decodable
  • Metadata returned to the client when grounding is enabled.

    Important

    If using Grounding with Google Search, you are required to comply with the“Grounding with Google Search” usage requirements for your chosen API provider:Gemini Developer APIor Vertex AI Gemini API (seeService Termssection within the Service Specific Terms).

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructGroundingMetadata:Sendable,Equatable,Hashable
    extensionGroundingMetadata:Decodable
  • Represents a specific segment within aModelContent struct, often used to pinpoint theexact location of text or data that grounding information refers to.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructSegment:Sendable,Equatable,Hashable
    extensionSegment:Decodable
  • A struct defining model parameters to be used when sending generative AIrequests to the backend model.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructGenerationConfig:Sendable
    extensionGenerationConfig:Encodable
  • Configuration parameters for sending requests to the backend.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructRequestOptions:Sendable
    extensionRequestOptions:Equatable
  • Represents token counting info for a single modality.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructModalityTokenCount:Sendable
    extensionModalityTokenCount:Decodable
  • Content part modality.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructContentModality:DecodableProtoEnum,Hashable,Sendable
  • A type describing data in media formats interpretable by an AI model. Each generative AIrequest or response contains anArray ofModelContents, and eachModelContent valuemay comprise multiple heterogeneousParts.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructModelContent:Equatable,Sendable
    extensionModelContent:Codable
  • A type defining potentially harmful media categories and their model-assigned ratings. A valueof this type may be assigned to a category for every model-generated response, not justresponses that exceed a certain threshold.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructSafetyRating:Equatable,Hashable,Sendable
    extensionSafetyRating:Decodable
  • A type used to specify a threshold for harmful content, beyond which the model will return afallback response instead of generated content.

    Seesafety settings for Geminimodels formore details.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructSafetySetting:Sendable
    extensionSafetySetting:Encodable
  • Categories describing the potential harm a piece of content may pose.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructHarmCategory:CodableProtoEnum,Hashable,Sendable
  • Structured representation of a function declaration.

    ThisFunctionDeclaration is a representation of a block of code that can be used as aToolby the model and executed by the client.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFunctionDeclaration:Sendable
    extensionFunctionDeclaration:Encodable
  • A tool that allows the generative model to connect to Google Search to access and incorporateup-to-date information from the web into its responses.

    Important

    When using this feature, you are required to comply with the“Grounding with Google Search” usage requirements for your chosen API provider:Gemini Developer APIor Vertex AI Gemini API (seeService Termssection within the Service Specific Terms).

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructGoogleSearch:Sendable
    extensionGoogleSearch:Encodable
  • A helper tool that the model may use when generating responses.

    ATool is a piece of code that enables the system to interact with external systems to performan action, or set of actions, outside of knowledge and scope of the model.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructTool:Sendable
    extensionTool:Encodable
  • Configuration for specifying function calling behavior.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFunctionCallingConfig:Sendable
    extensionFunctionCallingConfig:Encodable
  • Tool configuration for anyTool specified in the request.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructToolConfig:Sendable
    extensionToolConfig:Encodable
  • The model’s response to a count tokens request.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructCountTokensResponse:Sendable
    extensionCountTokensResponse:Decodable
  • Represents available backend APIs for the Firebase AI SDK.

    Declaration

    Swift

    publicstructBackend
  • An aspect ratio for images generated by Imagen.

    To specify an aspect ratio for generated images, setaspectRatio inyourImagenGenerationConfig. See theClouddocumentationfor more details and examples of the supported aspect ratios.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenAspectRatio:Sendable
  • Configuration options for generating images with Imagen.

    SeeParameters for Imagenmodels tolearn about parameters available for use with Imagen models, including how to configure them.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenGenerationConfig
  • A response from a request to generate images with Imagen.

    The type placeholderT is an image type; this is currently always anImagenInlineImage.

    This type is returned from:

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenGenerationResponse<T>:SendablewhereT:Sendable
    extensionImagenGenerationResponse:DecodablewhereT:Decodable
  • An image format for images generated by Imagen.

    To specify an image format for generated images, setimageFormat inyourImagenGenerationConfig. See theClouddocumentationfor more details.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenImageFormat
  • An error that occurs when image generation fails due to all generated images being blocked.

    The images may have been blocked due to the specifiedImagenSafetyFilterLevel, theImagenPersonFilterLevel, or filtering included in the model. These filter levels may beadjusted in yourImagenSafetySettings. See theResponsible AI and usage guidelines forImagenfor more details.

    Declaration

    Swift

    publicstructImagenImagesBlockedError:Error
    extensionImagenImagesBlockedError:CustomNSError
  • An image generated by Imagen, represented as inline data.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenInlineImage:Sendable
    extensionImagenInlineImage:Equatable
    extensionImagenInlineImage:Decodable
  • A filter level controlling whether generation of images containing people or faces is allowed.

    See thepersonGenerationdocumentation for more details.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenPersonFilterLevel:ProtoEnum
  • A filter level controlling how aggressively to filter sensitive content.

    Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AIare assessed against a list of safety filters, which include ‘harmful categories’ (for example,violence,sexual,derogatory, andtoxic). This filter level controls how aggressively tofilter out potentially harmful content from responses. See thesafetySettingdocumentation and theResponsible AI and usageguidelinesfor more details.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenSafetyFilterLevel:ProtoEnum,Sendable
  • Settings for controlling the aggressiveness of filtering out sensitive content.

    See theResponsible AI and usageguidelinesfor more details.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructImagenSafetySettings
  • Configuration options for audio transcriptions when communicating with a model that supports theGemini Live API.

    While there are not currently any options, this will likely change in the future. For now, justproviding an instance of this struct will enable audio transcriptions for the correspondinginput or output fields.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructAudioTranscriptionConfig:Sendable
  • Text transcription of some audio form during a live interaction with the model.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveAudioTranscription:Sendable
  • Configuration options for live content generation.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveGenerationConfig:Sendable
  • Incremental server update generated by the model in response to clientmessages.

    Content is generated as quickly as possible, and not in realtime. Clientsmay choose to buffer and play it out in realtime.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveServerContent:Sendable
  • Server will not be able to service client soon.

    To learn more about session limits, see the docs onMaximum session duration.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveServerGoingAwayNotice:Sendable
  • Update from the server, generated from the model in response to client messages.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveServerMessage:Sendable
  • Request for the client to execute the providedfunctionCalls.

    The client should return matchingFunctionResponsePart, where thefunctionId fields correspond to individualFunctionCallParts.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)@available(watchOS,unavailable)publicstructLiveServerToolCall:Sendable
  • Notification for the client to cancel a previous function call fromLiveServerToolCall.

    The client does not need to sendFunctionResponseParts for the cancelledFunctionCallParts.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveServerToolCallCancellation:Sendable
  • The model sent a message that the SDK failed to parse.

    This may indicate that the SDK version needs updating, a model is too old for the current SDKversion, or that the model is justnot supported.

    Check theNSUnderlyingErrorKey entry inerrorUserInfofor the error that caused this.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveSessionUnsupportedMessageError:Error,Sendable,CustomNSError
  • The live session was closed, because the network connection was lost.

    Check theNSUnderlyingErrorKey entry inerrorUserInfo forthe error that caused this.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveSessionLostConnectionError:Error,Sendable,CustomNSError
  • The live session was closed, but not for a reason the SDK expected.

    Check theNSUnderlyingErrorKey entry inerrorUserInfofor the error that caused this.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveSessionUnexpectedClosureError:Error,Sendable,CustomNSError
  • The model refused our request to setup a live session.

    This can occur due to the model not supporting the requested response modalities, the projectnot having access to the model, the model being invalid, or some internal error.

    Check theNSUnderlyingErrorKey entry inerrorUserInfo for the errorthat caused this.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructLiveSessionSetupError:Error,Sendable,CustomNSError
  • Configuration for controlling the voice of the model during conversation.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,*)@available(watchOS,unavailable)publicstructSpeechConfig:Sendable
  • A text part containing a string value.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructTextPart:Part
  • A data part that is provided inline in requests.

    Data provided as an inline data part is encoded as base64 and included directly (inline) in therequest. For large files, seeFileDataPart which references content by URI instead ofincluding the data in the request.

    Important

    Only small files can be sent as inline data because of limits on total requestsizes; seeinput files and requirements for more details and size limits.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructInlineDataPart:Part
  • File data stored in Cloud Storage for Firebase, referenced by URI.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFileDataPart:Part
  • A predicted function call returned from the model.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFunctionCallPart:Part
  • Result output from a function call.

    Contains a string representing theFunctionDeclaration.name and a structured JSON objectcontaining any output from the function is used as context to the model. This should contain theresult of aFunctionCallPart made based on model prediction.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructFunctionResponsePart:Part
  • A part containing code that was executed by the model.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructExecutableCodePart:Part
  • The result of executing code.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructCodeExecutionResultPart:Part
  • Represents the different types, or modalities, of data that a model can produce as output.

    To configure the desired output modalities for model requests, set theresponseModalitiesparameter when initializing aGenerationConfig. See themultimodalresponsesdocumentation for more details.

    Important

    Support for each response modality, or combination of modalities, depends on themodel.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructResponseModality:EncodableProtoEnum,Sendable
  • Configuration for controlling the “thinking” behavior of compatible Gemini models.

    Certain models, like Gemini 2.5 Flash and Pro, utilize a thinking process before generating aresponse. This allows them to reason through complex problems and plan a more coherent andaccurate answer.

    Declaration

    Swift

    publicstructThinkingConfig:Sendable
    extensionThinkingConfig:Encodable
  • A tool that allows the model to execute code.

    This tool can be used to solve complex problems, for example, by generating and executing Pythoncode to solve a math problem.

    Declaration

    Swift

    publicstructCodeExecution:Sendable,Encodable
  • Metadata related to theurlContext() tool.

    Warning

    URL context is aPublic Preview feature, which means that it is not subject toany SLA or deprecation policy and could change in backwards-incompatible ways.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructURLContextMetadata:Sendable,Hashable
    extensionURLContextMetadata:Decodable
  • Metadata for a single URL retrieved by theurlContext() tool.

    Warning

    URL context is aPublic Preview feature, which means that it is not subject toany SLA or deprecation policy and could change in backwards-incompatible ways.

    Declaration

    Swift

    @available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructURLMetadata:Sendable,Hashable
    extensionURLMetadata:Decodable

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-28 UTC.