Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The availability() static method of the LanguageModel interface returns a status identifier indicating whether the browser's language model supports a given set of configuration options, without creating a session or triggering a download.
Use availability() before calling LanguageModel.create() to determine whether the desired configuration is supported. This avoids initiating a session only to have it fail, and lets you provide a meaningful fallback to users when the configuration is not supported.
LanguageModel.availability()
LanguageModel.availability(options)options OptionalAn object that represents the base set of options used when checking language model support. Properties include:
expectedInputs OptionalAn array of objects representing the required input modalities and languages. Each object can include the following properties:
typeAn enumerated value indicating the content type. Must be one of:
textPlain text content.
imageImage content.
audioAudio content.
tool-callA tool invocation issued by the model.
tool-responseThe result of a tool invocation.
languages OptionalAn array of strings containing BCP 47 language tags (for example, en, fr, ja) representing languages that the session is expected to handle. The user agent uses this list to determine whether the model supports the specified languages.
expectedOutputsAn array of objects representing the required output modalities and languages. Each object can include the following properties:
typeAn enumerated value indicating the content type. Must be one of:
textTextual content.
imageImage content.
audioAudio content.
tool-callA tool invocation issued by the model.
tool-responseThe result of a tool invocation.
languages OptionalAn array of strings containing BCP 47 language tags (for example, en, fr, ja) that the session is expected to output.
toolsAn array of objects representing tools available to the AI. Each object can include the following properties:
nameA string giving the tool a unique name the model uses to refer to it when issuing a tool call.
descriptionA string describing what the tool does. The model uses this description to decide when and whether to invoke the tool.
inputSchemaAn object containing a JSON Schema that describes the tool's input parameters. The model uses this schema to construct the arguments it passes to the tool's execute function.
executeA callback function that the user agent invokes when the model calls this tool. It can receive any arguments provided by the model as appropriate and returns a Promise that resolves with a String representing the tool's result.
A Promise that resolves with one of the values listed below.
availableThe model is ready to use with the given options.
downloadableThe model can support the given options but needs to download additional data to do so. The download has not yet started.
downloadingThe model can support the given options with an additional data download. The download is currently in progress.
The model cannot support the given options, or the user agent cannot determine availability, for example, due to a transient activation error. In that case, the caller should retry or fall back to an alternative implementation.
InvalidStateError DOMExceptionThrown if the calling document is not fully active.
NotAllowedError DOMExceptionThrown if usage of the method is blocked by a language-model Permissions-Policy.
See also Using the Prompt API > Checking configuration support and the Complete example on the same page.
This example shows how to determine whether text and image inputs are supported by the model.
const status = await LanguageModel.availability({
expectedInputs: [{ type: "text" }, { type: "image" }],
});This example tests whether the model supports English before asking it to translate Japanese text to English.
const status = await LanguageModel.availability({
expectedInputs: [{ type: "text", languages: ["ja"] }],
expectedOutputs: [{ type: "text", languages: ["en"] }],
});
if (status === "available") {
const session = await LanguageModel.create({
expectedInputs: [{ type: "text", languages: ["ja"] }],
expectedOutputs: [{ type: "text", languages: ["en"] }],
});
const translation = await session.prompt([
{
role: "user",
content: "Translate the following text into English",
},
{
role: "user",
content: "桜はきれいです",
},
]);
console.log(translation);
}Multimodal input describes sessions that can use more than one type of input, such as text and images. Since the availability of input types varies by language model, your code should check the availability of desired modes before creating a session. An example is shown here.
const availability = await LanguageModel.availability({
expectedInputs: [{ type: "text" }, { type: "image" }],
expectedOutputs: [{ type: "text", languages: ["en"] }],
});
if (availability === "unavailable") {
console.warn("This configuration is not supported.");
} else {
const session = await LanguageModel.create({
expectedInputs: [{ type: "text" }, { type: "image" }],
expectedOutputs: [{ type: "text", languages: ["en"] }],
});
}