In each call to a model, you can send along a model configuration to control how the model generates a response. Each model offers different configuration options.
You can experiment with prompts and model configurations and rapidly iterate using Vertex AI Studio.
Gemini config options Jump to Imagen config options Jump to
Configure Gemini models
This section shows you how to set up a configuration for use with Gemini models and provides a description of each parameter.
Set up a model configuration (Gemini)
Config for general use cases
The configuration is maintained for the lifetime of the instance. If you want to
use a different config, create a new GenerativeModel
instance with that
config.
Swift
Set the values of the parameters in a
GenerationConfig
as part of creating a GenerativeModel
instance.
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
let config = GenerationConfig(
temperature: 0.9,
topP: 0.1,
topK: 16,
maxOutputTokens: 200,
stopSequences: ["red"]
)
// Specify the config as part of creating the `GenerativeModel` instance
let model = vertex.generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
Set the values of the parameters in a
GenerationConfig
as part of creating a GenerativeModel
instance.
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
val config = generationConfig {
maxOutputTokens = 200
stopSequences = listOf("red")
temperature = 0.9f
topK = 16
topP = 0.1f
}
// Specify the config as part of creating the `GenerativeModel` instance
val generativeModel = Firebase.vertexAI.generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig = config
)
// ...
Java
Set the values of the parameters in a
GenerationConfig
as part of creating a GenerativeModel
instance.
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;
GenerationConfig generationConfig = configBuilder.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModel gm = FirebaseVertexAI.getInstance().generativeModel(
"GEMINI_MODEL_NAME",
generationConfig
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// ...
Web
Set the values of the parameters in a
GenerationConfig
as part of creating a GenerativeModel
instance.
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
const generationConfig = {
max_output_tokens: 200,
stop_sequences: ["red"],
temperature: 0.9,
top_p: 0.1,
top_k: 16,
};
// Specify the config as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(vertex, { model: "GEMINI_MODEL_NAME", generationConfig });
// ...
Dart
Set the values of the parameters in a
GenerationConfig
as part of creating a GenerativeModel
instance.
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
final generationConfig = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"],
temperature: 0.9,
topP: 0.1,
topK: 16,
);
final model = FirebaseVertexAI.instance.generativeModel(
model: 'GEMINI_MODEL_NAME',
// Specify the config as part of creating the `GenerativeModel` instance
config: generationConfig,
);
// ...
You can find a description of each parameter in the next section of this page.
Config for the Gemini Live API
The configuration is maintained for the lifetime of the instance. If you want to
use a different config, create a new LiveModel
instance with that
config.
Swift
The Live API is not yet supported for Apple platform apps, but check back soon!
Kotlin
Set the values of parameters in a
LiveGenerationConfig
as part of creating a LiveModel
instance.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here)
val config = liveGenerationConfig {
maxOutputTokens = 200
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voices.FENRIR)
temperature = 0.9f
topK = 16
topP = 0.1f
}
// Specify the config as part of creating the `LiveModel` instance
val generativeModel = Firebase.vertexAI.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
generationConfig = config
)
// ...
Java
Set the values of parameters in a
LiveGenerationConfig
as part of creating a LiveModel
instance.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here)
LiveGenerationConfig.Builder configBuilder = new LiveGenerationConfig.Builder();
configBuilder.setMaxOutputTokens(200);
configBuilder.setResponseModalities(ResponseModality.AUDIO);
configBuilder.setSpeechConfig(new SpeechConfig(Voices.FENRIR));
configBuilder.setTemperature(0.9f);
configBuilder.setTopK(16);
configBuilder.setTopP(0.1f);
LiveGenerationConfig generationConfig = configBuilder.build();
// Specify the config as part of creating the `LiveModel` instance
LiveGenerativeModel gm = FirebaseVertexAI.getInstance().liveModel(
"gemini-2.0-flash-live-preview-04-09",
generationConfig
);
LiveModelFutures model = LiveModelFutures.from(gm);
// ...
Web
The Live API is not yet supported for Web apps, but check back soon!
Dart
Set the values of parameters in a
LiveGenerationConfig
as part of creating a LiveModel
instance.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here)
final generationConfig = LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: [ResponseModality.audio],
speechConfig: SpeechConfig(voice: Voice.fenrir),
temperature: 0.9,
topP: 0.1,
topK: 16,
);
// Specify the config as part of creating the `LiveModel` instance
final model = FirebaseVertexAI.instance.LiveModel(
model: 'gemini-2.0-flash-live-preview-04-09',
config: generationConfig,
);
// ...
You can find a description of each parameter in the next section of this page.
Description of parameters (Gemini)
Here is a high-level overview of the available parameters, as applicable. You can find a comprehensive list of parameters and their values in the Google Cloud documentation.
Parameter | Description | Default value |
---|---|---|
Audio timestamp
audioTimestamp
|
A boolean that enables timestamp understanding for audio-only input files. Only applicable when using |
false |
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. |
--- |
Max output tokens
maxOutputTokens
|
Specifies the maximum number of tokens that can be generated in the response. | --- |
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. |
--- |
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
|
--- |
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. |
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).
|
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. |
Depends on the model |
Response modality
responseModality
|
Specifies the type of streamed output when using the Live API, for example text or audio. Only applicable when using the Live API and a
|
--- |
Speech (voice)
speechConfig
|
Specifies the voice used for the streamed audio output when using the Live API. Only applicable when using the Live API and a
|
Puck |
Configure Imagen models
This section shows you how to set up a configuration for use with Imagen models and provides a description of each parameter.
Set up a model configuration (Imagen)
The configuration is maintained for the lifetime of the instance. If you want to
use a different config, create a new ImagenModel
instance with that
config.
Swift
Set the values of the parameters in an
ImagenGenerationConfig
as part of creating an ImagenModel
instance.
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
let config = ImagenGenerationConfig(
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: .landscape16x9,
imageFormat: .jpeg(compressionQuality: 100),
addWatermark: false
)
// Specify the config as part of creating the `ImagenModel` instance
let model = vertex.imagenModel(
modelName: "IMAGEN_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
Set the values of the parameters in an
ImagenGenerationConfig
as part of creating an ImagenModel
instance.
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
val config = ImagenGenerationConfig(
negativePrompt = "frogs",
numberOfImages = 2,
aspectRatio = ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat = ImagenImageFormat.jpeg(compressionQuality = 100),
addWatermark = false
)
// Specify the config as part of creating the `ImagenModel` instance
val imagenModel = Firebase.vertexAI.imagenModel(
modelName = "IMAGEN_MODEL_NAME",
generationConfig = config
)
// ...
Java
Set the values of the parameters in an
ImagenGenerationConfig
as part of creating an ImagenModel
instance.
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
ImagenGenerationConfig config = new ImagenGenerationConfig.Builder()
.setNegativePrompt("frogs")
.setNumberOfImages(2)
.setAspectRatio(ImagenAspectRatio.LANDSCAPE_16x9)
.setImageFormat(ImagenImageFormat.jpeg(100))
.setAddWatermark(false)
.build();
// Specify the config as part of creating the `ImagenModel` instance
ImagenModel m = FirebaseVertexAI.getInstance().imagenModel(
"IMAGEN_MODEL_NAME",
config
);
ImagenModelFutures model = ImagenModelFutures.from(m);
// ...
Web
Set the values of the parameters in an
ImagenGenerationConfig
as part of creating an ImagenModel
instance.
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
const generationConfig = {
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat: ImagenImageFormat.jpeg(100),
addWatermark: false
};
// Specify the config as part of creating the `ImagenModel` instance
const imagenModel = getImagenModel(vertexAI, { model: "IMAGEN_MODEL_NAME", generationConfig });
// ...
Dart
Set the values of the parameters in an
ImagenGenerationConfig
as part of creating an ImagenModel
instance.
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
final generationConfig = ImagenGenerationConfig(
negativePrompt: 'frogs',
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.landscape16x9,
imageFormat: ImagenImageFormat.jpeg(compressionQuality: 100)
addWatermark: false
);
// Specify the config as part of creating the `ImagenModel` instance
final model = FirebaseVertexAI.instance.imagenModel(
model: 'IMAGEN_MODEL_NAME',
config: generationConfig,
);
// ...
You can find a description of each parameter in the next section of this page.
Description of parameters (Imagen)
Here is a high-level overview of the available parameters, as applicable. You can find a comprehensive list of parameters and their values in the Google Cloud documentation.
Parameter | Description | Default value |
---|---|---|
Negative prompt
negativePrompt
|
A description of what you want to omit in generated images
This parameter is not yet supported by
|
--- |
Number of results
numberOfImages
|
The number of generated images returned for each request | default is one image for Imagen 3 models |
Aspect ratio
aspectRatio
|
The ratio of width to height of generated images | default is square (1:1) |
Image format
imageFormat
|
The output options, like the image format (MIME type) and level of compression of generated images | default MIME type is PNG default compression is 75 (if MIME type is set to JPEG) |
Watermark
addWatermark
|
Whether to add a non-visible digital watermark (called a SynthID) to generated images | default is true for Imagen 3 models
|
Person generation
personGeneration
|
Whether to allow generation of people by the model | default depends on the model |
Other options to control content generation
- Learn more about prompt design so that you can influence the model to generate output specific to your needs.
- Use safety settings to adjust the likelihood of getting responses that may be considered harmful, including hate speech and sexually explicit content.
- Set system instructions 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 along with the prompt to specify a specific output schema. This feature is most commonly used when generating JSON output, but it can also be used for classification tasks (like when you want the model to use specific labels or tags).