docs.rodeo

MDN Web Docs mirror

Summarizer API

{{SeeCompatTable}} {{DefaultAPISidebar("Summarizer API")}} 

The Summarizer API summarizes a given body of text via a browser’s internal AI model (which may differ between browsers).

Concepts and usage

Writing a summary of a larger body of text is a common writing task, and one that AI is well-suited to. Typical use cases include:

The Summarizer API provides an asynchronous ({{jsxref("Promise")}} -based) mechanism for a website to feed a body of text into the browser’s own internal AI model and request that it returns a summary of the text based on specified options.

This is done using the functionality made available by the {{domxref("Summarizer")}}  interface, in a two-step process:

  1. Create a Summarizer object instance using the {{domxref("Summarizer.create_static", "Summarizer.create()")}}  static method, specifying options for what kind of summary you want written. Options include length, type (for example, “tldr” or key points), format (plain text or markdown), and input and output languages.

    [!NOTE] If you want to check whether the browser AI model is able to support your preferences, you can do so with the {{domxref("Summarizer.availability_static", "Summarizer.availability()")}}  static method.

  2. Run the {{domxref("Summarizer.summarize()")}}  instance method to request the summary.

You can cancel a pending create() or summarize() operation using an {{domxref("AbortController")}} .

After a Summarizer instance has been created, you can release its assigned resources and stop any further activity by calling its {{domxref("Summarizer.destroy()")}}  method. You are encouraged to do this after you’ve finished with the Summarizer object as it can consume a lot of resources.

See Using the Summarizer API for a walkthrough of how the API works.

Interfaces

HTTP headers

Security considerations

The specification requires that a user has recently interacted with the page when creating Summarizer objects (transient user activation is required).

In addition, the specification controls access to the API via {{httpheader('Permissions-Policy/summarizer','summarizer')}}  {{httpheader("Permissions-Policy")}}  directives.

Examples

For a full example, see Using the Summarizer API.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN