---
title: maximumResponseTokens
framework: foundationmodels
role: symbol
role_heading: Instance Property
path: foundationmodels/generationoptions/maximumresponsetokens
---

# maximumResponseTokens

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

## Declaration

```swift
var maximumResponseTokens: Int?
```

## Mentioned in

Managing the context window

## Discussion

Discussion If the model produce maximumResponseTokens before it naturally completes its response, the response will be terminated early. No error will be thrown. This property can be used 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, an error will be thrown.

## See Also

### 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)
