files/en-us/web/api/summarizer/availability_static/index.md
{{APIRef("Summarizer API")}}{{SeeCompatTable}}{{securecontext_header}}
The availability() static method of the {{domxref("Summarizer")}} interface returns an enumerated value that indicates whether the browser AI model supports (or will support) a given Summarizer configuration.
Summarizer.availability()
Summarizer.availability(options)
options {{optional_inline}}
Summarizer. Possible values include:
expectedInputLanguages
["en"].expectedContextLanguages
sharedContext passed to the Summarizer, or a context specified during a {{domxref("Summarizer.summarize", "summarize()")}} or {{domxref("Summarizer.summarizeStreaming", "summarizeStreaming()")}} call). Defaults to ["en"].format
markdown.length
short.outputLanguage
Summarizer. Defaults to en.type
Summarizer to generate. Defaults to key-points.A {{jsxref("Promise")}} that fulfills with an enumerated value indicating whether support is available (or will be available) for a given Summarizer configuration, or null if support could not be determined.
Possible values include:
available
downloadable
downloading
unavailable
NotAllowedError {{domxref("DOMException")}}
NotSupportedError {{domxref("DOMException")}}
context is not in language the Summarizer supports.UnknownError {{domxref("DOMException")}}
measureInputUsage() call failed for any other reason, or a reason the user agent did not wish to disclose.availability() usageasync function getSummarizer() {
const options = {
sharedContext: "This is a scientific article",
type: "key-points",
format: "markdown",
length: "medium",
};
const availability = await Summarizer.availability(options);
if (availability === "unavailable") {
// The Summarizer API isn't usable
return undefined;
} else if (availability === "available") {
// The Summarizer API can be used immediately
return Summarizer.create(options);
}
// The Summarizer API can be used after the model is downloaded
const summarizer = await Summarizer.create(options);
summarizer.addEventListener("downloadprogress", (e) => {
console.log(`Downloaded ${e.loaded * 100}%`);
});
return summarizer;
}
async function langSupport(lang) {
const availability = await Summarizer.availability({
expectedInputLanguages: [lang],
});
return availability;
}
langSupport("en-US");
langSupport("fr");
langSupport("zh-CN");
{{Specifications}}
{{Compat}}