# Available capabilities when accessing the Gemini API through Apple's Foundation Models framework

This guide shows you how to send various types of requests to the Gemini API through Apple's Foundation Models framework using the Firebase AI Logic SDK for Apple platforms.

This page shows examples for how to send the following types of requests:

- [Generate text from text-only input](/content/docs/ai-logic/apple-foundation-models-framework/capabilities?api=dev#text-from-text-only-input/index.html)
- [Generate text during a multi-turn session (chat)](/content/docs/ai-logic/apple-foundation-models-framework/capabilities?api=dev#text-during-multi-turn-session/index.html)
- [Generate text from multimodal input (like images)](/content/docs/ai-logic/apple-foundation-models-framework/capabilities?api=dev#text-from-multimodal-input/index.html)
- [Generate images from text-only input](/content/docs/ai-logic/apple-foundation-models-framework/capabilities?api=dev#generate-images/index.html)
- [Generate structured JSON output](/content/docs/ai-logic/apple-foundation-models-framework/capabilities?api=dev#structured-json-output/index.html)

---

## Generate text

Gemini models support the following capabilities for generating text:

### Models that support this capability

- `gemini-3.1-pro-preview`
- `gemini-3.8-flash` (and the older `gemini-3.7-flash`, `gemini-3.6-flash`, and `gemini-3.5-flash`)
- `gemini-3.5-flash-lite` (and the older `gemini-3.1-flash-lite`)

### Generate text from text-only input

```swift
import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Initialize a `geminiLanguageModel` with a Gemini model that supports your use case.
let model = ai.geminiLanguageModel(name: "gemini-3.8-flash")

// Provide a prompt that contains text.
let prompt = "Write a story about a magic backpack."

// Create a session by injecting the model into Apple's `LanguageModelSession`.
let session = LanguageModelSession(model: model)

// Generate a text response to the prompt.
let response = try await session.respond(to: prompt)
print(response.content)
```

### Stream the response

You can achieve faster interactions by not waiting for the entire result from the model generation, and instead use streaming to handle partial results. To stream the response, use `streamResponse(to:)` instead of `respond(to:)`.

```swift
// imports
// initialization of Gemini API backend service and a `geminiLanguageModel`

// Provide a prompt that contains text.
let prompt = "Write a story about a magic backpack."

// Create a session by injecting the model into Apple's `LanguageModelSession`.
let session = LanguageModelSession(model: model)

// Generate a text response to the prompt.
let stream = session.streamResponse(to: prompt)
var response = ""
for try await snapshot in stream {
  response = snapshot.content
}
```

### Generate text during a multi-turn session (chat)

```swift
import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Create a session by injecting the model into Apple's `LanguageModelSession`.
let session = LanguageModelSession(model: model)

// Generate a text response to an initial prompt.
let response = try await session.respond(to: "Hello! I'd like to learn more about Albert Einstein.")
print(response.content)

// Continue using the existing session.
let response2 = try await session.respond(to: "When was he born?")
print(response2.content)
```

### Generate text from multimodal input (like images)

```swift
import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Create a session by injecting the model into Apple's `LanguageModelSession`.
let session = LanguageModelSession(model: model)

let cgImage: CGImage = // ... fetch CGImage from your datasource.
let response = try await session.respond {
  "What are the dominant colors of this image, in order?"
  Attachment(cgImage)
}
print(response.content)
```

### Stream the response

```swift
// imports
// initialization of Gemini API backend service and a `geminiLanguageModel`

let session = LanguageModelSession(model: model)

let cgImage: CGImage = // ... fetch CGImage from your datasource.
let stream = session.streamResponse {
  "What are the dominant colors of this image, in order?"
  Attachment(cgImage)
}

var response = ""
for try await snapshot in stream {
  response = snapshot.content
}
print(response)
```

## Generate images (using "Nano Banana" models)

### Models that support this capability

- `gemini-3-pro-image` (aka "Nano Banana Pro")
- `gemini-3.1-flash-image` (aka "Nano Banana 2")

```swift
import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Initialize a `geminiLanguageModel` with a Gemini model that supports image output.
let model = ai.geminiLanguageModel(name: "gemini-3.1-flash-image" options: GeminiGenerationOptions(responseModalities: .image))

let session = LanguageModelSession(model: model)
let response = try await session.respond(
          to: "Generate an image of the Eiffel tower with fireworks in the background."
        )

var generatedImage: CIImage?
for entry in response.transcriptEntries {
  if case let .response(response) = entry {
    for segment in response.segments {
      if case let .attachment(attachment) = segment,
          case let .image(image) = attachment.content {
        generatedImage = image.ciImage
      }
    }
  }
}
```

## Generate structured JSON output

### Models that support this capability

- `gemini-3.1-pro-preview`
- `gemini-3.5-flash`
- `gemini-3.1-flash-lite`
- `gemini-3-pro-image`

```swift
import FoundationModels
import FirebaseCore
import FirebaseAILogic

@Generable(description: "Basic profile information about a cat")
struct CatProfile {
  var name: String
  @Guide(description: "The age of the cat", .range(0 ... 20))
  var age: Int
  @Guide(description: "A one sentence profile about the cat's personality")
  var profile: String
}

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Initialize a `geminiLanguageModel` with a Gemini model that supports your use case.
let model = ai.geminiLanguageModel(name: "GEMINI_MODEL_NAME")
let session = LanguageModelSession(model: model)

let response = try await session.respond(
  to: "Generate a cute rescue cat profile with an Elvish theme",
  generating: CatProfile.self
)
let cat = response.content
```

Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies).
