---
title: LanguageModelExecutor
framework: foundationmodels
role: symbol
role_heading: Protocol
path: foundationmodels/languagemodelexecutor
---

# LanguageModelExecutor

A protocol that defines the interface for responding to session requests.

## Declaration

```swift
protocol LanguageModelExecutor : Sendable
```

## Overview

Overview An executor is the bridge between the framework types and the system that actually generates the tokens, like a server API or a local inference engine. A LanguageModel pairs with exactly one executor type and the framework instantiates the executor from the Configuration the model provides. Every request can include preferences that control generation: When the framework calls respond(to:model:streamingInto:), handle converting the transcript into the format your model expects and applying generation options. In some cases, you may need to fall back when your model can’t do exactly what was asked, like using temperature to approximate sampling options: // Parse generation and context options func respond(     to request: LanguageModelExecutorGenerationRequest,     model: MyLanguageModel,     streamingInto channel: LanguageModelExecutorGenerationChannel ) async throws {

// The request includes a sampling set to `greedy`, but your     // model only uses temperature.     if request.generationOptions.samplingMode == .greedy {         // Use the temperature of `0` to approximate the intention.     }

// ... } Use LanguageModelExecutorGenerationChannel to stream incremental events back as generation progresses. You don’t return a value or close the channel explicitly. The channel finishes when the method returns or when an error is thrown.

## Topics

### Creating an executor

- [init(configuration:)](foundationmodels/languagemodelexecutor/init(configuration:).md)
- [Configuration](foundationmodels/languagemodelexecutor/configuration.md)

### Prewarming the model

- [prewarm(model:transcript:)](foundationmodels/languagemodelexecutor/prewarm(model:transcript:).md)
- [Model](foundationmodels/languagemodelexecutor/model.md)

### Handling the response

- [respond(to:model:streamingInto:)](foundationmodels/languagemodelexecutor/respond(to:model:streaminginto:).md)

## Relationships

### Inherits From

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

## See Also

### Custom language model provider

- [Optimizing key-value caching in language model sessions](foundationmodels/optimizing-key-value-caching-in-language-model-sessions.md)
- [LanguageModel](foundationmodels/languagemodel.md)
- [LanguageModelCapabilities](foundationmodels/languagemodelcapabilities.md)
- [LanguageModelExecutorGenerationChannel](foundationmodels/languagemodelexecutorgenerationchannel.md)
- [LanguageModelExecutorGenerationRequest](foundationmodels/languagemodelexecutorgenerationrequest.md)
