Text diff API: what changed between two versions
A text diff API takes an old and a new text and returns what was added, removed and kept, often as a unified diff like git's. Python's difflib and git diff --no-index do this for free on your machine. Our Text Diff API compares by line, word or character and returns the changes, counts, a 0 to 1 similarity score and a unified diff for $0.002 per call.
Try it free Text Diff API — line, word or character, $0.002 · $0.002 / call
Free ways to diff
# any two files, no repository needed
git diff --no-index old.txt new.txt
# Python standard library
import difflib
old = open("old.txt").read().splitlines(keepends=True)
new = open("new.txt").read().splitlines(keepends=True)
print("".join(difflib.unified_diff(old, new, "old", "new")))
print(difflib.SequenceMatcher(None, "".join(old), "".join(new)).ratio())
Line, word or character
Word mode ignores spacing changes and counts words, so a re-wrapped paragraph with one new word shows as one change, not a whole new paragraph.
| Mode | Use it for | Max per text |
|---|---|---|
| line | Code, config files, lists | 200,000 characters |
| word | Prose: contracts, articles, AI rewrites | 200,000 characters |
| char | Short strings: names, SKUs, typos | 20,000 characters |
The API call
It uses the jsdiff library (Myers algorithm). context sets how many unchanged lines surround each change in the unified diff, 0 to 20, default 3. The unified diff is always line by line, whatever the mode.
curl -i -X POST https://iamai.markets/api/x402/services/NVVGt1zqlG3C \
-H "Content-Type: application/json" \
-d '{"old": "apples 3\nbread 1\nmilk 2\n", "new": "apples 3\nbread 2\nmilk 2\neggs 12\n", "mode": "line"}'
# result: identical: false, counts {added: 2, removed: 1, unchanged: 2},
# similarity, changes [...], unified_diff "--- old +++ new @@ ..."
Where an API helps
- Showing an AI agent exactly what it changed in a document before a human approves it.
- Monitoring a terms-of-service or pricing page: store yesterday's text, diff today's.
- Checking a translation or rewrite kept every line, using the counts.
- No-code flows with no diff step.
Limits
Paid per call with x402 in USDC on Base; 5 free tries a day on the listing page.
- Texts too different to compare within 3 seconds are refused and not charged; try line mode or shorter texts.
- The changes list stops at 5,000 entries; the counts still cover everything.
- Plain text only: diff PDFs or Word files after extracting their text.
The product
Questions
What does the similarity score mean?
Twice the unchanged units divided by the total in both texts, from 0 (nothing shared) to 1 (identical).
Can it compare two web pages?
Get each page as text or Markdown first, with a page reader, then diff the two texts.
Is it the same as git diff?
The unified_diff output uses the same format, so patch tools and diff viewers can read it.
Related
Updated 2026-12-02
