Summarizer
Summarizer API
Summarizer API
The **`Summarizer`** interface of the Summarizer API contains all the functionality for this API, including checking AI model availability, creating a new `Summarizer` instance, using it to generate a new summary, and more.
## Instance properties
- expectedContextLanguages
- : The languages the context strings should be written in.
- expectedInputLanguages
- : The languages the `Summarizer` should support.
- format
- : The text format summaries will be returned in.
- inputQuota
- : The input quota available to the browser for generating summaries.
- length
- : The relative length of the generated summaries.
- outputLanguage
- : The language the summary should be generated in.
- sharedContext
- : A text string describing the context the pieces of text to summarize are being used in, which helps the `Summarizer` generate more suitable summaries.
- type
- : The type of summary that will be generated by the `Summarizer`.
## Static methods
- availability()
- : Returns an enumerated value that indicates whether the browser AI model supports a given `Summarizer` configuration.
- create()
- : Creates a new `Summarizer` instance from which to generate summaries.
## Instance methods
- destroy()
- : Releases the resources assigned to the `Summarizer` instance it is called on and stops any further activity on it.
- measureInputUsage()
- : Reports how much input quota would be used by a summarize operation for a given text input.
- summarize()
- : Generates a new summary string.
- summarizeStreaming()
- : Generates a new summary as a ReadableStream.
## Examples
See [Using the Summarizer API](/docs/Web/API/Summarizer_API/Using) for a complete example.
### Creating a `Summarizer` instance
```js
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
format: "markdown",
expectedInputLanguages: ["en-US"],
outputLanguage: "en-US",
});
```
### Generating a summary
```js
const summary = await summarizer.summarize(myTextString);
console.log(summary);
```
### Generating a summary stream
```js
const stream = summarizer.summarizeStreaming(myTextString);
let summary = "";
for await (const chunk of stream) {
summary += chunk;
}
console.log("Stream complete");
summaryOutput.textContent = summary;
```
## Specifications
## Browser compatibility
## See also
- [Using the Summarizer API](/docs/Web/API/Summarizer_API/Using)
- [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev
Cite this
"Summarizer". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Summarizer JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy