Logo
Comparison

Content Comparison

Overview

The Content Comparison endpoint compares documents side-by-side with intelligent difference detection. It analyzes two documents and generates visual HTML diff report highlighting additions, deletions, and changes between them.

Use this endpoint to:

  • Compare document versions side-by-side
  • Identify text additions, deletions, and modifications
  • Generate visual diff reports with color-coded changes
  • Track document revisions and edits
  • Build document change tracking workflows

Endpoint Details

Method: POST
Endpoint: /api/agent/content_comparison
Base URL: https://api.k-v.ai
Authentication: Access Key (Required)


Request Specification

Headers

HeaderTypeRequiredDescription
access-keystringYesYour unique access-key generated from the platform UI
Content-TypestringYesMust be application/json

Request Body

{
    "doc_1_process_id": "3b5337f9edb4a828ed580b75f9cc1952",
    "doc_2_process_id": "264dfa262b748d15ccbeaada89430c68"
}

Body Fields

FieldTypeRequiredDescription
doc_1_process_idstringYesFirst document ID to compare (obtained from Upload or List Documents APIs)
doc_2_process_idstringYesSecond document ID to compare (obtained from Upload or List Documents APIs)

Response Specification

Success Response (200 OK)

{
    "data": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n          \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html>\n<head>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n    <title></title>\n    <style type=\"text/css\">\n        table.diff {font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace; border:medium}\n        .diff_header {background-color:#e0e0e0}\n        td.diff_header {text-align:right}\n        .diff_next {background-color:#c0c0c0}\n        .diff_add {background-color:#aaffaa}\n        .diff_chg {background-color:#ffff77}\n        .diff_sub {background-color:#ffaaaa}\n    </style>\n</head>\n<body>\n    <table class=\"diff\">\n        ...\n    </table>\n</body>\n</html>",
    "message": "Content compared successfully"
}

Response Fields

FieldTypeDescription
datastringComplete HTML document containing the visual diff comparison
messagestringHuman-readable response message

HTML Diff Output

The returned HTML includes:

Visual Elements:

  • Green highlighting (.diff_add) - Text added in document 2
  • Yellow highlighting (.diff_chg) - Text changed between documents
  • Red highlighting (.diff_sub) - Text deleted from document 1

Structure:

  • Side-by-side comparison table
  • Line numbers for both documents
  • Navigation links to jump between changes
  • Color-coded legend explaining the diff markers

Error Responses

401 Unauthorized

{
    "data": {},
    "message": "Invalid or missing access key"
}

Cause: Missing or invalid access-key header.


400 Bad Request - Invalid Document IDs

{
    "data": {},
    "message": "Invalid docs selected"
}

Causes:

  • Missing or invalid doc_1_process_id or doc_2_process_id
  • Documents don't exist in your account
  • Documents are not yet processed (status is not processed)

500 Internal Server Error - General Error

{
    "data": {},
    "message": "Something went wrong"
}

Causes:

  • Server-side processing error
  • Documents cannot be parsed for content comparison

Code Snippets

curl --location 'https://api.k-v.ai/api/agent/content_comparison' \
--header 'access-key: YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "doc_1_process_id": "3b5337f9edb4a828ed580b75f9cc1952",
    "doc_2_process_id": "264dfa262b748d15ccbeaada89430c68"
}'
import requests
import json

url = "https://api.k-v.ai/api/agent/content_comparison"

payload = json.dumps({
    "doc_1_process_id": "3b5337f9edb4a828ed580b75f9cc1952",
    "doc_2_process_id": "264dfa262b748d15ccbeaada89430c68"
})

headers = {
    'access-key': 'YOUR_ACCESS_KEY',
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)

print(response.text)
const axios = require('axios');

let data = JSON.stringify({
    "doc_1_process_id": "3b5337f9edb4a828ed580b75f9cc1952",
    "doc_2_process_id": "264dfa262b748d15ccbeaada89430c68"
});

let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://api.k-v.ai/api/agent/content_comparison',
    headers: { 
        'access-key': 'YOUR_ACCESS_KEY',
        'Content-Type': 'application/json'
    },
    data: data
};

axios.request(config)
.then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
    console.log(error);
});

Important Notes

  • Document Processing: Both documents must have status: "processed" from List Documents API
  • HTML Output: The response contains a complete, standalone HTML document
  • Browser Viewing: Save the HTML and open in any web browser to view the comparison
  • Line Numbers: Each change includes line numbers from both documents for easy reference

Next Steps

After comparing document content:

  • Save HTML Report: Write the HTML to a file with .html extension
  • Review Changes: Open in browser to view color-coded differences
  • Analyze Modifications: Identify critical changes between documents

Need Help? Contact support at support@k-v.ai

On this page