---
title: "Rewrite"
method: POST
path: "/v2/rewrite/"
tags: ["rewrite"]
---

# Rewrite

`POST /v2/rewrite/`

## Request

- Base URL: `https://api.mentium.io` (the document declares no server; this is the origin it was published from)
- URL: `https://api.mentium.io/v2/rewrite/`
- Auth: HTTP bearer

Rewrite selected text within the context of a full text.

This endpoint is designed to work with Tiptap's AI Changes extension:
1. User selects text in the editor
2. Editor calls this API with selected text + full text context
3. API returns rewritten text
4. Tiptap tracks changes and allows accept/reject workflow

The rewriting considers the full text context to maintain consistency and coherence with the surrounding content.

## Headers

- `mentium-workspace-id` string, nullable

## Request body

- RewriteRequest: Request model for text rewriting in Tiptap editor with AI Changes tracking.
  - `full_text_with_embedded_selection` string, required: The full text with embedded selection
  - `rewrite_instructions_for_selection` string, required: The rewrite instructions for the selection

## Response `200`

Successful Response

- RewriteResponse: Response model for text rewriting compatible with Tiptap AI Changes.
  - `rewritten_selection` string, required: The rewritten selection

## Other responses

- `404`: Not found
- `422`: Validation Error

---

[API](https://skmtc.dev/mentium/apis/mentium-api.md) - [All operations](https://skmtc.dev/mentium/apis/mentium-api/llms.txt) - [OpenAPI document](https://skmtc.dev/mentium/apis/mentium-api/revisions/b4ed8e59432e?raw)
