How to compare two texts and get a diff with an API
Updated 2026-11-10
Use when an agent must show exactly what changed between two versions of a text.
From an MCP client, add https://tanod.dev/mcp and call diff_text; its free daily calls are applied automatically, no key or signup.
POST two texts, a (old) and b (new), to /v1/diff. It returns a similarity ratio, insert and delete counts and hunks. In line mode you also get a git-style unified diff.
Request
a and b are up to 100,000 characters each. mode is line (default), word or char; word and char modes accept up to 20,000 characters per side and return change records (equal, insert, delete, replace) with character offsets into a and b. context sets unchanged lines around each hunk, 0 to 10.
curl -s -X POST https://tanod.dev/v1/diff \
-H 'X-Tanod-Free: 1' -H 'content-type: application/json' \
-d '{"a": "one\ntwo\nthree\n", "b": "one\n2\nthree\nfour\n", "mode": "line"}'Response
{
"mode": "line",
"context": 3,
"similarity": 0.571429,
"identical": false,
"stats": {
"units": "lines",
"a_units": 3,
"b_units": 4,
"inserted": 2,
"deleted": 1,
"unchanged": 2
},
"truncated": false,
"hunks": [
{
"a_start": 1,
"a_lines": 3,
"b_start": 1,
"b_lines": 4
}
],
"unified": "--- a\n+++ b\n@@ -1,3 +1,4 @@\n one\n-two\n+2\n three\n+four\n",
"source": {
"library": "Python difflib",
"license": "PSF-2.0"
}
}Recipe: check a direct quote against its source
A news or research agent must confirm that each direct quote appears word for word in the page it cites. Three calls cover it:
- Fetch the source with
POST /v1/render({"url": "<source>"}). It returns the page as Markdown. Keep that copy with the story: if the quote stops matching later, a diff against the saved copy shows whether the source was rewritten. - Remove hidden characters from the quote and the page with
POST /v1/text/unicodeand"strip_invisible": true. Wire copy can carry U+2060 (word joiner) or U+200B (zero-width space) inside a quote, and these break a plain string match. The cleaned text is intext. Curly quotes and dashes are not changed by Unicode normalization, so straighten those in your own code (or with/v1/text/replace). - Compare the quote with the closest passage using
POST /v1/diffand"mode": "word".similaritygives a score, andhunkslist each change. A quote that differs only by a comma shows onedeleteof",", which you can mark for review rather than fail.
Example compare: {"a": "we will win, soon", "b": "we will win soon", "mode": "word"} returns similarity 0.933333 and one change, the deleted comma. The Unicode check and the diff share the utility free pool (10 calls a day per IP with the header X-Tanod-Free: 1); the render call has its own free daily allowance, shown on its page. After that, each call is paid.
Limits and caveats
At most 1,000 hunks and 5,000 change records are returned, then truncated is true. Input too complex for the resource limits is a 422 and not charged.
The diff comes from Python's difflib, which finds a good but not always minimal edit script. It can differ from git diff on repetitive text.
Tanod does not log or store the submitted text; it is processed in memory for the answer.
Doing this by hand? Use the free text diff checker in your browser.
Price and free allowance
USD 0.001 per call, paid in USDC on Base, Polygon, Solana, BNB Chain or Arbitrum with x402. 10 free calls per IP per UTC day with the header X-Tanod-Free: 1. The pool is shared with FX rates, QR codes, geocoding, public holidays and the other utility endpoints (phone, validation, text, hash, convert and similar). MCP tool: diff_text at https://tanod.dev/mcp, where the free tier is automatic.
Use it from Claude without writing code: in claude.ai or Claude Desktop, add https://tanod.dev/mcp/text?via=text-diff-api as a custom connector (steps), then ask in plain words, for example "Show exactly what changed between these two versions of the paragraph." The free daily allowance is applied automatically over MCP. Beyond it a call needs an x402 payment, which these clients can make.
Related guides: How to count words and score readability of a text with an API, How to validate JSON against a JSON Schema with an API, How to convert between JSON, YAML, CSV, TOML and XML with an API. Back to tanod.dev or the guide index. Results are automated and heuristic.