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

# LanguageModelExecutor

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

```
protocol LanguageModelExecutor : Sendable
```

## 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`](/documentation/FoundationModels/LanguageModel)
pairs with exactly one executor type and the framework instantiates the executor
from the [`Configuration`](/documentation/FoundationModels/LanguageModelExecutor/Configuration) the model provides.

Every request can include preferences that control generation:

- [`GenerationOptions`](/documentation/FoundationModels/GenerationOptions): Configures the sampling strategy, temperature,
  and maximum response length.
- [`ContextOptions`](/documentation/FoundationModels/ContextOptions): Configures the prompting behavior and thinking effort.

When the framework calls [`respond(to:model:streamingInto:)`](/documentation/FoundationModels/LanguageModelExecutor/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:

```swift
// 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`](/documentation/FoundationModels/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:)`](/documentation/FoundationModels/LanguageModelExecutor/init(configuration:))

Creates an executor from a configuration.

[`Configuration`](/documentation/FoundationModels/LanguageModelExecutor/Configuration)

### Prewarming the model

[`prewarm(model:transcript:)`](/documentation/FoundationModels/LanguageModelExecutor/prewarm(model:transcript:))

Loads assets into memory or pre-fills caches ahead of a request.

[`Model`](/documentation/FoundationModels/LanguageModelExecutor/Model)

The model type this executor processes requests for.

### Handling the response

[`respond(to:model:streamingInto:)`](/documentation/FoundationModels/LanguageModelExecutor/respond(to:model:streamingInto:))

Creates a response stream containing deltas.



---

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)