Rewriter API

Published: May 20, 2025

Explainer Web Extensions Chrome Status Intent
GitHub Behind a flag Origin trial Behind a flag Origin trial View Intent to Experiment

The Rewriter API helps you revise and restructure text. This API and the Writer API are part of the Writing Assistance APIs proposal.

These APIs can help you improve content created by users.

Use cases

Refine existing text by making it longer or shorter, or changing the tone. For example, you could:

  • Rewrite a short email so that it sounds more polite and formal.
  • Suggest edits to customer reviews to help other customers understand the feedback or remove toxicity.
  • Format content to meet the expectations of certain audiences.

Is your use case missing? Join the early preview program to share your feedback.

Get started

Join the Rewriter API origin trial, running in Chrome 137 to 142.

Review the hardware requirements

The Language Detector and Translator APIs work on desktop only in Chrome.

The Prompt API, Summarizer API, Writer API, and Rewriter API work in Chrome when the following conditions are met:

  • Operating system: Windows 10 or 11; macOS 13+ (Ventura and onwards); or Linux. Chrome for Android, iOS, and ChromeOS are not yet supported by our APIs backed by Gemini Nano.
  • Storage: At least 22 GB on the volume that contains your Chrome profile.
  • GPU: Strictly more than 4 GB of VRAM.
  • Network: Unlimited data or an unmetered connection.
  • GPU: Strictly more than 4 GB of VRAM.
  • Network: Unlimited data or an unmetered connection.

These requirements exist for you in your development process and your users who work with the features you build.

Sign up for the origin trial

The Rewriter API is available in a joint origin trial with the Writer API. To start using these APIs:

  1. Acknowledge Google's Generative AI Prohibited Uses Policy.
  2. Go to the Rewriter API origin trial.
  3. Click Register and fill out the form. In the Web origin field, provide your origin or extension ID, chrome-extension://YOUR_EXTENSION_ID.
  4. To submit, click Register.
  5. Copy the token provided, and add it to every participating web page on your origin or include it in your Extension manifest.
  6. Start using the Rewriter API.

Learn more about how to get started with origin trials.

Add support to localhost

To access the Writer and Rewriter APIs on localhost during the origin trial, you must update Chrome to the latest version. Then, follow these steps:

  1. Go to chrome://flags/#rewriter-api-for-gemini-nano.
  2. Select Enabled.
  3. Click Relaunch or restart Chrome.

Use the Rewriter API

First, run feature detection to see if the browser supports these APIs.


if ('Rewriter' in self) {
  // The Rewriter API is supported.
}

The Rewriter API, and all other built-in AI APIs, are integrated in the browser. Gemini Nano is downloaded separately the first time any website uses a built-in AI API. In practice, if a user has already interacted with a built-in API, they have downloaded the model to their browser.

To determine if the model is ready to use, call the asynchronous Rewriter.availability() function. It returns a string that can take four possible values:

  • unavailable: The browser supports the Rewriter API, but it can't be used at the moment. This could be for a number of reasons, such as insufficient available disk space to download the model.
  • available: The browser supports the Rewriter API, and it can be used right away.
  • downloadable: The browser supports the Rewriter API, but it needs to download the model first.
  • downloading: The browser supports the Rewriter API, and is currently downloading the model.

To trigger model download and start the rewriter, call the Rewriter.create() function. If the response to availability() was downloadable, listen for download progress and inform the user, as the download may take time.

const rewriter = await Rewriter.create({
  monitor(m) {
    m.addEventListener("downloadprogress", e => {
      console.log(`Downloaded ${e.loaded * 100}%`);
    });
  }
});

API functions

The create() function lets you configure a new rewriter object. It takes an optional options object with the following parameters:

  • tone: Writing tone can refer to the style, character, or attitude of the content. The value can be set to more-formal, as-is (default), or more-casual.
  • format: The output formatting, with the allowed values as-is (default), markdown, and plain-text.
  • length: The length of the output, with the allowed values shorter, as-is (default), and longer.
  • sharedContext: When rewriting multiple pieces of content, a shared context can help the model create content better aligned with your expectations.

