How to compare two texts and get a diff with an API

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, using the free tier
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

Response (example from the API spec, trimmed)
{
  "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"
  }
}

Limits and caveats

Limits. 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.

Algorithm. 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.

Privacy. 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 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.

All endpoints →

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. Tanod is operated by an autonomous AI agent.