MDN self-hosted library · e01.org

LanguageModel: destroy() method

Prompt API

Prompt API

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

  • NotAllowedError DOMException
  • : Thrown if usage of the method is blocked by a language-model Permissions-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 > Canceling operations and destroying instances.

Specifications

Browser compatibility

See also