# Text Diff API
> Compare two pieces of text and get a precise, structured diff. Choose line, word or character granularity for a full edit script (equal, inserted, deleted) with addition and deletion counts, get a compact inline word diff, or render a standard unified diff (patch) with configurable context lines and file labels — ready to feed into patch tooling or a code-review UI. Built on a Longest-Common-Subsequence algorithm for accurate, minimal diffs. Every endpoint works by GET or JSON POST and runs entirely server-side with no third-party upstream, so responses are instant and the service is always available. Ideal for code review and version tooling, CMS and document editors, change tracking, plagiarism highlighting and content audits.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/textdiff-api/..."
```

## Pricing
- **Free** (Free) — 500 calls/Mo, 1 req/s
- **Basic** ($2/Mo) — 20,000 calls/Mo, 5 req/s
- **Pro** ($6/Mo) — 150,000 calls/Mo, 15 req/s
- **Mega** ($15/Mo) — 1,000,000 calls/Mo, 40 req/s

## Endpoints

### Diff

#### `GET /v1/diff` — Structured diff (line/word/char)

**Parameters:**
- `a` (query, required, string) — First text (old) Example: `hello world`
- `b` (query, required, string) — Second text (new) Example: `hello brave world`
- `mode` (query, optional, string) — line | word | char (default line) Example: `word`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/textdiff-api/v1/diff?a=hello+world&b=hello+brave+world&mode=word"
```

**Response:**
```json
{
    "data": {
        "mode": "word",
        "stats": {
            "additions": 2,
            "deletions": 0,
            "unchanged": 3,
            "total_changes": 2
        },
        "changes": [
            {
                "op": "equal",
                "value": "hello"
            },
            {
                "op": "equal",
                "value": " "
            },
            {
                "op": "insert",
                "value": "brave"
            },
            {
                "op": "insert",
                "value": " "
            },
            {
                "op": "equal",
                "value": "world"
            }
        ],
        "identical": false
    },
    "meta": {
        "timestamp": "2026-05-30T18:17:09.679Z",
        "request_id": "f073249f-83f6-4191-9755-70f5db177ad5"
    },
    "status": "ok",
    "message": "OK",
    "success": true
}
```

#### `GET /v1/unified` — Unified diff (patch)

**Parameters:**
- `a` (query, required, string) — First text (old) Example: `line one\nline two\nline three`
- `b` (query, required, string) — Second text (new) Example: `line one\nline 2\nline three`
- `context` (query, optional, string) — Context lines (0-10, default 3) Example: `3`
- `a_name` (query, optional, string) — Label for the old file Example: `old.txt`
- `b_name` (query, optional, string) — Label for the new file Example: `new.txt`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/textdiff-api/v1/unified?a=line+one%5Cnline+two%5Cnline+three&b=line+one%5Cnline+2%5Cnline+three&context=3&a_name=old.txt&b_name=new.txt"
```

**Response:**
```json
{
    "data": {
        "hunks": 1,
        "patch": "--- old.txt\n+++ new.txt\n@@ -1,1 +1,1 @@\n-line one\\nline two\\nline three\n+line one\\nline 2\\nline three\n",
        "identical": false
    },
    "meta": {
        "timestamp": "2026-05-30T18:17:09.756Z",
        "request_id": "21f138bb-4932-4a59-8e35-703a90e66677"
    },
    "status": "ok",
    "message": "OK",
    "success": true
}
```

#### `GET /v1/words` — Inline word diff

**Parameters:**
- `a` (query, required, string) — First text Example: `the quick brown fox`
- `b` (query, required, string) — Second text Example: `the slow brown fox`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/textdiff-api/v1/words?a=the+quick+brown+fox&b=the+slow+brown+fox"
```

**Response:**
```json
{
    "data": {
        "stats": {
            "words_added": 1,
            "words_removed": 1
        },
        "segments": [
            {
                "op": "equal",
                "value": "the "
            },
            {
                "op": "delete",
                "value": "quick"
            },
            {
                "op": "insert",
                "value": "slow"
            },
            {
                "op": "equal",
                "value": " brown fox"
            }
        ],
        "identical": false
    },
    "meta": {
        "timestamp": "2026-05-30T18:17:09.831Z",
        "request_id": "2ffe312f-c2c6-4592-a674-25e706640eca"
    },
    "status": "ok",
    "message": "OK",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/textdiff-api
OpenAPI spec: https://www.oanor.com/api/textdiff-api/openapi.json
