Difference Viewer

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 header like @@ -1,3 +1,4 @@, the line ranges, and lines, an ordered list of { type, text } where type is context, add or remove.
  • A missing final newline is ignored: both texts are compared as if they ended with one.
  • language only sets the file extension in the diff header (a/original.js). It does not change the comparison.
  • context is the number of unchanged lines shown around each change, 0 to 20.
  • If the texts are identical, identical is true and hunks is empty.

Endpoints

POST
https://opentools.ca/api/v1/tools/difference-viewer
Compare two texts and get a unified diff

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
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
OptionalSets the file extension in the diff header.Default: text
context
number
OptionalUnchanged 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 compare
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key inactive, expired, or request from a disallowed IP
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code 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"}'

Ready to get started?

Create an API key to start using the Difference Viewer API.

Rather use it in your browser? Open the Difference Viewer