POST
/api/diff$0.001🛠️ Text Diff
Generate a unified diff between two text strings, similar to the Unix `diff` command. Returns standard unified diff format showing additions, deletions, and context. Useful for code review, change tracking, and document comparison.
Request Body
Response Fields
Code Examples
cURL
bash
curl -X POST https://sparkforge.sh/api/diff \
-H "Content-Type: application/json" \
-H "X-PAYMENT: <x402-payment-token>" \
-d '{
"text1": "Hello World\nThis is the original text.",
"text2": "Hello SparkForge\nThis is the modified text."
}'Python
python
import requests
response = requests.post(
"https://sparkforge.sh/api/diff",
headers={"Content-Type": "application/json", "X-PAYMENT": "<token>"},
json={
"text1": "Hello World\nThis is original.",
"text2": "Hello SparkForge\nThis is modified."
}
)
data = response.json()
print(data["diff"])
print(f"+{data['additions']} -{data['deletions']}")TypeScript / Node.js
typescript
const res = await fetch402("https://sparkforge.sh/api/diff", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text1: "Hello World\nThis is original.",
text2: "Hello SparkForge\nThis is modified.",
}),
});
const { diff, additions, deletions } = await res.json();Example Response
json
{
"diff": "@@ -1,2 +1,2 @@\n-Hello World\n+Hello SparkForge\n-This is the original text.\n+This is the modified text.",
"additions": 2,
"deletions": 2,
"changed": true
}💳 Payment via x402
This endpoint costs $0.001 per call, paid in USDC on Base, Polygon, or Solana. Use the @x402/fetch library to handle payments automatically, or implement the x402 handshake manually.
bash
# Free demo mode (no payment)
curl https://sparkforge.sh/api/diff?demo=true
# Or try via MCP (Claude Desktop, Cursor, Windsurf)
# Add to mcp config: { "url": "https://sparkforge.sh/api/mcp" }