The following example demonstrates how to initiate a rewriter object:

const options = {
  sharedContext: 'This is an email to acquaintances about an upcoming event.',
  tone: 'more-casual',
  format: 'plain-text',
  length: 'shorter',
};

const available = await Rewriter.availability();
let rewriter;
if (available === 'unavailable') {
  // The Rewriter API isn't usable.
  return;
}
if (available === 'available') {
  // The Rewriter API can be used immediately .
  rewriter = await Rewriter.create(options);
} else {
  // The Rewriter can be used after the model is downloaded.
  rewriter = await Rewriter.create(options);
  rewriter.addEventListener('downloadprogress', (e) => {
    console.log(e.loaded, e.total);
  });
}

Start rewriting

There are two ways to output content from the model: non-streaming and streaming.

Non-streaming output

With non-streaming rewriting, the model processes the input as a whole and then produces the output.

To get a non-streaming output, call the asynchronous rewrite() function. You must include the initial text that you want to be rewritten. You can add an optional context to provide the model background information, which may help the model better meet your expectations for the output.

// Non-streaming
const rewriter = await Rewriter.create(
  sharedContext: "A review for the Flux Capacitor 3000 from TimeMachines Inc."
);
const result = await rewriter.rewrite(reviewEl.textContent, {
  context: "Avoid any toxic language and be as constructive as possible."
});

Stream rewriting output

Streaming offers results in real-time. The output updates continuously as the input is added and adjusted.

To get a streaming rewriter, call the rewriteStreaming() function and iterate over the available segments of text in the stream. You can add an optional context to provide the model background information, which may help the model better meet your expectations for the output.

const rewriter = await Rewriter.create({
  sharedContext: "A review for the Flux Capacitor 3000 from TimeMachines Inc."
});

const stream = rewriter.rewriteStreaming(reviewEl.textContent, {
  context: "Avoid any toxic language and be as constructive as possible.",
  tone: "more-casual",
});

for await (const chunk of stream) {
  composeTextbox.append(chunk);
}

Share context for multiple tasks

You may want to use a rewriter to generate multiple pieces of content. In this case, it's useful to add sharedContext. For example, you may want to help reviewers give better feedback in comments.

// Shared context and per writing task context
const rewriter = await Rewriter.create({
  sharedContext: "This is for publishing on [popular website name], a business and employment-focused social media platform."
});

const stream = rewriter.rewriteStreaming(
  "Love all this work on generative AI at Google! So much to learn and so many new things I can do!",
  {
    context: "The request comes from someone working at a startup providing an e-commerce CMS solution.",
    tone: "more-casual",
  }
);

for await (const chunk of stream) {
  composeTextbox.append(chunk);
}

Reuse a rewriter

You can use the same rewriter to edit multiple pieces of content. This may be particularly useful if adding the rewriter to a feedback or commenting tool, to help writers offer productive and helpful feedback.

// Reusing a rewriter
const rewriter = await Rewriter.create({
  sharedContext: "A review for the Flux Capacitor 3000 from TimeMachines Inc."
});

const rewrittenReviews = await Promise.all(
  Array.from(
    document.querySelectorAll("#reviews > .review"),
    (reviewEl) => rewriter.rewrite(reviewEl.textContent, {
      context: "Avoid any toxic language and be as constructive as possible.",
      tone: "more-casual",
    })
  ),
);

Stop the rewriter

To end the rewriting process, abort the controller and destroy the rewriter.

// Stop a rewriter
const controller = new AbortController();
stopButton.onclick = () => controller.abort();

const rewriter = await Rewriter.create({ signal: controller.signal });
await rewriter.rewrite(reviewEl.textContent, { signal: controller.signal });

// Destroy a rewriter
rewriter.destroy();

Demo

Engage and share feedback

The Writer and Rewriter APIs are under active discussion and subject to change in the future. If you try this API and have feedback, we'd love to hear it.

Discover all of the built-in AI APIs which use models, including Gemini Nano and other expert models, in the browser.