<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/GenerationOptions",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation Models"
    ],
    "preciseIdentifier" : "s:16FoundationModels17GenerationOptionsV"
  },
  "title" : "GenerationOptions"
}
-->

# GenerationOptions

Options that control how the model generates its response to a prompt.

```
struct GenerationOptions
```

## Overview

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`](/documentation/FoundationModels/GenerationOptions/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`](/documentation/FoundationModels/LanguageModelSession) — including the [`Instructions`](/documentation/FoundationModels/Instructions), [`Prompt`](/documentation/FoundationModels/Prompt), [`Tool`](/documentation/FoundationModels/Tool),
and [`Generable`](/documentation/FoundationModels/Generable) types, and the model’s responses. If your session exceeds the
available context size, it throws
[`LanguageModelError.contextSizeExceeded(_:)`](/documentation/FoundationModels/LanguageModelError/contextSizeExceeded(_:)). For more
information on managing the context window size, see
[Managing the context window](/documentation/FoundationModels/managing-the-context-window).

## Topics

### Creating options

[`init(samplingMode:temperature:maximumResponseTokens:)`](/documentation/FoundationModels/GenerationOptions/init(samplingMode:temperature:maximumResponseTokens:))

[`init(samplingMode:temperature:maximumResponseTokens:toolCallingMode:)`](/documentation/FoundationModels/GenerationOptions/init(samplingMode:temperature:maximumResponseTokens:toolCallingMode:))

Creates generation options that control token sampling behavior.

[`init(sampling:temperature:maximumResponseTokens:)`](/documentation/FoundationModels/GenerationOptions/init(sampling:temperature:maximumResponseTokens:))

Creates generation options that control token sampling behavior.

### Configuring options

[`temperature`](/documentation/FoundationModels/GenerationOptions/temperature)

A value that influences the confidence of the model’s response.

[`sampling`](/documentation/FoundationModels/GenerationOptions/sampling)

A sampling strategy for how the model picks tokens when generating a
response.

[`samplingMode`](/documentation/FoundationModels/GenerationOptions/samplingMode-swift.property)

A sampling strategy for how the model picks tokens when generating a
response.

[`GenerationOptions.SamplingMode`](/documentation/FoundationModels/GenerationOptions/SamplingMode-swift.struct)

A type that defines how values are sampled from a probability distribution.

[`toolCallingMode`](/documentation/FoundationModels/GenerationOptions/toolCallingMode-swift.property)

The tool calling requirements.

[`GenerationOptions.ToolCallingMode`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct)

A value you use to describe the model behavior when it comes to tool usage.

[`maximumResponseTokens`](/documentation/FoundationModels/GenerationOptions/maximumResponseTokens)

The maximum number of tokens the model is allowed to produce in its response.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)