Skip to content

Code Diff API

Overview

Compares two source-code inputs line by line, with language-aware comment and whitespace options. Output is JSONL.

Endpoint and authentication

POST https://api.apidatatools.com/code-diff-api with x-api-key: YOUR_API_KEY.

Input modes

Body mode accepts {"left":"...","right":"..."}. URL mode uses left_url and right_url; file mode uses left_file and right_file. URL/file processing is asynchronous.

Accepted extensions: .txt, .log, .py, .js, .ts, .java, .c, .cpp, .cs, .go, .rb, .sh, .sql, .css.

Options

Header Required / default Description
x-code-language Required c, cpp, csharp, css, go, java, javascript, typescript, python, ruby, shell, or sql.
x-ignore-comments false Ignore language comments.
x-ignore-whitespace true Ignore whitespace.
x-ignore-case false Ignore case.
x-max-changes 100000 Change limit.

curl example

curl -X POST 'https://api.apidatatools.com/code-diff-api' \\
  -H 'x-api-key: YOUR_API_KEY' \\
  -H 'x-code-language: python' \\
  -H 'x-ignore-comments: true' \\
  --data-raw '{"left":"x = 1 # old","right":"x=1 # new"}'

URL and file mode examples

Include all code option headers on async submissions.

curl --request POST --url https://api.apidatatools.com/code-diff-api \
  --header 'x-api-key: YOUR_API_KEY' --header 'x-source-type: url' \
  --header 'x-code-language: python' --header 'x-ignore-comments: true' \
  --header 'Content-Type: application/json' \
  --data '{"left_url":"https://example.com/old.py","right_url":"https://example.com/new.py"}'
curl --request POST --url https://api.apidatatools.com/code-diff-api \
  --header 'x-api-key: YOUR_API_KEY' --header 'x-source-type: file' \
  --header 'x-code-language: python' --header 'Content-Type: application/json' \
  --data '{"left_file":"LEFT_UPLOAD_KEY","right_file":"RIGHT_UPLOAD_KEY"}'

Result and async process

Output is JSONL with metadata, line-change records, and a summary. Body mode returns HTTP 200 with file and preview. URL/file mode returns HTTP 202 with job_id and status_url. Poll with the same API key; queued/processing states include retry_after, success includes result.file, and failure includes error.

{"status":"accepted","job_id":"JOB_ID","status_url":"https://api.apidatatools.com/jobs/JOB_ID","request_id":"REQUEST_ID"}

Errors

HTTP status Error codes
400 INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_CODE_LANGUAGE, INVALID_DIFF_BODY, INVALID_UTF8, EMPTY_DIFF_INPUT, DIFF_LINE_TOO_LARGE
401 UNAUTHORIZED
404 USER_NOT_FOUND, UNKNOWN_FUNCTION
413 PAYLOAD_TOO_LARGE
429 QUOTA_EXCEEDED, RATE_LIMITED
500 PLAN_NOT_FOUND, AUTH_ERROR, INTERNAL_ERROR

Async errors include INVALID_DIFF_INPUTS, FILE_TOO_LARGE, CONFIG_ERROR, PLAN_CONFIG_ERROR, DOWNLOAD_FAILED, and UPLOAD_FAILED. Status errors include INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, and DDB_ERROR.

Notes

Each source is size-checked independently. Honor retry_after; JSONL output URLs are temporary.