
Difference Viewer API
Development
Free diff checker to compare code, text, or config files. Visualize changes in split or unified views.
Authentication
All API requests require a valid API key passed in the Authorization header as a Bearer token.
Rate Limit
120 requests per minute
Endpoints
1 endpoint available
Overview
Compare two texts line by line. The response has a git-style unified diff, the same changes as structured hunks, and counts of added and removed lines.
Notes
- Each text can be up to 200,000 characters. If the texts differ by more than 5000 lines the API returns 400 instead of a diff.
- Each hunk has a
headerlike@@ -1,3 +1,4 @@, the line ranges, andlines, an ordered list of{ type, text }wheretypeiscontext,addorremove. - A missing final newline is ignored: both texts are compared as if they ended with one.
languageonly sets the file extension in the diff header (a/original.js). It does not change the comparison.contextis the number of unchanged lines shown around each change, 0 to 20.- If the texts are identical,
identicalis true andhunksis empty.
Endpoints
POST
https://opentools.ca/api/v1/tools/difference-viewerCompare two texts and get a unified diff
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| original | string | Required | The original text, up to 200,000 characters. May be empty. |
| modified | string | Required | The changed text, up to 200,000 characters. May be empty. |
| language | string Enum: javascript, css, html, markdown, text | Optional | Sets the file extension in the diff header.Default: text |
| context | number | Optional | Unchanged lines to include around each change, 0 to 20.Default: 3 |
Response Example
{
"success": true,
"identical": false,
"additions": 2,
"deletions": 1,
"hunks": [
{
"header": "@@ -1,3 +1,4 @@",
"oldStart": 1,
"oldLines": 3,
"newStart": 1,
"newLines": 4,
"lines": [
{
"type": "context",
"text": "a"
},
{
"type": "remove",
"text": "b"
},
{
"type": "add",
"text": "B"
},
{
"type": "context",
"text": "c"
},
{
"type": "add",
"text": "d"
}
]
}
],
"unifiedDiff": "diff --git a/original.js b/modified.js\n--- a/original.js\t\n+++ b/modified.js\t\n@@ -1,3 +1,4 @@\n a\n-b\n+B\n c\n+d\n"
}Error Codes
400
Bad Request - Missing or oversized text, invalid option, or texts that differ by too many lines to compare401
Unauthorized - Invalid or missing API key403
Forbidden - API key inactive, expired, or request from a disallowed IP429
Too Many Requests - Rate limit exceeded500
Internal Server ErrorCode Examples
curl -X POST https://opentools.ca/api/v1/tools/difference-viewer \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"original": "a\nb\nc", "modified": "a\nB\nc\nd", "language": "javascript"}'Rather use it in your browser? Open the Difference Viewer