apyhub
DEVELOPER TOOLS

Differentiate Text API

Hosted on ApyHub

What it does

Text Diff Comparator compares two text or code snippets and returns an ordered diff, plus simple change counts. Send text1 and text2, and optionally set mode to char, word, or line depending on whether you're checking typos, prose, or multi-line code and config files.

Use word mode for sentences and paragraphs, line mode for source files, JSON, YAML, and other structured text, and char mode when small edits matter. The response includes the normalised mode used for comparison, a diffs array with equal, insert, and delete segments, and stats with additions, deletions, and unchanged counts.

This is useful for review workflows, content editors, code inspection tools, and any integration that needs to explain what changed between two versions without doing its own diffing. Because the diff segments are returned in order, you can render side-by-side comparisons, highlight edits inline, or compute summary metrics from the same response.

If you need a straightforward way to compare revisions and inspect the exact segments that differ, Text Diff Comparator gives you the result in a compact, machine-readable format.

POST
Compare two text or code snippets
http://localhost:8080/apyhub/compare-text-or-code-snippets
QUICKSTARTGUIDE

Quickstart

Compare two texts or code snippets by sending both inputs in a JSON body.

curl -X POST "http://localhost:8080/apyhub/compare-text-or-code-snippets" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "text1": "I love eating apples",
    "text2": "I love eating oranges"
  }'

What you'll get back

Returns a JSON object with a data object. data includes mode (the normalized comparison mode used), diffs (ordered diff segments with op and text), and stats with additions, deletions, and unchanged.

{
  "data": {
    "mode": "word",
    "diffs": [
      { "op": "equal", "text": "I love eating " },
      { "op": "delete", "text": "apples" },
      { "op": "insert", "text": "oranges" }
    ],
    "stats": {
      "additions": 1,
      "deletions": 1,
      "unchanged": 3
    }
  }
}
TRY ITLIVE · 40 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
Comparison granularity. `char` for typos / short strings, `word` for sentences and paragraphs (default), `line` for code, configs, and other multi-line content.
Original text or code snippet. Capped at 1 MiB.
New text or code snippet. Capped at 1 MiB.

About this endpoint

What it does

Compares two text or code snippets and returns a diff breakdown plus summary statistics. The comparison granularity is controlled by mode, which can be char, word, or line.

Request Body

ParameterTypeMandatoryDescription
modeENUMNoComparison granularity. Allowed values: char (for typos / short strings), word (for sentences and paragraphs, default), line (for code, configs, and other multi-line content). Default: word.
text1StringYesOriginal text or code snippet. Capped at 1 MiB.
text2StringYesNew text or code snippet. Capped at 1 MiB.

Response

Returns a JSON object with a data object field. data contains the normalized mode actually used to compute the diff, an ordered diffs array of diff segments, and a stats object with additions, deletions, and unchanged counts.

ParameterTypeMandatoryDescription
dataObjectNoDiff result wrapper containing mode, diffs, and stats.
data.modeENUMYesNormalised mode actually used to compute the diff. Allowed values: char, word, line.
data.diffsObject ArrayYesOrdered diff segments. Concatenating equal + delete recovers text1; concatenating equal + insert recovers text2. Each item has op and text.
data.diffs[].opENUMYesSegment type. Allowed values: equal (appears in both inputs), delete (exists only in text1), insert (exists only in text2).
data.diffs[].textStringYesVerbatim segment content in the chosen mode.
data.statsObjectYesSummary counts for the diff.
data.stats.additionsIntegerYesUnits inserted in text2 (counted in the chosen mode).
data.stats.deletionsIntegerYesUnits removed from text1 (counted in the chosen mode).
data.stats.unchangedIntegerYesUnits present in both inputs (counted in the chosen mode).

Body

Name
Type
Description
bodyREQUIRED
object
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.