> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenrip.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Diff Version

> GET /v0/artifacts/{publicId}/versions/{vid}/diff — Diff a version against the previous version

Retrieve the difference between a version and the version immediately before it. Text artifacts (`markdown`, `html`, `code`, `text`, `json`) return a word-level diff; `csv` artifacts return a row-level diff. This endpoint is publicly accessible — no authentication required.

The diff is computed on first request and cached, so repeat calls are fast. A diff is always a version against its immediate predecessor — there is no arbitrary version-pair comparison.

## Path Parameters

| Parameter  | Type   | Required | Description                                    |
| ---------- | ------ | -------- | ---------------------------------------------- |
| `publicId` | string | Yes      | The public ID of the artifact                  |
| `vid`      | string | Yes      | The version ID to diff against its predecessor |

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.tokenrip.com/v0/artifacts/ast_abc123/versions/vid_9kLmN3pQ/diff
  ```
</CodeGroup>

## Example Response

```json theme={null}
{
  "ok": true,
  "data": {
    "versionId": "vid_9kLmN3pQ",
    "baseVersionId": "vid_7hGfD2sR",
    "baseVersion": 2,
    "payload": {
      "strategy": "text",
      "segments": [
        { "op": "equal", "value": "The quick " },
        { "op": "delete", "value": "brown" },
        { "op": "insert", "value": "red" },
        { "op": "equal", "value": " fox" }
      ],
      "stats": { "added": 1, "removed": 1 }
    }
  }
}
```

## Response Fields

| Field           | Type            | Description                                                                                  |
| --------------- | --------------- | -------------------------------------------------------------------------------------------- |
| `versionId`     | string          | The version that was diffed                                                                  |
| `baseVersionId` | string \| null  | The previous version it was compared against. `null` for the earliest version.               |
| `baseVersion`   | integer \| null | The sequential number of the previous version                                                |
| `payload`       | object \| null  | The diff. `null` for the earliest version or a non-diffable type (`chart`, `file`, `table`). |

### Text payload (`strategy: "text"`)

| Field           | Type    | Description                                                               |
| --------------- | ------- | ------------------------------------------------------------------------- |
| `segments`      | array   | Ordered runs of text, each with an `op` of `equal`, `insert`, or `delete` |
| `stats.added`   | integer | Number of inserted words                                                  |
| `stats.removed` | integer | Number of removed words                                                   |

### Rows payload (`strategy: "rows"`)

| Field           | Type    | Description                                                           |
| --------------- | ------- | --------------------------------------------------------------------- |
| `rows`          | array   | Ordered CSV rows, each with an `op` of `equal`, `insert`, or `delete` |
| `stats.added`   | integer | Number of inserted rows                                               |
| `stats.removed` | integer | Number of removed rows                                                |

## Error Codes

| Error       | Description                                                                                              |
| ----------- | -------------------------------------------------------------------------------------------------------- |
| `NOT_FOUND` | No artifact exists with the given `publicId`, or no version exists with the given `vid` on this artifact |
