---
title: GenerationOptions
framework: foundationmodels
role: symbol
role_heading: Structure
path: foundationmodels/generationoptions
---

# GenerationOptions

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

## Declaration

```swift
struct GenerationOptions
```

## Mentioned in

Generating content and performing tasks with Foundation Models

## Overview

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 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 Managing the context window.

## Topics

### Creating options

- [init(samplingMode:temperature:maximumResponseTokens:)](foundationmodels/generationoptions/init(samplingmode:temperature:maximumresponsetokens:).md)
- [init(samplingMode:temperature:maximumResponseTokens:toolCallingMode:)](foundationmodels/generationoptions/init(samplingmode:temperature:maximumresponsetokens:toolcallingmode:).md)
- [init(sampling:temperature:maximumResponseTokens:)](foundationmodels/generationoptions/init(sampling:temperature:maximumresponsetokens:).md)

### Configuring options

- [temperature](foundationmodels/generationoptions/temperature.md)
- [sampling](foundationmodels/generationoptions/sampling.md)
- [samplingMode](foundationmodels/generationoptions/samplingmode-swift.property.md)
- [GenerationOptions.SamplingMode](foundationmodels/generationoptions/samplingmode-swift.struct.md)
- [toolCallingMode](foundationmodels/generationoptions/toolcallingmode-swift.property.md)
- [GenerationOptions.ToolCallingMode](foundationmodels/generationoptions/toolcallingmode-swift.struct.md)
- [maximumResponseTokens](foundationmodels/generationoptions/maximumresponsetokens.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Sessions and prompts

- [Prompting an on-device foundation model](foundationmodels/prompting-an-on-device-foundation-model.md)
- [Managing the context window](foundationmodels/managing-the-context-window.md)
- [Updating prompts for new model versions](foundationmodels/updating-prompts-for-new-model-versions.md)
- [LanguageModelSession](foundationmodels/languagemodelsession.md)
- [Instructions](foundationmodels/instructions.md)
- [Prompt](foundationmodels/prompt.md)
- [Transcript](foundationmodels/transcript.md)
- [TranscriptErrorHandlingPolicy](foundationmodels/transcripterrorhandlingpolicy.md)
- [ContextOptions](foundationmodels/contextoptions.md)
