Options that control how the model generates its response to a prompt.
Generation options determine the decoding strategy the framework uses to adjust
the way the model chooses output tokens. When you interact with the model, it
converts your input to a token sequence, and uses it to generate the response.
Only use ``maximumResponseTokens`` when you need to protect against unexpectedly
verbose responses. Enforcing a strict token response limit can lead to the model
producing malformed results or grammatically incorrect responses.
All input to the model contributes tokens to the context window of the
``LanguageModelSession`` --- including the ``Instructions``, ``Prompt``, ``Tool``,
and ``Generable`` types, and the model's responses. If your session exceeds the
available context size, it throws
``LanguageModelError/contextSizeExceeded(_:)``. For more
information on managing the context window size, see
<doc:managing-the-context-window>.
Members (13)
get · iOS 26.0+
temperature
TypeScript
get temperature(): (number) | null
Swift declaration
var temperature: Double?
A value that influences the confidence of the model's response.
The value of this property must be a number between `0` and `1` inclusive.
Temperature is an adjustment applied to the probability distribution
prior to sampling. A value of `1` results in no adjustment. Values less
than `1` make the probability distribution sharper, with already
likely tokens becoming even more likely.
The net effect is that low temperatures manifest as more stable and
predictable responses, while high temperatures give the model more
creative license.
- Note: Leaving `temperature` nil lets the system choose a reasonable
default on your behalf.
set · iOS 26.0+
temperature
TypeScript
set temperature(value: (number) | null)
Swift declaration
var temperature: Double?
A value that influences the confidence of the model's response.
The value of this property must be a number between `0` and `1` inclusive.
Temperature is an adjustment applied to the probability distribution
prior to sampling. A value of `1` results in no adjustment. Values less
than `1` make the probability distribution sharper, with already
likely tokens becoming even more likely.
The net effect is that low temperatures manifest as more stable and
predictable responses, while high temperatures give the model more
creative license.
- Note: Leaving `temperature` nil lets the system choose a reasonable
default on your behalf.
Creates generation options that control token sampling behavior.
- Parameters:
- samplingMode: A strategy to use for sampling from a distribution.
- temperature: A value between `0` and `1`, inclusive, that controls how sharply the model
favors its most likely responses. A higher value increases variety.
- maximumResponseTokens: The maximum number of tokens the model is allowed
to produce before being artificially halted. Must be positive.
- toolCalling: The requirements defining how the model should call tools.
get samplingMode(): (GenerationOptions_SamplingMode) | null
Swift declaration
@backDeployed(before: iOS 27.0, macOS 27.0, visionOS 27.0)
var samplingMode: GenerationOptions.SamplingMode? { get set }
A sampling strategy for how the model picks tokens when generating a
response.
When you execute a prompt on a model, the model produces a probability
for every token in its vocabulary. The sampling strategy controls how
the model narrows down the list of tokens to consider during that process.
A strategy that picks the single most likely token yields a predictable
response every time, but other strategies offer results that often
sound more natural to a person.
- Note: Leaving the `sampling` nil lets the system choose a
a reasonable default on your behalf.
set · iOS 26.0+
samplingMode
TypeScript
set samplingMode(value: (GenerationOptions_SamplingMode) | null)
Swift declaration
@backDeployed(before: iOS 27.0, macOS 27.0, visionOS 27.0)
var samplingMode: GenerationOptions.SamplingMode? { get set }
A sampling strategy for how the model picks tokens when generating a
response.
When you execute a prompt on a model, the model produces a probability
for every token in its vocabulary. The sampling strategy controls how
the model narrows down the list of tokens to consider during that process.
A strategy that picks the single most likely token yields a predictable
response every time, but other strategies offer results that often
sound more natural to a person.
- Note: Leaving the `sampling` nil lets the system choose a
a reasonable default on your behalf.
get · iOS 27.0+
toolCallingMode
TypeScript
get toolCallingMode(): (GenerationOptions_ToolCallingMode) | null
Swift declaration
var toolCallingMode: GenerationOptions.ToolCallingMode?
The tool calling requirements.
set · iOS 27.0+
toolCallingMode
TypeScript
set toolCallingMode(value: (GenerationOptions_ToolCallingMode) | null)
Swift declaration
var toolCallingMode: GenerationOptions.ToolCallingMode?
The tool calling requirements.
get · iOS 26.0+
maximumResponseTokens
TypeScript
get maximumResponseTokens(): (number) | null
Swift declaration
var maximumResponseTokens: Int?
The maximum number of tokens the model is allowed to produce in its response.
If the model produce `maximumResponseTokens` before it naturally completes its response,
the framework terminates the response early, without throwing an error. Use this property
to protect against unexpectedly verbose responses and runaway generations.
If no value is specified, then the model is allowed to produce the longest answer
its context size supports. If the response exceeds that limit without terminating,
the framework throws an error.
set · iOS 26.0+
maximumResponseTokens
TypeScript
set maximumResponseTokens(value: (number) | null)
Swift declaration
var maximumResponseTokens: Int?
The maximum number of tokens the model is allowed to produce in its response.
If the model produce `maximumResponseTokens` before it naturally completes its response,
the framework terminates the response early, without throwing an error. Use this property
to protect against unexpectedly verbose responses and runaway generations.
If no value is specified, then the model is allowed to produce the longest answer
its context size supports. If the response exceeds that limit without terminating,
the framework throws an error.
Creates generation options that control token sampling behavior.
- Parameters:
- sampling: A strategy to use for sampling from a distribution.
- temperature: Increasing temperature makes it possible for the model to produce less likely
responses. Must be between `0` and `1`, inclusive.
- maximumResponseTokens: The maximum number of tokens the model is allowed
to produce before being artificially halted. Must be positive.
get · iOS 26.0+
sampling
TypeScript
get sampling(): (GenerationOptions_SamplingMode) | null
Swift declaration
var sampling: GenerationOptions.SamplingMode?
A sampling strategy for how the model picks tokens when generating a
response.
When you execute a prompt on a model, the model produces a probability
for every token in its vocabulary. The sampling strategy controls how
the model narrows down the list of tokens to consider during that process.
A strategy that picks the single most likely token yields a predictable
response every time, but other strategies offer results that often
sound more natural to a person.
- Note: Leaving the `sampling` nil lets the system choose a
a reasonable default on your behalf.
set · iOS 26.0+
sampling
TypeScript
set sampling(value: (GenerationOptions_SamplingMode) | null)
Swift declaration
var sampling: GenerationOptions.SamplingMode?
A sampling strategy for how the model picks tokens when generating a
response.
When you execute a prompt on a model, the model produces a probability
for every token in its vocabulary. The sampling strategy controls how
the model narrows down the list of tokens to consider during that process.
A strategy that picks the single most likely token yields a predictable
response every time, but other strategies offer results that often
sound more natural to a person.
- Note: Leaving the `sampling` nil lets the system choose a
a reasonable default on your behalf.