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
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| mode | ENUM | No | Comparison 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. |
| text1 | String | Yes | Original text or code snippet. Capped at 1 MiB. |
| text2 | String | Yes | New 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.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| data | Object | No | Diff result wrapper containing mode, diffs, and stats. |
| data.mode | ENUM | Yes | Normalised mode actually used to compute the diff. Allowed values: char, word, line. |
| data.diffs | Object Array | Yes | Ordered diff segments. Concatenating equal + delete recovers text1; concatenating equal + insert recovers text2. Each item has op and text. |
| data.diffs[].op | ENUM | Yes | Segment type. Allowed values: equal (appears in both inputs), delete (exists only in text1), insert (exists only in text2). |
| data.diffs[].text | String | Yes | Verbatim segment content in the chosen mode. |
| data.stats | Object | Yes | Summary counts for the diff. |
| data.stats.additions | Integer | Yes | Units inserted in text2 (counted in the chosen mode). |
| data.stats.deletions | Integer | Yes | Units removed from text1 (counted in the chosen mode). |
| data.stats.unchanged | Integer | Yes | Units present in both inputs (counted in the chosen mode). |