The Writer API provides a high-level interface to call on the browser's built-in language model to generate net-new material given a writing task prompt, configuring tone, format, and length.

Developer Trial: This API is currently in active development. To use it locally, enable #writer-api-for-gemini-nano and #optimization-guide-on-device-model in chrome://flags. For production origins, register for the joint Writer/Rewriter origin trial (Chrome 137 to 148).

Writer.availability()

Checks if the browser currently supports creating a writer session with the provided configuration. Returns a Promise resolving to an Availability string ('available' | 'downloadable' | 'unavailable' | 'downloading').

static availability(options?: WriterCreateCoreOptions): Promise<Availability>;

Parameters (WriterCreateCoreOptions)

NameType / ValuesDescription
tone"formal" | "neutral" | "casual"The overall tone of the generated writing. Default is "neutral".
format"plain-text" | "markdown"Output format. Default is "markdown".
length"short" | "medium" | "long"The target length of the text. Default is "short".
expectedInputLanguagessequence<DOMString>BCP-47 language tags for the writing-task input.
expectedContextLanguagessequence<DOMString>BCP-47 language tags for the context strings.
outputLanguageDOMStringThe language to generate the text in.
Interactive Playground

Writer.create()

Creates and returns a new Writer instance. If the model is downloadable, calling this method initiates the network download — in that case the call must happen from a user gesture (it requires and consumes transient user activation) or it rejects with a NotAllowedError.

static create(options?: WriterCreateOptions): Promise<Writer>;

Parameters (WriterCreateOptions)

Inherits all properties from WriterCreateCoreOptions (above), plus:

NameTypeDescription
sharedContextDOMStringBackground context shared across all write calls made by this instance.
monitorCreateMonitorCallbackA function to track model weight downloads (emits downloadprogress events).
signalAbortSignalPass an AbortController.signal to cancel session creation and halt downloads.
Interactive Playground

writer.write()

Executes inference and returns a single Promise resolving to the complete generated text.

write(input: DOMString, options?: WriterWriteOptions): Promise<DOMString>;

Options Parameter (WriterWriteOptions)

NameTypeDescription
contextDOMStringContext specific to this individual writing request.
signalAbortSignalPass an AbortController.signal to cancel this specific operation.
Interactive Playground

writer.writeStreaming()

Identical parameters to write(), but returns a ReadableStream of string chunks as they are generated.

writeStreaming(input: DOMString, options?: WriterWriteOptions): ReadableStream;
Interactive Playground

writer.measureInputUsage()

Measures how much of the input quota the given input and context will consume (implementation-defined units, typically tokens). Returns a Promise resolving to a number.

measureInputUsage(input: DOMString, options?: WriterWriteOptions): Promise<double>;
Interactive Playground

writer.destroy()

Signals that the writer is no longer needed, allowing the browser to free the model resources. Any pending write() calls are rejected with an AbortError.

destroy(): undefined;
Interactive Playground

Properties

Read-only attributes representing the configuration of the current session.

  • readonly sharedContext: DOMString
  • readonly tone: WriterTone
  • readonly format: WriterFormat
  • readonly length: WriterLength
  • readonly expectedInputLanguages: FrozenArray<DOMString>?
  • readonly expectedContextLanguages: FrozenArray<DOMString>?
  • readonly outputLanguage: DOMString?
  • readonly inputQuota: unrestricted double - The maximum input usage this instance accepts (implementation-defined units; may be Infinity if unrestricted).
Interactive Playground