<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 27.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).

When a property is `nil`, the framework defers to the underlying
[`LanguageModel`](/documentation/FoundationModels/LanguageModel) to select an appropriate value. Each model, and each version
of a given model, may pick a different default, and the framework doesn’t
guarantee a specific value or that the value remains stable across OS or model
updates.

## Topics

### Creating options

[`init(samplingMode: GenerationOptions.SamplingMode?, temperature: Double?, maximumResponseTokens: Int?)`](/documentation/FoundationModels/GenerationOptions/init(samplingMode:temperature:maximumResponseTokens:))

Creates generation options that control token sampling behavior.

[`init(samplingMode: GenerationOptions.SamplingMode?, temperature: Double?, maximumResponseTokens: Int?, toolCallingMode: GenerationOptions.ToolCallingMode?)`](/documentation/FoundationModels/GenerationOptions/init(samplingMode:temperature:maximumResponseTokens:toolCallingMode:))

Creates generation options that control token sampling behavior.

[`init(sampling: GenerationOptions.SamplingMode?, temperature: Double?, maximumResponseTokens: Int?)`](/documentation/FoundationModels/GenerationOptions/init(sampling:temperature:maximumResponseTokens:))

Creates generation options that control token sampling behavior.

### Configuring options

[`var temperature: Double?`](/documentation/FoundationModels/GenerationOptions/temperature)

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

[`var sampling: GenerationOptions.SamplingMode?`](/documentation/FoundationModels/GenerationOptions/sampling)

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

[`var samplingMode: GenerationOptions.SamplingMode?`](/documentation/FoundationModels/GenerationOptions/samplingMode-swift.property)

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

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

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

[`var toolCallingMode: GenerationOptions.ToolCallingMode?`](/documentation/FoundationModels/GenerationOptions/toolCallingMode-swift.property)

The tool calling requirements.

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

A value that describes how the model uses tools.

[`var maximumResponseTokens: Int?`](/documentation/FoundationModels/GenerationOptions/maximumResponseTokens)

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

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)