In each call to a model, you can send along a model configuration to control how
the model generates a response. Each model supports different configuration
options, like setting `maxOutputTokens` or specialized configs for thinking,
response modalities, images, speech, or voice activity detection (VAD).

For the majority of use cases when accessing a Gemini model, you
configure the model using `GenerationConfig`. However, if you're configuring a
Gemini Live API model, then you use `LiveGenerationConfig`.

This page shows how to set up the configuration for Gemini models and
provides a
[table of available parameters](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#parameters-descriptions-gemini).

[Jump to Gemini config](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#config-gemini-general)
[Jump to Gemini Live API config](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#config-gemini-live-api)

## `GenerationConfig` for Gemini models

|---|
| *Click your Gemini API provider to view provider-specific content and code on this page.* <button value="dev" default="">Gemini Developer API</button> <button value="vertex">Agent Platform Gemini API</button> |

Set a `GenerationConfig` for the majority of Gemini models, including
general-use models, image-generating (Nano Banana) models,
and text-to-speech (TTS) models.

The configuration is maintained for the lifetime of the `GenerativeModel`
instance. If you want to use a different config, create and use a new instance
with a different config.

The following example shows a very basic model configuration. For additional
options (especially for specialized models), see the table of
[available parameters](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#parameters-descriptions-gemini) later on this page.

> [!WARNING]
>
> For the latest general-use Gemini 4.x and Gemini 3.x
> models, the following parameters are now unsupported: temperature, top-K,
> top-P, frequency penalty, presence penalty, and candidate count. Remove them
> from your app's code.
>
> - **Temperature, top-K, or top-P** : All the general-use Gemini 4.x and Gemini 3.x models will ignore them.
> - **Frequency penalty, presence penalty, and candidate count** : For `gemini-4-carbon`, `gemini-4-argon`, `gemini-3.8-flash`, and `gemini-3.7-flash`, the request will *fail* with a 400 error.

### Swift

Set the values of the parameters in a
[`GenerationConfig`](https://firebase.google.com/docs/reference/swift/firebaseailogic/api/reference/Structs/GenerationConfig.md.txt)
as part of creating a `GenerativeModel` instance.

```swift

import FirebaseAILogic

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
let config = GenerationConfig(
  maxOutputTokens: 200,
  stopSequences: ["red"]
)

// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: config
)

// ...

```

### Kotlin

Set the values of the parameters in a
[`GenerationConfig`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/GenerationConfig.md.txt)
as part of creating a `GenerativeModel` instance.

```kotlin

// ...

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
val config = generationConfig {
    maxOutputTokens = 200
    stopSequences = listOf("red")
}

// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
    modelName = "GEMINI_MODEL_NAME",
    generationConfig = config
)

// ...

```

### Java

Set the values of the parameters in a
[`GenerationConfig`](https://firebase.google.com/docs/reference/android/com/google/firebase/ai/type/GenerationConfig.md.txt)
as part of creating a `GenerativeModel` instance.

```java

// ...

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");

GenerationConfig config = configBuilder.build();

// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
        FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel(
                    "GEMINI_MODEL_NAME",
                    config
                );
);

// ...

```

### Web

Set the values of the parameters in a
[`GenerationConfig`](https://firebase.google.com/docs/reference/js/ai.generationconfig.md.txt)
as part of creating a `GenerativeModel` instance.

```javascript

// ...

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
const generationConfig = {
  maxOutputTokens: 200,
  stopSequences: ["red"],
};

// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME",  generationConfig });

// ...

```

### Dart

Set the values of the parameters in a
[`GenerationConfig`](https://pub.dev/documentation/firebase_ai/latest/firebase_ai/GenerationConfig-class.html)
as part of creating a `GenerativeModel` instance.

```dart

// ...

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
final generationConfig = GenerationConfig(
  maxOutputTokens: 200,
  stopSequences: ["red"],
);

// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_MODEL_NAME',
  generationConfig: generationConfig,
);

// ...

```

### Unity

Set the values of the parameters in a
[`GenerationConfig`](https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/generation-config.md.txt)
as part of creating a `GenerativeModel` instance.

```c#

// ...

// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
var generationConfig = new GenerationConfig(
  maxOutputTokens: 200,
  stopSequences: new string[] { "red" }
);

// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: generationConfig
);

```
You can experiment with prompts and model configurations using [Google AI Studio](https://aistudio.google.com).

## `LiveGenerationConfig` for Gemini Live API models

|---|
| *Click your Gemini API provider to view provider-specific content and code on this page.* <button value="dev" default="">Gemini Developer API</button> <button value="vertex">Agent Platform Gemini API</button> |

Set a `LiveGenerationConfig` only when using Gemini Live API models.

The configuration is maintained for the lifetime of the `LiveModel`
instance. If you want to use a different config, create and use a new instance
with a different config.

The following example shows a very basic model configuration. For additional
options (like configuring voice activity detection (VAD)), see the table of
[available parameters](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#parameters-descriptions-gemini) later on this page.

### Swift

Set the values of parameters in the
[`liveGenerationConfig`](https://firebase.google.com/docs/reference/swift/firebaseailogic/api/reference/Structs/LiveGenerationConfig.md.txt)
during initialization of the `LiveModel` instance:

```swift

// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
let config = LiveGenerationConfig(
  maxOutputTokens: 200,
  responseModalities: [.audio],
  speech: SpeechConfig(voiceName: "Fenrir"),
)

// Specify the config as part of creating the `liveModel` instance.
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_MODEL_NAME",
  generationConfig: config
)

// ...

```

### Kotlin

Set the values of parameters in a
[`LiveGenerationConfig`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/LiveGenerationConfig.md.txt)
as part of creating a `LiveModel` instance.

```kotlin

// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
val config = liveGenerationConfig {
    maxOutputTokens = 200
    responseModality = ResponseModality.AUDIO
    speechConfig = SpeechConfig(voice = Voice("FENRIR"))
}

// Specify the config as part of creating the `LiveModel` instance.
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
    modelName = "GEMINI_LIVE_MODEL_NAME",
    generationConfig = config
)

// ...

```

### Java

Set the values of parameters in a
[`LiveGenerationConfig`](https://firebase.google.com/docs/reference/android/com/google/firebase/ai/type/LiveGenerationConfig.md.txt)
as part of creating a `LiveModel` instance.

```java

// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
LiveGenerationConfig.Builder configBuilder = new LiveGenerationConfig.Builder();
configBuilder.setMaxOutputTokens(200);
configBuilder.setResponseModality(ResponseModality.AUDIO);

configBuilder.setSpeechConfig(new SpeechConfig(new Voice("FENRIR")));

LiveGenerationConfig config = configBuilder.build();

// Specify the config as part of creating the `LiveModel` instance.
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
          "GEMINI_LIVE_MODEL_NAME",
          config
);

// ...

```

### Web

Set the values of parameters in the
[`LiveGenerationConfig`](https://firebase.google.com/docs/reference/js/ai.livegenerationconfig.md.txt)
during initialization of the `LiveGenerativeModel` instance:

```javascript

// ...

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
const liveGenerationConfig = {
  maxOutputTokens: 200,
  responseModalities: [ResponseModality.AUDIO],
  speechConfig: {
    voiceConfig: {
      prebuiltVoiceConfig: { voiceName: "Fenrir" },
    },
  },
};

// Specify the config as part of creating the `LiveGenerativeModel` instance.
const liveModel = getLiveGenerativeModel(ai, {
  model: "GEMINI_LIVE_MODEL_NAME",
  liveGenerationConfig,
});

// ...

```

### Dart

Set the values of parameters in a
[`LiveGenerationConfig`](https://pub.dev/documentation/firebase_ai/latest/firebase_ai/LiveGenerationConfig-class.html)
as part of creating a `LiveGenerativeModel` instance.

```dart

// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
final config = LiveGenerationConfig(
  maxOutputTokens: 200,
  responseModalities: [ResponseModalities.audio],
  speechConfig: SpeechConfig(voiceName: 'Fenrir'),
);

// Specify the config as part of creating the `liveGenerativeModel` instance.
final liveModel = FirebaseAI.googleAI().liveGenerativeModel(
  model: 'GEMINI_LIVE_MODEL_NAME',
  liveGenerationConfig: config,
);

// ...

```

### Unity

Set the values of parameters in a
[`LiveGenerationConfig`](https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/live-generation-config.md.txt)
as part of creating a `LiveModel` instance.

```c#

// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here).
var config = new LiveGenerationConfig(
  maxOutputTokens: 200,
  responseModalities: new[] { ResponseModality.Audio },
  speechConfig: SpeechConfig.UsePrebuiltVoice("Fenrir")
);

// Specify the config as part of creating the `LiveModel` instance.
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
  modelName: "GEMINI_LIVE_MODEL_NAME",
  liveGenerationConfig: config
);

// ...

```
You can experiment with prompts and model configurations using [Google AI Studio](https://aistudio.google.com).

<br />

*** ** * ** ***

## Available model parameters

The following table is a high-level overview of the available parameters for
model configuration. Some parameters are only applicable for certain models.

> [!WARNING]
>
> For the latest general-use Gemini 4.x and Gemini 3.x
> models, the following parameters are now unsupported: temperature, top-K,
> top-P, frequency penalty, presence penalty, and candidate count. Remove them
> from your app's code.
>
> - **Temperature, top-K, or top-P** : All the general-use Gemini 4.x and Gemini 3.x models will ignore them.
> - **Frequency penalty, presence penalty, and candidate count** : For `gemini-4-carbon`, `gemini-4-argon`, `gemini-3.8-flash`, and `gemini-3.7-flash`, the request will *fail* with a 400 error.

| Parameter | Description | Limitations | Default value |
|---|---|---|---|
| Max output tokens `maxOutputTokens` | Specifies the maximum number of tokens that can be generated in the response. For `gemini-4-carbon` and `gemini-4-argon`, the default and maximum output token limits are `32,768` tokens for non-streaming requests and `65,536` tokens for streaming requests. Note that Firebase AI Logic does *not yet* support long decode, but that feature is coming soon! | --- | --- |
| Stop sequences `stopSequences` | Specifies a list of strings that tells the model to stop generating content if one of the strings is encountered in the response. | Only applicable when using a `GenerativeModel` configuration. Not applicable for Nano Banana or TTS models. | --- |
| **Specialized configurations** ||||
| Thinking [`thinkingConfig`](https://firebase.google.com/docs/ai-logic/thinking.md.txt) | Controls the "thinking process" for the models when they're generating a response. - Control the amount of thinking that the model can do using a *thinking level*. - Control whether to include *thought summaries*. | Supported values: See the [thinking documentation](https://firebase.google.com/docs/ai-logic/thinking.md.txt#supported-thinking-level-values) Not applicable for TTS models. Firebase AI Logic does *not yet* support setting a `thinkingConfig` for Live API models. | [Depends on the model](https://firebase.google.com/docs/ai-logic/thinking.md.txt#supported-thinking-level-values) |
| Response modalities `responseModalities` | Specifies the type of output (like text, audio, or images). | Only applicable (and *required* ) when using Nano Banana, TTS, and Live API models. | --- |
| Image characteristics [`imageConfig`](https://firebase.google.com/docs/ai-logic/generate-images-gemini.md.txt#configure-image-generation) | Specifies the aspect ratio and resolution of generated images. | Supported values: See [Configure image generation](https://firebase.google.com/docs/ai-logic/generate-images-gemini.md.txt#configure-image-generation) Only applicable when using Nano Banana models. | 1:1 aspect ratio (square) 1024x1024 resolution |
| Speech (voice) `speechConfig` | Specifies the voice used for the audio output. | Only applicable when using TTS models and Live API models. Required for TTS models. | `Puck` |
| Voice activity detection (VAD) [`realtimeInputConfig`](https://firebase.google.com/docs/ai-logic/live-api/configuration.md.txt#vad) | Configures voice activity detection (VAD), interruption handling, and turn context coverage, or disables automatic VAD. | Supported values: See [Configure VAD](https://firebase.google.com/docs/ai-logic/live-api/configuration.md.txt#vad-configuration-settings) Only applicable when using Live API models. | VAD enabled See [default values](https://firebase.google.com/docs/ai-logic/live-api/configuration.md.txt#vad-configuration-settings) for individual settings. |

> [!NOTE]
> **Note** : The following configurations are also supported in the `GenerationConfig`:
>
> - [Generating structured output (like JSON)](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt) is controlled by using the `responseMimeType` and `responseSchema` parameters.  
>   These parameters are only supported for general-use text models (*not* for Nano Banana, TTS, or Live API models).
>
>
> Note that Firebase AI Logic does *not* support the parameter
> `audioTimestamp`.

<br />

#### Temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count are unsupported

<br />

> [!WARNING]
>
> For the latest general-use Gemini 4.x and Gemini 3.x
> models, the following parameters are now unsupported: temperature, top-K,
> top-P, frequency penalty, presence penalty, and candidate count. Remove them
> from your app's code.
>
> - **Temperature, top-K, or top-P** : All the general-use Gemini 4.x and Gemini 3.x models will ignore them.
> - **Frequency penalty, presence penalty, and candidate count** : For `gemini-4-carbon`, `gemini-4-argon`, `gemini-3.8-flash`, and `gemini-3.7-flash`, the request will *fail* with a 400 error.

| Parameter | Description | Limitations | Default value |
|---|---|---|---|
| Candidate count `candidateCount` | Specifies the number of response variations to return. For each request, you're charged for the output tokens of all candidates, but you're only charged once for the input tokens. > [!WARNING] > Setting `candidateCount` is unsupported. | Supported values: `1` - `8` (inclusive) Only applicable when using `generateContent`. Not applicable when using `generateContentStream`, Nano Banana, TTS, or Live API models. | `1` |
| Frequency penalty `frequencyPenalty` | Controls the probability of including tokens that repeatedly appear in the generated response. Positive values penalize tokens that repeatedly appear in the generated content, decreasing the probability of repeating content. > [!WARNING] > Setting `frequencyPenalty` is unsupported. | Not applicable for Nano Banana or TTS models. | --- |
| Presence penalty `presencePenalty` | Controls the probability of including tokens that already appear in the generated response. Positive values penalize tokens that already appear in the generated content, increasing the probability of generating more diverse content. > [!WARNING] > Setting `presencePenalty` is unsupported. | Not applicable for Nano Banana or TTS models. | --- |
| Temperature `temperature` | Controls the degree of randomness in the response. Lower temperatures result in more deterministic responses, and higher temperatures result in more diverse or creative responses. > [!WARNING] > Setting `temperature` is unsupported. | --- | Depends on the model |
| Top-K `topK` | Limits the number of highest probability words used in the generated content. A top-K value of `1` means the next selected token should be *the most probable* among all tokens in the model's vocabulary, while a top-K value of `n` means that the next token should be selected from among *the *n* most probable* tokens (all based on the temperature that's set). > [!WARNING] > Setting `topK` is unsupported. | --- | Depends on the model |
| Top-P `topP` | Controls diversity of generated content. Tokens are selected from the most probable (see top-K above) to least probable until the sum of their probabilities equals the top-P value. > [!WARNING] > Setting `topP` is unsupported. | --- | Depends on the model |

<br />

<br />

<br />

*** ** * ** ***

## Other options to control content generation

- Learn more about [prompt design](https://firebase.google.com/docs/ai-logic/prompt-design.md.txt) so that you can influence the model to generate output specific to your needs.
- Use [safety settings](https://firebase.google.com/docs/ai-logic/safety-settings.md.txt) to adjust the likelihood of getting responses that may be considered harmful, including hate speech and sexually explicit content.
- Set [system instructions](https://firebase.google.com/docs/ai-logic/system-instructions.md.txt) to steer the behavior of the model. This feature is like a preamble that you add before the model gets exposed to any further instructions from the end user.
- Pass a [*response schema*](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt) along with the prompt to specify a specific output schema. This feature is most commonly used when [generating JSON output](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt#generate-json-basic), but it can also be used for [classification tasks](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt#generate-enum-basic) (like when you want the model to use specific labels or tags).