This package supports many of the API's within the Microsoft.Windows.AI.Text, Microsoft.Windows.AI.Imaging, and Microsoft.Windows.AI namespaces. This package is designed to expose a JavaScript API surface of the native Windows AI API's. Class, method, enum, and parameter names in this package are designed to replicate their native counterparts in WinAppSDK.
Below is the list of supported API's for the @microsoft/windows-ai-electron package. For usage information, see the Usage Guide.
Main class for text generation and AI model interactions. Maps to WinAppSDK Microsoft.Windows.AI.Text.LanguageModel
Static Methods:
CreateAsync()- Asynchronously creates a new LanguageModel instance. Maps to LanguageModel.CreateAsync()GetReadyState()- Returns the current AI feature ready state. Maps to LanguageModel.GetReadyState()EnsureReadyAsync()- Ensures AI features are ready for use. Maps to LanguageModel.EnsureReadyAsync()
Instance Methods:
Important
This method uses a Windows API which is a part of a Limited Access Feature. To request an unlock token, please use the LAF Access Token Request Form. To use this method, you must first call LimitedAccessFeature.TryUnlockToken. See Usage.md for usage examples.
GenerateResponseAsync(string, LanguageModelOptions?)- Generates text response from a prompt. Maps to LanguageModel.GenerateResponseAsync()
Configuration options for language model behavior. Maps to WinAppSDK Microsoft.Windows.AI.Text.LanguageModelOptions
Properties:
Temperature(number) - Controls randomness in generation (0.0-1.0). Maps to LanguageModelOptions.TemperatureTopK(number) - Limits vocabulary for next token selection. Maps to LanguageModelOptions.TopKTopP(number) - Nucleus sampling threshold (0.0-1.0). Maps to LanguageModelOptions.TopPContentFilterOptions(ConftentFilterOptions) - Content safety settings. Maps to LanguageModelOptions.ContentFilterOptions
Contains the result of a text generation operation. Maps to WinAppSDK Microsoft.Windows.AI.Text.LanguageModelResponseResult
Properties:
Text(string) - The generated text response. Maps to LanguageModelResponseResult.TextStatus(number) - Status code from LanguageModelResponseStatus enum. Maps to LanguageModelResponseResult.StatusExtendedError(string) - Extended error information if available. Maps to LanguageModelResponseResult.ExtendedError
Main class for AI-powered text and conversation summarization. Maps to WinAppSDK Microsoft.Windows.AI.Text.TextSummarizer
Constructor:
new TextSummarizer(LanguageModel)- Creates a TextSummarizer with the provided LanguageModel instance. Maps to TextSummarizer(LanguageModel)
Instance Methods:
SummarizeAsync(string)- Asynchronously summarizes the provided text. Maps to TextSummarizer.SummarizeAsync(String)SummarizeParagraphAsync(string)- Asynchronously summarizes a paragraph with paragraph-specific optimization. Maps to TextSummarizer.SummarizeParagraphAsync(String)SummarizeConversationAsync(ConversationItem[], ConversationSummaryOptions)- Asynchronously summarizes a conversation from an array of ConversationItem objects. Maps to TextSummarizer.SummarizeConversationAsync(IVectorView, ConversationSummaryOptions)IsPromptLargerThanContext(string)- Checks if text prompt exceeds context window (returns boolean). Maps to TextSummarizer.IsPromptLargerThanContext(String)IsPromptLargerThanContext(ConversationItem[], ConversationSummaryOptions)- Checks if conversation prompt exceeds context window (returns object with isLarger boolean and cutoffPosition number). Maps to TextSummarizer.IsPromptLargerThanContext(IVectorView, ConversationSummaryOptions, UInt64)
Represents a single message in a conversation for summarization. Maps to WinAppSDK Microsoft.Windows.AI.Text.ConversationItem
Constructor:
new ConversationItem()- Creates a new conversation item. Maps to ConversationItem()
Properties:
Message(string) - The message content. Maps to ConversationItem.MessageParticipant(string) - The participant who sent the message (e.g., "User", "Assistant", "Support"). Maps to ConversationItem.Participant
Configuration options for conversation summarization. Maps to WinAppSDK Microsoft.Windows.AI.Text.ConversationSummaryOptions
Properties:
includeMessageCitations(boolean) - Whether to include references to specific messages in the summary. Maps to ConversationSummaryOptions.IncludeMessageCitationsincludeParticipantAttribution(boolean) - Whether to attribute parts of the summary to specific participants. Maps to ConversationSummaryOptions.IncludeParticipantAttribution
Main class for AI-powered text rewriting and tone adjustment. Maps to WinAppSDK Microsoft.Windows.AI.Text.TextRewriter
Constructor:
new TextRewriter(LanguageModel)- Creates a TextRewriter with the provided LanguageModel instance. Maps to TextRewriter(LanguageModel)
Instance Methods:
RewriteAsync(string)- Asynchronously rewrites the provided text using the default tone. Maps to TextRewriter.RewriteAsync(String)RewriteAsync(string, TextRewriteTone)- Asynchronously rewrites the provided text using the specified TextRewriteTone. Maps to TextRewriter.RewriteAsync(String, TextRewriteTone)
Main class for AI-powered conversion of text content into structured table format. Maps to WinAppSDK Microsoft.Windows.AI.Text.TextToTableConverter
Constructor:
new TextToTableConverter(LanguageModel)- Creates a TextToTableConverter with the provided LanguageModel instance. Maps to TextToTableConverter(LanguageModel)
Instance Methods:
ConvertAsync(string)- Asynchronously converts the provided text into a structured table format, returns TextToTableResponseResult. Maps to TextToTableConverter.ConvertAsync(String)
Result object containing structured table data from text conversion operations. Maps to WinAppSDK Microsoft.Windows.AI.Text.TextToTableResponseResult
Properties:
ExtendedError(string) - Extended error information as hex string (e.g., "0x80004005") if available. Maps to TextToTableResponseResult.ExtendedErrorStatus(number) - Status code from the conversion operation. Maps to TextToTableResponseResult.Status
Methods:
GetRows()- Returns an array of TextToTableRow objects representing the table structure. Maps to TextToTableResponseResult.GetRows()
Represents a single row in a converted table structure. Maps to WinAppSDK Microsoft.Windows.AI.Text.TextToTableRow
Methods:
GetColumns()- Returns an array of strings representing the column values for this row. Maps to TextToTableRow.GetColumns()
Result object for AI feature readiness operations. Maps to WinAppSDK Microsoft.Windows.AI.AIFeatureReadyResult
Properties:
Error(number) - Error code if operation failed. Maps to AIFeatureReadyResult.ErrorErrorDisplayText(string) - Human-readable error description. Maps to AIFeatureReadyResult.ErrorDisplayTextExtendedError(number) - Extended error code. Maps to AIFeatureReadyResult.ExtendedErrorStatus(number) - Operation status fromAIFeatureReadyResultStateenum. Maps to AIFeatureReadyResult.Status
Main class for generating descriptions and captions for images. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.ImageDescriptionGenerator
Static Methods:
CreateAsync()- Asynchronously creates a new ImageDescriptionGenerator instance. Maps to ImageDescriptionGenerator.CreateAsync()GetReadyState()- Returns the current AI feature ready state for image description. Maps to ImageDescriptionGenerator.GetReadyState()EnsureReadyAsync()- Ensures image description features are ready for use. Maps to ImageDescriptionGenerator.EnsureReadyAsync()
Instance Methods:
DescribeAsync(string, ImageDescriptionKind, ContentFilterOptions)- Generates description for an image, file path must be the absolute path to the image. Maps to ImageDescriptionGenerator.DescribeAsync(String, ImageDescriptionKind, ContentFilterOptions)Close()- Closes the generator and releases resources. Maps to ImageDescriptionGenerator.Close()
Contains the result of an image description operation. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.ImageDescriptionResult
Properties:
Description(string) - The generated image description. Maps to ImageDescriptionResult.DescriptionStatus(ImageDescriptionResultStatus) - Status code from ImageDescriptionResultStatus enum. Maps to ImageDescriptionResult.Status
Main class for optical character recognition (OCR) on images. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.TextRecognizer
Static Methods:
CreateAsync()- Asynchronously creates a new TextRecognizer instance. Maps to TextRecognizer.CreateAsync()GetReadyState()- Returns the current AI feature ready state for text recognition. Maps to TextRecognizer.GetReadyState()EnsureReadyAsync()- Ensures text recognition features are ready for use. Maps to TextRecognizer.EnsureReadyAsync()
Instance Methods:
RecognizeTextFromImageAsync(string)- Asynchronously recognizes text in an image, file path must be the absolute path to the image. Maps to TextRecognizer.RecognizeTextFromImageAsync(String)RecognizeTextFromImage(string)- Synchronously recognizes text in an image, file path must be the absolute path to the image. Maps to TextRecognizer.RecognizeTextFromImage(String)Close()- Closes the recognizer and releases resources. Maps to TextRecognizer.Close()Dispose()- Disposes the recognizer and cleans up resources. Maps to TextRecognizer.Dispose()
Contains the complete text recognition results from an image. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.RecognizedText
Properties:
Lines(RecognizedLine[]) - Array of recognized text lines. Maps to RecognizedText.LinesTextAngle(number) - Angle of the text in the image. Maps to RecognizedText.TextAngle
Represents a single line of recognized text. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.RecognizedLine
Properties:
BoundingBox(RecognizedTextBoundingBox) - Bounding box coordinates for the line. Maps to RecognizedLine.BoundingBoxStyle(RecognizedLineStyle) - Text style information from RecognizedLineStyle enum. Maps to RecognizedLine.StyleLineStyleConfidence(number) - Confidence level for the line style. Maps to RecognizedLine.LineStyleConfidenceText(string) - The recognized text content. Maps to RecognizedLine.TextWords(RecognizedWord[]) - Array of individual words in the line. Maps to RecognizedLine.Words
Represents a single recognized word. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.RecognizedWord
Properties:
BoundingBox(RecognizedTextBoundingBox) - Bounding box coordinates for the word. Maps to RecognizedWord.BoundingBoxMatchConfidence(number) - Confidence level for the word recognition. Maps to RecognizedWord.MatchConfidenceText(string) - The recognized word text. Maps to RecognizedWord.Text
Defines the bounding box coordinates for recognized text elements. Maps to WinAppSDK Microsoft.Windows.AI.Imaging.RecognizedTextBoundingBox
Properties:
TopLeft(object) - Top-left corner coordinates {X, Y}. Maps to RecognizedTextBoundingBox.TopLeftTopRight(object) - Top-right corner coordinates {X, Y}. Maps to RecognizedTextBoundingBox.TopRightBottomLeft(object) - Bottom-left corner coordinates {X, Y}. Maps to RecognizedTextBoundingBox.BottomLeftBottomRight(object) - Bottom-right corner coordinates {X, Y}. Maps to RecognizedTextBoundingBox.BottomRight
Configuration for content filtering policies. Maps to WinAppSDK Microsoft.Windows.AI.ContentSafety.ContentFilterOptions
Properties:
imageMaxAllowedSeverityLevel(ImageContentFilterSeverity) - Maximum allowed severity for image content. Maps to ContentFilterOptions.ImageMaxAllowedSeverityLevelpromptMaxAllowedSeverityLevel(TextContentFilterSeverity) - Maximum allowed severity for prompt text. Maps to ContentFilterOptions.PromptMaxAllowedSeverityLevelresponseMaxAllowedSeverityLevel(TextContentFilterSeverity) - Maximum allowed severity for response text. Maps to ContentFilterOptions.ResponseMaxAllowedSeverityLevel
Severity levels for different types of image content. Maps to WinAppSDK Microsoft.Windows.AI.ContentSafety.ImageContentFilterSeverity
Properties:
AdultContentLevel(number) - Severity level for adult content. Maps to ImageContentFilterSeverity.AdultContentLevelGoryContentLevel(number) - Severity level for gory content. Maps to ImageContentFilterSeverity.GoryContentLevelRacyContentLevel(number) - Severity level for racy content. Maps to ImageContentFilterSeverity.RacyContentLevelViolentContentLevel(number) - Severity level for violent content. Maps to ImageContentFilterSeverity.ViolentContentLevel
Severity levels for different types of text content. Maps to WinAppSDK Microsoft.Windows.AI.ContentSafety.TextContentFilterSeverity
Properties:
Hate(number) - Severity level for hate speech. Maps to TextContentFilterSeverity.HateSelfHarm(number) - Severity level for self-harm content. Maps to TextContentFilterSeverity.SelfHarmSexual(number) - Severity level for sexual content. Maps to TextContentFilterSeverity.SexualViolent(number) - Severity level for violent content. Maps to TextContentFilterSeverity.Violent
Important
This class is currently needed to be able to use GenerateResponseAsync. To use this class, you will need to request an unlock token, please use the LAF Access Token Request Form.
Provides access to Windows limited access features that require special permissions or tokens. Maps to WinAppSDK Windows.ApplicationModel.LimitedAccessFeatures
Static Methods:
Important
When attempting to gain access to GenerateResponseAsync, the feature ID should be com.microsoft.windows.ai.languagemodel and the developer signature should be <insert-app-id> has registered their use of com.microsoft.windows.ai.languagemodel with Microsoft and agrees to the terms of use..
TryUnlockFeature(string, string, string)- Attempts to unlock a limited access feature using feature ID, token, and developer signature. Returns LimitedAccessFeatureRequestResult. Maps to LimitedAccessFeatures.TryUnlockFeature(String, String, String)
Contains the result of a limited access feature unlock request. Maps to WinAppSDK Windows.ApplicationModel.LimitedAccessFeatureRequestResult
Properties:
FeatureId(string) - The identifier of the requested feature. Maps to LimitedAccessFeatureRequestResult.FeatureIdStatus(LimitedAccessFeatureStatus) - The status of the unlock request. Maps to LimitedAccessFeatureRequestResult.StatusEstimatedRemovalDate(Date | null) - Estimated date when the feature will be removed, if applicable. Maps to LimitedAccessFeatureRequestResult.EstimatedRemovalDate
Maps to WinAppSDK Microsoft.Windows.AI.AIFeatureReadyState
Ready(0) - AI features are ready for use. Maps to AIFeatureReadyState.ReadyNotReady(1) - AI features are not ready yet. Maps to AIFeatureReadyState.NotReadyNotSupportedOnCurrentSystem(2) - AI not supported on this system. Maps to AIFeatureReadyState.NotSupportedOnCurrentSystemDisabledByUser(3) - AI disabled by user settings. Maps to AIFeatureReadyState.DisabledByUser
Maps to WinAppSDK Microsoft.Windows.AI.Text.LanguageModelResponseStatus
Complete(0) - Generation completed successfully. Maps to LanguageModelResponseStatus.CompleteInProgress(1) - Generation is still in progress. Maps to LanguageModelResponseStatus.InProgressBlockedByPolicy(2) - Request blocked by policy. Maps to LanguageModelResponseStatus.BlockedByPolicyPromptLargerThanContext(3) - Prompt exceeds context length. Maps to LanguageModelResponseStatus.PromptLargerThanContextPromptBlockedByContentModeration(4) - Prompt blocked by content filter. Maps to LanguageModelResponseStatus.PromptBlockedByContentModerationResponseBlockedByContentModeration(5) - Response blocked by content filter. Maps to LanguageModelResponseStatus.ResponseBlockedByContentModerationError(6) - An error occurred during generation. Maps to LanguageModelResponseStatus.Error
Maps to WinAppSDK Microsoft.Windows.AI.ContentSafety.SeverityLevel
Minimum(10) - Minimal content filtering. Maps to SeverityLevel.MinimumLow(11) - Low severity threshold. Maps to SeverityLevel.LowMedium(12) - Medium severity threshold. Maps to SeverityLevel.MediumHigh(13) - High severity threshold. Maps to SeverityLevel.High
Maps to WinAppSDK Microsoft.Windows.AI.AIFeatureReadyResultState
InProgress(0) - Operation is in progress. Maps to AIFeatureReadyResultState.InProgressSuccess(1) - Operation completed successfully. Maps to AIFeatureReadyResultState.SuccessFailure(2) - Operation failed. Maps to AIFeatureReadyResultState.Failure
Maps to WinAppSDK Microsoft.Windows.AI.Imaging.ImageDescriptionKind
BriefDescription(0) - Generate a brief description for the image. Maps to ImageDescriptionKind.BriefDescriptionDetailedDescription(1) - Generate a detailed description of the image. Maps to ImageDescriptionKind.DetailedDescriptionDiagramDescription(2) - Generate a description suitable for diagrams and technical images. Maps to ImageDescriptionKind.DiagramDescriptionAccessibleDescription(3) - Generate accessible description optimized for screen readers. Maps to ImageDescriptionKind.AccessibleDescription
Maps to WinAppSDK Microsoft.Windows.AI.Text.TextRewriteTone
Default(0) - Use the default tone for text rewriting. Maps to TextRewriteTone.DefaultGeneral(1) - Use a general, neutral tone. Maps to TextRewriteTone.GeneralCasual(2) - Use a casual, informal tone. Maps to TextRewriteTone.CasualFormal(3) - Use a formal, professional tone. Maps to TextRewriteTone.Formal
Maps to WinAppSDK Microsoft.Windows.AI.Imaging.ImageDescriptionResultStatus
Success(0) - Image description generated successfully. Maps to ImageDescriptionResultStatus.SuccessFailure(1) - Image description generation failed. Maps to ImageDescriptionResultStatus.FailureContentFiltered(2) - Image description blocked by content filtering. Maps to ImageDescriptionResultStatus.ContentFiltered
Maps to WinAppSDK Microsoft.Windows.AI.Imaging.RecognizedLineStyle
None(0) - No specific style detected. Maps to RecognizedLineStyle.NoneHandwritten(1) - Handwritten text style. Maps to RecognizedLineStyle.HandwrittenPrinted(2) - Printed text style. Maps to RecognizedLineStyle.Printed
Maps to WinAppSDK Windows.ApplicationModel.LimitedAccessFeatureStatus
Available(0) - Limited access feature is available with proper authentication. Maps to LimitedAccessFeatureStatus.AvailableAvailableWithoutToken(1) - Limited access feature is available without requiring a token. Maps to LimitedAccessFeatureStatus.AvailableWithoutTokenUnknown(2) - Limited access feature status is unknown. Maps to LimitedAccessFeatureStatus.UnknownUnavailable(3) - Limited access feature is not available. Maps to LimitedAccessFeatureStatus.Unavailable