Simplified access to AI in Microsoft Edge: Introducing the Prompt and Writing Assistance APIs
Local AI models are a great way to bring AI capabilities to your web application with increased privacy, network independence, and, most importantly, reduced costs relative to cloud-based services. But hosting local AI models on the web, via existing The post Simplified access to AI in Microsoft Edge: Introducing the Prompt and Writing Assistance APIs appeared first on Windows Blog.

Local AI models are a great way to bring AI capabilities to your web application with increased privacy, network independence, and, most importantly, reduced costs relative to cloud-based services. But hosting local AI models on the web, via existing solutions based on WebNN or WebGPU, may require domain-specific AI/ML expertise and lead to high model download costs for users and developers (since models aren't shared across domains).
We're excited to introduce experimental web APIs in Microsoft Edge that make it easier than ever for web developers to integrate AI into their web applications. The Prompt API and Writing Assistance APIs — now available as developer previews in Edge Canary and Dev channels — give you access to a powerful small language model, Phi-4-mini, that is built into the Edge browser. Whether you're trying out prompt engineering, summarizing and modifying content, or generating text, these APIs are designed to help you bring AI to your web code with a few lines of JavaScript.
https://www.youtube.com/watch?v=FlXj9ZAtoAY
Introducing the Prompt API in Edge 138
We're excited to announce the availability of the Prompt API as a developer preview in Edge Canary and Dev channels, starting with Microsoft Edge 138. The Prompt API provides sites and extensions access to a built-in small language model via a simple API for prompt engineering. In its simplest form, prompting the built-in language model simply requires the following lines of client-side JavaScript code:const session = await LanguageModel.create(); // Prompt the model and wait for the result const result = await session.prompt("Score this feedback into a rating between 0-5: “The food was delicious, service was excellent. Would recommend!”");The Prompt API can be used to support a wide variety of use cases, ranging from text analysis and generation, to data classification and sentiment analysis, and can easily be integrated into your existing application code. We have also added the ability to constrain model outputs by adding structured outputs to the Prompt API. This makes it easier and more predictable to work with language models programmatically and minimizes the variance of API results across different models and browsers.
const schema = { type: "object", required: ["rating"], properties: { rating: { type: "number", minimum: 0, maximum: 5, }, }, }; // Prompt the model and wait for the JSON response to come back. const result = await session.prompt("Score this feedback into a rating between 0-5: " + "The food was delicious, service was excellent. Would recommend!", { responseConstraint: schema } ); const { rating } = JSON.parse(result);
Introducing the Writing Assistance APIs in Edge 138
We're also excited to announce the availability of the Summarizer, Writer, and Rewriter APIs as developer previews in Canary and Dev channels, starting with Microsoft Edge 138. These Writing Assistance APIs provide sites and extensions the ability to modify and generate text via simple interfaces that are scoped to the specific writing assistance task they serve. The Summarizer, Writer, and Rewriter APIs also use the built-in Phi-4-mini model in Edge but, unlike the Prompt API, are optimized to serve summarization, writing, and rewriting use-cases. A few lines of client-side JavaScript code can now help you generate or modify text in your web application:// Summarize an article with added context and desired style and length. const summarizer = await Summarizer.create({ sharedContext: "An article from the Daily Economic News magazine", type: "tl;dr", length: "short" }); const summary = await summarizer.summarize(articleEl.textContent, { context: "This article was written 2024-08-07 and is in the World Markets section." }); // Write a blurb based on the provided prompt and tone. const writer = await Writer.create({ tone: "formal" }); const result = await writer.write( "A draft for an inquiry to my bank about how to enable wire transfers on my account" ); // Rewrite a user review to remove problematic language while preserving intent. const rewriter = await Rewriter.create({ sharedContext: "A user review for shoes from Contoso Inc." }); const result = await rewriter.rewrite(reviewEl.textContent, { context: "Refine user feedback to remove harsh, profane, or negative language while preserving the core issue, ensuring clarity and professionalism." });