The Rewriter API provides a high-level interface to call on the browser's built-in language model to transform, rephrase, expand, or adjust the tone and format of existing text inputs.

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

Rewriter.availability()

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

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

Parameters (RewriterCreateCoreOptions)

NameType / ValuesDescription
tone"as-is" | "more-formal" | "more-casual"The directional tone of the rewritten text. Default is "as-is".
format"as-is" | "plain-text" | "markdown"Output format. Default is "as-is".
length"as-is" | "shorter" | "longer"The target length of the text relative to the input. Default is "as-is".
expectedInputLanguagessequence<DOMString>BCP-47 language tags for the input text you intend to rewrite.
expectedContextLanguagessequence<DOMString>BCP-47 language tags for the context strings.
outputLanguageDOMStringThe language to output the rewritten text in.
Interactive Playground

Rewriter.create()

Creates and returns a new Rewriter 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?: RewriterCreateOptions): Promise<Rewriter>;

Parameters (RewriterCreateOptions)

Inherits all properties from RewriterCreateCoreOptions (above), plus:

NameTypeDescription
sharedContextDOMStringBackground context shared across all rewrite 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

rewriter.rewrite()

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

rewrite(input: DOMString, options?: RewriterRewriteOptions): Promise<DOMString>;

Options Parameter (RewriterRewriteOptions)

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

rewriter.rewriteStreaming()

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

rewriteStreaming(input: DOMString, options?: RewriterRewriteOptions): ReadableStream;
Interactive Playground

rewriter.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?: RewriterRewriteOptions): Promise<double>;
Interactive Playground

rewriter.destroy()

Signals that the rewriter is no longer needed, allowing the browser to free the model resources. Any pending rewrite() 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: RewriterTone
  • readonly format: RewriterFormat
  • readonly length: RewriterLength
  • 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