🔀

Text Diff

Get a structured word-level or line-level diff between two texts

POST 1 credit /v1/text/diff
curl -X POST "https://textanalysis.toolkitapi.io/v1/text/diff" \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"original": "The cat sat on the mat.", "revised": "The cat sat on the rug.", "mode": "word"}'
import httpx

resp = httpx.post(
    "https://textanalysis.toolkitapi.io/v1/text/diff",
    json={"original": "The cat sat on the mat.", "revised": "The cat sat on the rug.", "mode": "word"},
)
print(resp.json())
const resp = await fetch("https://textanalysis.toolkitapi.io/v1/text/diff", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"original": "The cat sat on the mat.", "revised": "The cat sat on the rug.", "mode": "word"}),
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "mode": "word",
  "diff": [
    {"type": "equal",  "text": "The cat sat on the "},
    {"type": "delete", "text": "mat"},
    {"type": "insert", "text": "rug"},
    {"type": "equal",  "text": "."}
  ],
  "insertions": 1,
  "deletions": 1
}

Try It Live

Live Demo

Description

Get a structured word-level or line-level diff between two texts

How to Use

1

1. Send a POST request to `/v1/text/diff` with `original` and `revised` as the two texts. 2. Set `mode` to `word` (default) or `line`. 3. Iterate over the `diff` array; render `delete` segments in red and `insert` segments in green. 4. Use `insertions` and `deletions` counts for summary statistics.

About This Tool

The Text Diff endpoint compares two texts and returns a structured list of changes — additions, deletions, and unchanged sections — at word or line granularity.

Each segment in the response has a `type` field (`equal`, `insert`, `delete`) and the corresponding `text`, making it trivial to render coloured diffs in any UI framework.

Why Use This Tool

Start using Text Diff now

Get your free API key and make your first request in under a minute.