properties
TypeScriptget properties(): SessionPropertyValuesSwift declarationfinal var properties: SessionPropertyValues { get }class · iOS 26.0+ · SDK 27.1
final class LanguageModelSessionAn object that represents a session that interacts with a language model. A session is a single context that you use to generate content with, and maintains state between requests. You can reuse the existing instance or create a new one each time you call the model. When you create a session you can provide instructions that tells the model what its role is and provides guidance on how to respond. ```swift let session = LanguageModelSession(instructions: """ You are a motivational workout coach that provides quotes to inspire \ and motivate athletes. """ ) let prompt = "Generate a motivational quote for my next workout." let response = try await session.respond(to: prompt) ``` The framework records each call to the model in a ``Transcript`` that includes all prompts and responses. If your session exceeds the available context size, it throws ``LanguageModelError/contextSizeExceeded(_:)``. For more information on managing the context window size, see <doc:managing-the-context-window>. Use Instruments to analyze token consumption while your app is running and to look for opportunities to improve performance, like with ``prewarm(promptPrefix:)``. For more information on Instruments, see <doc:analyzing-the-runtime-performance-of-your-foundation-models-app>.
get properties(): SessionPropertyValuesSwift declarationfinal var properties: SessionPropertyValues { get }get transcript(): TranscriptSwift declarationfinal var transcript: Transcript { get set }A full history of interactions, including user inputs and model responses.
get isResponding(): booleanSwift declarationfinal var isResponding: Bool { get }A Boolean value that indicates whether a response is being generated. - Important: You should not call any of the respond methods while this property is `true`. Disable buttons and other interactions to prevent users from submitting a second prompt while the model is responding to their first prompt. ```swift struct ShopView: View { @State var session = LanguageModelSession() @State var joke = "" var body: some View { Text(joke) Button("Generate joke") { Task { assert(!session.isResponding, "It should not be possible to tap this button while the model is responding") joke = try await session.respond(to: "Tell me a joke").content } } .disabled(session.isResponding) // Prevent concurrent calls to respond } } ```
streamResponseIncludeSchemaInPromptOptionsPrompt(includeSchemaInPrompt: boolean, options: GenerationOptions, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<number>Swift declarationfinal func streamResponse<Content>(generating type: Content.Type = Content.self, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions(), @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseGeneratingOptionsContextOptionsMetadataPrompt(type: "Bool" | "Int" | "Double" | "Float" | "String" | "Foundation.Decimal" | "FoundationModels.GeneratedContent" | "FoundationModels.ImageReference", options: GenerationOptions, contextOptions: ContextOptions, metadata: Record<string, SDKHandle>, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<unknown>Swift declarationfinal func streamResponse<Content>(generating type: Content.Type = Content.self, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:], @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToIncludeSchemaInPromptOptions(prompt: Prompt, includeSchemaInPrompt?: boolean, options?: GenerationOptions): LanguageModelSession_ResponseStream<number>Swift declarationfinal func streamResponse<Content>(to prompt: Prompt, generating type: Content.Type = Content.self, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToIncludeSchemaInPromptOptions49503(prompt: string, includeSchemaInPrompt?: boolean, options?: GenerationOptions): LanguageModelSession_ResponseStream<number>Swift declarationfinal func streamResponse<Content>(to prompt: String, generating type: Content.Type = Content.self, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToGeneratingOptionsContextOptionsMetadata(prompt: Prompt, type?: "Bool" | "Int" | "Double" | "Float" | "String" | "Foundation.Decimal" | "FoundationModels.GeneratedContent" | "FoundationModels.ImageReference", options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<unknown>Swift declarationfinal func streamResponse<Content>(to prompt: Prompt, generating type: Content.Type = Content.self, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToGeneratingOptionsContextOptionsMetadata69944(prompt: string, type?: "Bool" | "Int" | "Double" | "Float" | "String" | "Foundation.Decimal" | "FoundationModels.GeneratedContent" | "FoundationModels.ImageReference", options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<unknown>Swift declarationfinal func streamResponse<Content>(to prompt: String, generating type: Content.Type = Content.self, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<Content> where Content : GenerableProduces a response stream to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToSchemaIncludeSchemaInPromptOptions(prompt: Prompt, schema: GenerationSchema, includeSchemaInPrompt?: boolean, options?: GenerationOptions): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(to prompt: Prompt, schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToSchemaIncludeSchemaInPromptOptions56182(prompt: string, schema: GenerationSchema, includeSchemaInPrompt?: boolean, options?: GenerationOptions): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(to prompt: String, schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToSchemaOptionsContextOptionsMetadata(prompt: Prompt, schema: GenerationSchema, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(to prompt: Prompt, schema: GenerationSchema, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToSchemaOptionsContextOptionsMetadata77454(prompt: string, schema: GenerationSchema, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(to prompt: String, schema: GenerationSchema, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseToOptionsContextOptionsMetadata(prompt: Prompt, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(to prompt: Prompt, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces aggregated tokens.
streamResponseToOptionsContextOptionsMetadata41858(prompt: string, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(to prompt: String, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(), metadata: [String : any ConvertibleToGeneratedContent] = [:]) -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces aggregated tokens.
streamResponseToOptions(prompt: Prompt, options?: GenerationOptions): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(to prompt: Prompt, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces aggregated tokens.
streamResponseToOptions65097(prompt: string, options?: GenerationOptions): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(to prompt: String, options: GenerationOptions = GenerationOptions()) -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces aggregated tokens.
streamResponseSchemaIncludeSchemaInPromptOptionsPrompt(schema: GenerationSchema, includeSchemaInPrompt: boolean, options: GenerationOptions, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions(), @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseSchemaOptionsContextOptionsMetadataPrompt(schema: GenerationSchema, options: GenerationOptions, contextOptions: ContextOptions, metadata: Record<string, SDKHandle>, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<GeneratedContent>Swift declarationfinal func streamResponse(schema: GenerationSchema, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:], @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<GeneratedContent>Produces a response stream to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces ``GeneratedContent`` containing the fields and values defined in the schema.
streamResponseOptionsContextOptionsMetadataPrompt(options: GenerationOptions, contextOptions: ContextOptions, metadata: Record<string, SDKHandle>, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(), metadata: [String : any ConvertibleToGeneratedContent] = [:], @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A response stream that produces aggregated tokens.
streamResponseOptionsPrompt(options: GenerationOptions, prompt: (() => Prompt)): LanguageModelSession_ResponseStream<string>Swift declarationfinal func streamResponse(options: GenerationOptions = GenerationOptions(), @PromptBuilder prompt: () throws -> Prompt) rethrows -> sending LanguageModelSession.ResponseStream<String>Produces a response stream to a prompt. - Important: If running in the background, use the non-streaming ``LanguageModelSession/respond(to:options:)-(Prompt,_)`` method to reduce the likelihood of encountering ``LanguageModelError/rateLimited(_:)`` errors. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A response stream that produces aggregated tokens.
logFeedbackAttachmentSentimentIssuesDesiredOutput(sentiment?: (LanguageModelFeedback_Sentiment) | null, issues?: Array<LanguageModelFeedback_Issue>, desiredOutput?: (Transcript_Entry) | null): ArrayBufferSwift declaration@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredOutput: Transcript.Entry? = nil) -> DataLogs and serializes a feedback attachment that can be submitted to Apple. This method creates a structured feedback attachment containing the session's transcript and any provided feedback information. The attachment can be saved to a file and submitted to Apple using [Feedback Assistant](https://feedbackassistant.apple.com). If an error occurred during a previous response, any rejected entries that were rolled back from the transcript are included in the feedback data. ```swift let session = LanguageModelSession() let response = try await session.respond(to: "What is the capital of France?") // Create feedback for a helpful response let feedbackData = session.logFeedbackAttachment(sentiment: .positive) // Or create feedback for a problematic response let feedbackData = session.logFeedbackAttachment( sentiment: .negative, issues: [ LanguageModelFeedback.Issue( category: .incorrect, explanation: "The model provided outdated information" ) ], desiredOutput: Transcript.Entry.response(...) ) ``` If your `desiredOutput` is a string, use ``Transcript/Entry/response(_:)`` to turn your desired output into a ``Transcript`` entry: ```swift let text = Transcript.TextSegment(content: "The capital of France is Paris.") let segment = Transcript.Segment.text(text) let response = Transcript.Response(segments: [segment]) let entry = Transcript.Entry.response(response) ``` If your `desiredOutput` is a ``Generable`` type, turning that into a ``Transcript`` entry is slightly different: ```swift let customType = MyCustomType(...) // A generable type. let structure = Transcript.StructuredSegment(schemaName: String(describing: Foo.self), content: customType.generatedContent) let segment = Transcript.Segment.structure(structure) let response = Transcript.Response(segments: [segment]) let entry = Transcript.Entry.response(response) ``` Finally, if you'd like to submit the feedback to Apple, write your feedback to a `.json` file and include the file as an attachment to [Feedback Assistant](https://feedbackassistant.apple.com). You can include one or many feedback attachment in the same file: ```swift let allFeedback = feedbackData + feedbackData2 + feedbackData3 let url = URL(fileURLWithPath: "path/to/save/feedback.json") try allFeedback.write(to: url) ``` - Parameters: - sentiment: An optional sentiment rating about the model's output (positive, negative, or neutral). - issues: An array of specific issues identified with the model's response. Defaults to an empty array. - desiredOutput: An optional transcript entry showing what the desired output should have been. - Returns: A `Data` object containing the JSON-encoded feedback attachment that can be submitted to Feedback Assistant.
logFeedbackAttachmentSentimentIssuesDesiredResponseText(sentiment?: (LanguageModelFeedback_Sentiment) | null, issues?: Array<LanguageModelFeedback_Issue>, desiredResponseText?: (string) | null): ArrayBufferSwift declaration@backDeployed(before: iOS 26.1, macOS 26.1, visionOS 26.1)
@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredResponseText: String?) -> DatalogFeedbackAttachmentSentimentIssuesDesiredResponseContent(sentiment?: (LanguageModelFeedback_Sentiment) | null, issues?: Array<LanguageModelFeedback_Issue>, desiredResponseContent?: (SDKHandle) | null): ArrayBufferSwift declaration@backDeployed(before: iOS 26.1, macOS 26.1, visionOS 26.1)
@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredResponseContent: (any ConvertibleToGeneratedContent)?) -> Dataget transcriptErrorHandlingPolicy(): (TranscriptErrorHandlingPolicy) | nullSwift declarationfinal var transcriptErrorHandlingPolicy: TranscriptErrorHandlingPolicy? { get set }The session's policy for managing the transcript when errors occur.
set transcriptErrorHandlingPolicy(value: (TranscriptErrorHandlingPolicy) | null)Swift declarationfinal var transcriptErrorHandlingPolicy: TranscriptErrorHandlingPolicy? { get set }The session's policy for managing the transcript when errors occur.
static initModelToolsTranscript(model: SystemLanguageModel, tools: Array<SDKHandle>, transcript: Transcript): LanguageModelSessionSwift declarationconvenience init(model: SystemLanguageModel = .default, tools: [any Tool] = [], transcript: Transcript)Creates a session by rehydrating from a transcript. - Parameters - model: The language model to use for this session. - transcript: A transcript to resume from. - tools: Tools to make available to the model for this session.
static initModelToolsInstructions(model?: SystemLanguageModel, tools?: Array<SDKHandle>, instructions?: (Instructions) | null): LanguageModelSessionSwift declarationconvenience init(model: SystemLanguageModel = .default, tools: [any Tool] = [], instructions: Instructions? = nil)Creates a session in a blank slate state with instructions. - Parameters - model: The language model to use for this session. - tools: Tools to make available to the model for this session. - instructions: Instructions that control the model's behavior.
static initModelToolsInstructions11508(model: SystemLanguageModel, tools: Array<SDKHandle>, instructions: (() => Instructions)): LanguageModelSessionSwift declarationconvenience init(model: SystemLanguageModel = .default, tools: [any Tool] = [], @InstructionsBuilder instructions: () throws -> Instructions) rethrowsCreates a session in a blank slate state with an instructions builder. - Parameters - model: The language model to use for this session. - tools: Tools to make available to the model for this session. - instructions: Instructions that control the model's behavior.
static initModelToolsInstructions81584(model?: SystemLanguageModel, tools?: Array<SDKHandle>, instructions?: (string) | null): LanguageModelSessionSwift declarationconvenience init(model: SystemLanguageModel = .default, tools: [any Tool] = [], instructions: String? = nil)Creates a session in a blank slate state with string-based instructions. - Parameters - model: The language model to use for this session. - tools: Tools to make available to the model for this session. - instructions: Instructions that control the model's behavior.
get usage(): LanguageModelSession_UsageSwift declarationfinal var usage: LanguageModelSession.Usage { get }The total accumulated usage across all responses generated by this session. This value increases monotonically over the lifetime of the session.
prewarm(promptPrefix?: (Prompt) | null): voidSwift declarationfinal func prewarm(promptPrefix: Prompt? = nil)Loads the resources required for this session into memory ahead of a request. This method can be useful in cases where you have a strong signal that the user will interact with session within a few seconds. For example, you might call `prewarm(promptPrefix:)` when a person begins typing into a text field. If you know a prefix for the future prompt, passing it to `prewarm(promptPrefix:)` allows the system to process the prompt eagerly and reduce latency for the future request. - Important: You should only use prewarm when you have a window of at least 1 second before the call to a respond method, like ``respond(to:options:)-(Prompt,_)`` or ``streamResponse(to:options:)-(Prompt,_)``. Calling this method doesn't guarantee that the system loads your assets immediately, particularly if your app is running in the background or the system is under load.
respondToIncludeSchemaInPromptOptions(prompt: Prompt, includeSchemaInPrompt?: boolean, options?: GenerationOptions): Promise<LanguageModelSession_Response<number>>Swift declaration@discardableResult nonisolated(nonsending) final func respond<Content>(to prompt: Prompt, generating type: Content.Type = Content.self, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<Content> where Content : GenerableProduces a generable object as a response to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToIncludeSchemaInPromptOptions42884(prompt: string, includeSchemaInPrompt?: boolean, options?: GenerationOptions): Promise<LanguageModelSession_Response<number>>Swift declaration@discardableResult nonisolated(nonsending) final func respond<Content>(to prompt: String, generating type: Content.Type = Content.self, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<Content> where Content : GenerableProduces a generable object as a response to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToGeneratingOptionsContextOptionsMetadata(prompt: Prompt, type?: "Bool" | "Int" | "Double" | "Float" | "String" | "Foundation.Decimal" | "FoundationModels.GeneratedContent" | "FoundationModels.ImageReference", options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<unknown>>Swift declaration@discardableResult nonisolated(nonsending) final func respond<Content>(to prompt: Prompt, generating type: Content.Type = Content.self, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<Content> where Content : GenerableProduces a generable object as a response to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToGeneratingOptionsContextOptionsMetadata53237(prompt: string, type?: "Bool" | "Int" | "Double" | "Float" | "String" | "Foundation.Decimal" | "FoundationModels.GeneratedContent" | "FoundationModels.ImageReference", options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<unknown>>Swift declaration@discardableResult nonisolated(nonsending) final func respond<Content>(to prompt: String, generating type: Content.Type = Content.self, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<Content> where Content : GenerableProduces a generable object as a response to a prompt. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - type: A type to produce as the response. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToSchemaIncludeSchemaInPromptOptions(prompt: Prompt, schema: GenerationSchema, includeSchemaInPrompt?: boolean, options?: GenerationOptions): Promise<LanguageModelSession_Response<GeneratedContent>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: Prompt, schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<GeneratedContent>Produces a generated content type as a response to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToSchemaIncludeSchemaInPromptOptions36651(prompt: string, schema: GenerationSchema, includeSchemaInPrompt?: boolean, options?: GenerationOptions): Promise<LanguageModelSession_Response<GeneratedContent>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: String, schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<GeneratedContent>Produces a generated content type as a response to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - includeSchemaInPrompt: If `true`, injects the schema into the prompt to bias the model. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToSchemaOptionsContextOptionsMetadata(prompt: Prompt, schema: GenerationSchema, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<GeneratedContent>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: Prompt, schema: GenerationSchema, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<GeneratedContent>Produces a generated content type as a response to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToSchemaOptionsContextOptionsMetadata41640(prompt: string, schema: GenerationSchema, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<GeneratedContent>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: String, schema: GenerationSchema, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(includeSchemaInPrompt: true), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<GeneratedContent>Produces a generated content type as a response to a prompt and schema. Consider using the default value of `true` for `includeSchemaInPrompt`. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session. - Parameters: - prompt: A prompt for the model to respond to. - schema: A schema to guide the output with. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: ``GeneratedContent`` containing the fields and values defined in the schema.
respondToOptionsContextOptionsMetadata(prompt: Prompt, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<string>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: Prompt, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<String>Produces a response to a prompt. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A string composed of the tokens produced by sampling model output.
respondToOptionsContextOptionsMetadata6997(prompt: string, options?: GenerationOptions, contextOptions?: ContextOptions, metadata?: Record<string, SDKHandle>): Promise<LanguageModelSession_Response<string>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: String, options: GenerationOptions = GenerationOptions(), contextOptions: ContextOptions = ContextOptions(), metadata: [String : any ConvertibleToGeneratedContent] = [:]) async throws -> LanguageModelSession.Response<String>Produces a response to a prompt. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - contextOptions: Settings that configure how the model is prompted. - metadata: Metadata to attach to the request. - Returns: A string composed of the tokens produced by sampling model output.
respondToOptions(prompt: Prompt, options?: GenerationOptions): Promise<LanguageModelSession_Response<string>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: Prompt, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<String>Produces a response to a prompt. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A string composed of the tokens produced by sampling model output.
respondToOptions26720(prompt: string, options?: GenerationOptions): Promise<LanguageModelSession_Response<string>>Swift declaration@discardableResult nonisolated(nonsending) final func respond(to prompt: String, options: GenerationOptions = GenerationOptions()) async throws -> LanguageModelSession.Response<String>Produces a response to a prompt. - Parameters: - prompt: A prompt for the model to respond to. - options: Options that control how tokens are sampled from the distribution the model produces. - Returns: A string composed of the tokens produced by sampling model output.
13 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
LanguageModelSession.init(profile:history:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.init(model:dynamicInstructions:history:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.transcript
The iOS SDK compiler rejected this binding: setter for 'transcript' is only available in iOS 27.0 or newer
LanguageModelSession.init(model:tools:instructions:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.init(model:tools:transcript:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.init(model:tools:instructions:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.init(model:tools:instructions:)
This protocol needs associated types that cannot yet cross the bridge.
LanguageModelSession.respond(options:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency
LanguageModelSession.respond(schema:includeSchemaInPrompt:options:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency
LanguageModelSession.respond(generating:includeSchemaInPrompt:options:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency
LanguageModelSession.respond(options:contextOptions:metadata:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency
LanguageModelSession.respond(schema:options:contextOptions:metadata:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency
LanguageModelSession.respond(generating:options:contextOptions:metadata:prompt:)
The iOS SDK compiler rejected this binding: 'async' call in a function that does not support concurrency