Controls the randomness of the language model’s output. Higher values (for
example, 1.0) make the text more random and creative, while lower values (for example,
0.1) make it more focused and deterministic.
topP
Controls diversity of generated text. Higher values (e.g., 0.9) produce more diverse
text, while lower values (e.g., 0.5) make the output more focused.
topK
Limits the number of highest probability words the model considers when generating
text. For example, a topK of 40 means only the 40 most likely words are considered for the
next token. A higher value increases diversity, while a lower value makes the output more
deterministic.
candidateCount
The number of response variations to return; defaults to 1 if not set.
Support for multiple candidates depends on the model; see the
Cloud documentation
for more details.
maxOutputTokens
Maximum number of tokens that can be generated in the response.
See the configure model parameters documentation
for more details.
presencePenalty
Controls the likelihood of repeating the same words or phrases already
generated in the text. Higher values increase the penalty of repetition, resulting in more
diverse output.
frequencyPenalty
Controls the likelihood of repeating words or phrases, with the penalty
increasing for each repetition. Higher values increase the penalty of repetition,
resulting in more diverse output.
stopSequences
A set of up to 5 Strings that will stop output generation. If specified,
the API will stop at the first appearance of a stop sequence. The stop sequence will not
be included as part of the response. See the
Cloud documentation
for more details.
responseMIMEType
Output response MIME type of the generated candidate text.
responseSchema
Output schema of the generated candidate text. If set, a compatible
responseMIMEType must also be set.
responseModalities
The data types (modalities) that may be returned in model responses.
thinkingConfig
Configuration for controlling the “thinking” behavior of compatible Gemini
models; see ThinkingConfig for more details.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-25 UTC."],[],[],null,["# FirebaseAI Framework Reference\n\nGenerationConfig\n================\n\n @available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)\n public struct GenerationConfig : Sendable\n\n extension GenerationConfig: Encodable\n\nA struct defining model parameters to be used when sending generative AI\nrequests to the backend model.\n- `\n ``\n ``\n `\n\n ### [init(temperature:topP:topK:candidateCount:maxOutputTokens:presencePenalty:frequencyPenalty:stopSequences:responseMIMEType:responseSchema:responseModalities:thinkingConfig:)](#/s:10FirebaseAI16GenerationConfigV11temperature4topP0F1K14candidateCount15maxOutputTokens15presencePenalty09frequencyM013stopSequences16responseMIMEType0Q6Schema0Q10Modalities08thinkingD0ACSfSg_APSiSgA2q2PSaySSGSgSSSgAA0S0CSgSayAA16ResponseModalityVGSgAA08ThinkingD0VSgtcfc)\n\n `\n ` \n Creates a new `GenerationConfig` value.\n\n See the\n [Configure model parameters](https://firebase.google.com/docs/vertex-ai/model-parameters)\n guide and the\n [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)\n for more details. \n\n #### Declaration\n\n Swift \n\n public init(temperature: Float? = nil, topP: Float? = nil, topK: Int? = nil,\n candidateCount: Int? = nil, maxOutputTokens: Int? = nil,\n presencePenalty: Float? = nil, frequencyPenalty: Float? = nil,\n stopSequences: [String]? = nil, responseMIMEType: String? = nil,\n responseSchema: ../Classes/Schema.html? = nil, responseModalities: [../Structs/ResponseModality.html]? = nil,\n thinkingConfig: ../Structs/ThinkingConfig.html? = nil)\n\n #### Parameters\n\n |----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*temperature*` ` | Controls the randomness of the language model's output. Higher values (for example, 1.0) make the text more random and creative, while lower values (for example, 0.1) make it more focused and deterministic. |\n | ` `*topP*` ` | Controls diversity of generated text. Higher values (e.g., 0.9) produce more diverse text, while lower values (e.g., 0.5) make the output more focused. |\n | ` `*topK*` ` | Limits the number of highest probability words the model considers when generating text. For example, a topK of 40 means only the 40 most likely words are considered for the next token. A higher value increases diversity, while a lower value makes the output more deterministic. |\n | ` `*candidateCount*` ` | The number of response variations to return; defaults to 1 if not set. Support for multiple candidates depends on the model; see the [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig) for more details. |\n | ` `*maxOutputTokens*` ` | Maximum number of tokens that can be generated in the response. See the configure model parameters [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#max-output-tokens) for more details. |\n | ` `*presencePenalty*` ` | Controls the likelihood of repeating the same words or phrases already generated in the text. Higher values increase the penalty of repetition, resulting in more diverse output. |\n | ` `*frequencyPenalty*` ` | Controls the likelihood of repeating words or phrases, with the penalty increasing for each repetition. Higher values increase the penalty of repetition, resulting in more diverse output. |\n | ` `*stopSequences*` ` | A set of up to 5 `String`s that will stop output generation. If specified, the API will stop at the first appearance of a stop sequence. The stop sequence will not be included as part of the response. See the [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig) for more details. |\n | ` `*responseMIMEType*` ` | Output response MIME type of the generated candidate text. |\n | ` `*responseSchema*` ` | Output schema of the generated candidate text. If set, a compatible `responseMIMEType` must also be set. |\n | ` `*responseModalities*` ` | The data types (modalities) that may be returned in model responses. |\n | ` `*thinkingConfig*` ` | Configuration for controlling the \"thinking\" behavior of compatible Gemini models; see [ThinkingConfig](../Structs/ThinkingConfig.html) for more details. |"]]