LanguageModel: destroy() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The destroy() method of the LanguageModel interface releases the resources assigned to the LanguageModel instance it is called on and stops any further activity on it. Any ongoing and subsequent method calls made on the LanguageModel will reject with an AbortError.
It makes sense to destroy LanguageModel objects if they are no longer being used, as they tie up significant resources in their handling.
Syntax
destroy()
Parameters
None.
Return value
None (undefined).
Exceptions
NotAllowedErrorDOMException-
Thrown if usage of the method is blocked by a
language-modelPermissions-Policy.
Examples
>Basic destroy() usage
const session = await LanguageModel.create({
expectedInputs: [{ type: "text", languages: ["en"] }],
expectedOutputs: [{ type: "text", languages: ["en"] }],
});
// ...
session.destroy();
See also Using the Prompt API > Cancelling operations and destroying instances.
Specifications
| Specification |
|---|
| Writing Assistance APIs> # dom-destroyablemodel-destroy> |