---
title: "Rewrite a selection"
description: "Rewrites text from a page you can edit: improves, shortens or fixes it, changes its tone, translates it, or turns it into a checklist, a table or an…"
canonical_url: https://docs.markdrop.in/api/page-ai/rewrite-a-selection
last_updated: 2026-11-04
site: "Markdrop Docs"
index: https://docs.markdrop.in/llms.txt
---

# Rewrite a selection

`POST https://api.markdrop.in/api/v1/ai/pages/{slug}/transform`

Rewrites text from a page you can edit: improves, shortens or fixes it, changes its tone, translates it, or turns it into a checklist, a table or an explanation. Streams the result as server-sent events: `delta` events with text as it's written, then `done` (or `limit` when a limit stops it). Nothing changes on the page: the result is a suggestion.

- **Authentication:** API token required: `Authorization: Bearer mdk_…`.
- **Rate limit:** 60 per minute per IP address.
- **Guide:** [AI in pages](https://docs.markdrop.in/pages/ai)

## Path parameters

- `slug` (string, required): The document's address: the part after `markdrop.in/`.

## Headers

- `X-Edit-Secret` (string): The document's edit secret (`sk_…`), for a document published without an account. See [Edit key](https://docs.markdrop.in/documents/edit-key).

## Request body

`application/json`, required.

- `action` (string, required): `improve`, `shorten`, `fix`, `tone`, `translate`, `checklist`, `table` or `explain`. Up to 20 characters.
- `text` (string, required): The selected text. Up to 14,000 characters.
- `tone` (string): For `tone`: `professional`, `friendly` or `concise`. Up to 20 characters.
- `lang` (string): For `translate`: the language, in English, like `Spanish`. Up to 40 characters.
- `before` (string): Text just before the selection, for context. Up to 2,000 characters.
- `after` (string): Text just after the selection, for context. Up to 2,000 characters.

## Responses

- `200`: OK.
- `401`: No token, or the token is revoked or mistyped.
- `422`: The request didn't validate. `detail` lists each problem, with where it is (`loc`) and why (`msg`).
- `429`: Too many requests from your IP address. Wait the seconds in `Retry-After`.

## Examples

**curl**

```bash
curl -X POST https://api.markdrop.in/api/v1/ai/pages/k3x9q2m/transform \
  -H "Authorization: Bearer $MARKDROP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "action": "shorten",
       "text": "We are going to be shipping the new release at some point next week."
     }'
```

**JavaScript**

```javascript
const res = await fetch("https://api.markdrop.in/api/v1/ai/pages/k3x9q2m/transform", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MARKDROP_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "action": "shorten",
    "text": "We are going to be shipping the new release at some point next week."
  }),
});
const data = await res.text();
```

**Python**

```python
import os

import requests

r = requests.post(
    "https://api.markdrop.in/api/v1/ai/pages/k3x9q2m/transform",
    headers={"Authorization": f"Bearer {os.environ['MARKDROP_TOKEN']}"},
    json={
        "action": "shorten",
        "text": "We are going to be shipping the new release at some point next week.",
    },
)
r.raise_for_status()
print(r.text)
```
