Last updated: March 24, 2026
Aborting operations is important. Both the create and inference methods accept an AbortSignal (obtained from an AbortController) via their signal option.
const abortController = new AbortController();
// Passing Abort to create
const session = await *.create({
signal: abortController.signal,
})
// Passing Abort to "inference" methods (options are the second argument, after the input)
session.*(input, {
signal: abortController.signal,
})
// To abort
abortController.abort();create method when doing inference will abort it as well and destroy the session. If you only want to abort the inference, you need to pass a specific abortController to the “inference” methods. const abortController = new AbortController();
// Passing Abort to create
const session = await *.create({
signal: abortController.signal,
})
const sessionAbortController = new AbortController();
// Passing Abort to "inference" methods (options are the second argument, after the input)
session.*(input, {
signal: sessionAbortController.signal,
})
// Will abort both and destroy the session
abortController.abort();
// Will only abort the "inference"
sessionAbortController.abort(); Start generating text, then click "Stop Generation" before it finishes to see the AbortController instantly halt the inference stream.