Skip to main content
GET
/
github
/
diff
/
:owner
/
:repo
/
:pull_number
Get Pull Request Diff
curl --request GET \
  --url https://api.example.com/github/diff/:owner/:repo/:pull_number
{
  "401": {},
  "403": {},
  "404": {}
}

Authentication

This endpoint requires JWT authentication. Include your JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>

Path Parameters

owner
string
required
The GitHub username or organization name that owns the repository
repo
string
required
The name of the repository
pull_number
number
required
The pull request number (not the pull request ID)

Response

Returns the pull request changes in unified diff format. This format shows the differences between files with context lines and change indicators.

Diff Format

The response is a plain text string in unified diff format with the following structure:
  • Lines starting with --- indicate the original file
  • Lines starting with +++ indicate the modified file
  • Lines starting with @@ show the line numbers and context
  • Lines starting with - show removed lines
  • Lines starting with + show added lines
  • Lines without prefixes are context lines (unchanged)

Example Request

cURL
curl -X GET "https://api.diffy.ai/github/diff/octocat/Hello-World/1" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json"
JavaScript
const response = await fetch(
  'https://api.diffy.ai/github/diff/octocat/Hello-World/1',
  {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_JWT_TOKEN',
      'Content-Type': 'application/json'
    }
  }
);

const diff = await response.text();
console.log(diff);
Python
import requests

url = "https://api.diffy.ai/github/diff/octocat/Hello-World/1"
headers = {
    "Authorization": "Bearer YOUR_JWT_TOKEN",
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers)
diff = response.text
print(diff)

Example Response

diff --git a/src/app.ts b/src/app.ts
index 1234567..abcdefg 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,8 +1,12 @@
 import express from 'express';
+import helmet from 'helmet';
 
 const app = express();
 const PORT = process.env.PORT || 3000;
 
+// Add security middleware
+app.use(helmet());
+
 app.use(express.json());
 
 app.get('/', (req, res) => {
@@ -10,6 +14,10 @@
   res.json({ message: 'Hello World!' });
 });
 
+app.get('/health', (req, res) => {
+  res.json({ status: 'ok' });
+});
+
 app.listen(PORT, () => {
   console.log(`Server running on port ${PORT}`);
 });
diff --git a/package.json b/package.json
index 9876543..fedcba9 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
   "dependencies": {
     "express": "^4.18.0",
+    "helmet": "^7.0.0",
     "dotenv": "^16.0.0"
   },
   "devDependencies": {

Parsing the Diff

The diff can be parsed to extract:
  • File paths: Found after --- and +++ markers
  • Line numbers: Found in @@ markers (e.g., @@ -1,8 +1,12 @@)
    • -1,8 means starting at line 1, 8 lines in the original file
    • +1,12 means starting at line 1, 12 lines in the modified file
  • Changes: Lines prefixed with - (deletions) and + (additions)
  • Context: Unprefixed lines showing surrounding code

Use Cases

  • Code Review: Display changes for manual review
  • AI Analysis: Parse diff to analyze code changes programmatically
  • Change Detection: Identify what files and lines were modified
  • Diff Visualization: Build custom diff viewers
  • Automated Testing: Determine which tests to run based on changes

Error Responses

401
error
Unauthorized - Invalid or missing JWT token
404
error
Not Found - Pull request, repository, or owner does not exist
403
error
Forbidden - User does not have access to the repository

Notes

  • The diff is returned in the same format as GitHub’s native diff view
  • Large diffs may take longer to process
  • Binary file changes will show as “Binary files differ” without detailed changes
  • The diff includes all commits in the pull request, not just the latest commit

Build docs developers (and LLMs) love