curl -X POST https://api.roysa.net/extract \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@invoice.pdf" \
-F 'fields=[{"name":"Vendor"},{"name":"Invoice Number"},{"name":"Total Amount"},{"name":"Due Date"}]'
import requests, json
API_KEY = "YOUR_API_KEY"
fields = [
{"name": "Vendor"}, {"name": "Invoice Number"},
{"name": "Total Amount"}, {"name": "Due Date"},
]
with open("invoice.pdf", "rb") as f:
r = requests.post(
"https://api.roysa.net/extract",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"fields": json.dumps(fields)},
)
result = r.json()
print(result["extracted_features"]) # {"Vendor": "Acme Corp", ...}
print(result["confidence_scores"]) # {"Vendor": 0.97, ...}
print(result["bounding_boxes"]) # page + normalized coords per field
const API_KEY = "YOUR_API_KEY";
async function extractFromDoc(file) {
const form = new FormData();
form.append("file", file);
form.append("fields", JSON.stringify([
{name: "Vendor"}, {name: "Invoice Number"},
{name: "Total Amount"}, {name: "Due Date"},
]));
const r = await fetch("https://api.roysa.net/extract", {
method: "POST",
headers: {"X-API-Key": API_KEY},
body: form,
});
const result = await r.json();
console.log(result.extracted_features);
console.log(result.confidence_scores);
return result;
}
# ── Document / Image ─────────────────────────────────────────────────────────
curl -X POST https://api.roysa.net/document-ask \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@contract.pdf" \
-F "question=What is the termination clause?"
# ── Audio / Video (2-step) ────────────────────────────────────────────────────
# Step 1: get transcript
TRANSCRIPT=$(curl -s -X POST https://api.roysa.net/process-media \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@meeting.mp4" \
| python3 -c "import sys,json; d=json.load(sys.stdin); \
print(' '.join(s.get('text','') for s in d['transcript_segments']))")
# Step 2: ask about the transcript
curl -X POST https://api.roysa.net/document-ask \
-H "X-API-Key: YOUR_API_KEY" \
-F "question=What decisions were made?" \
-F "transcript_text=${TRANSCRIPT}"
import requests
API_KEY = "YOUR_API_KEY"
H = {"X-API-Key": API_KEY}
BASE = "https://api.roysa.net"
# ── Document / Image ──────────────────────────────────────────────────────────
with open("contract.pdf", "rb") as f:
r = requests.post(f"{BASE}/document-ask", headers=H,
files={"file": f},
data={"question": "What is the termination clause?"})
result = r.json()
print(result["answer"])
for ref in result["references"]:
print(f" [{ref['label']}] {ref['value']} (page {ref['page']})")
# session_id can be reused for follow-up questions (no re-upload needed)
session_id = result["session_id"]
# ── Audio / Video (2-step) ────────────────────────────────────────────────────
# Step 1: process media
with open("meeting.mp4", "rb") as f:
media = requests.post(f"{BASE}/process-media", headers=H,
files={"file": f}).json()
transcript_text = " ".join(s["text"] for s in media["transcript_segments"])
# Step 2: ask about the transcript
r2 = requests.post(f"{BASE}/document-ask", headers=H,
data={"question": "What decisions were made?",
"transcript_text": transcript_text})
print(r2.json()["answer"])
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.roysa.net";
async function askAboutDoc(file, question) {
const form = new FormData();
form.append("file", file);
form.append("question", question);
const r = await fetch(`${BASE}/document-ask`, {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const result = await r.json();
console.log(result.answer);
// Reuse result.session_id for follow-up questions — no re-upload
return result;
}
async function followUp(sessionId, question) {
const form = new FormData();
form.append("session_id", sessionId);
form.append("question", question);
const r = await fetch(`${BASE}/document-ask`, {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
return (await r.json()).answer;
}
curl -X POST https://api.roysa.net/transcribe \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.mp3" \
--output transcript.pdf
import requests
API_KEY = "YOUR_API_KEY"
with open("recording.mp3", "rb") as f:
r = requests.post(
"https://api.roysa.net/transcribe",
headers={"X-API-Key": API_KEY},
files={"file": f},
)
# Returns a PDF; X-Transcript-Segments header has segment count
with open("transcript.pdf", "wb") as out:
out.write(r.content)
print(f"Saved transcript.pdf ({r.headers.get('X-Transcript-Segments', '?')} segments)")
const API_KEY = "YOUR_API_KEY";
async function transcribeMedia(file) {
const form = new FormData();
form.append("file", file);
const r = await fetch("https://api.roysa.net/transcribe", {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const blob = await r.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url; a.download = "transcript.pdf"; a.click();
}
curl -X POST https://api.roysa.net/translate-document \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@document.pdf" \
-F "target_language=Spanish" \
--output translated.pdf
import requests
API_KEY = "YOUR_API_KEY"
with open("document.pdf", "rb") as f:
r = requests.post(
"https://api.roysa.net/translate-document",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"target_language": "Spanish"},
)
with open("translated.pdf", "wb") as out:
out.write(r.content)
print("Saved translated.pdf")
const API_KEY = "YOUR_API_KEY";
async function translateDoc(file, targetLanguage) {
const form = new FormData();
form.append("file", file);
form.append("target_language", targetLanguage);
const r = await fetch("https://api.roysa.net/translate-document", {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const blob = await r.blob();
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = `translated_${targetLanguage}.pdf`; a.click();
}
GEO_Q="List ALL geographic locations, addresses, cities, regions, and countries \
mentioned in this document. For each provide the label, full text value, \
page number, and exact bounding box."
curl -X POST https://api.roysa.net/document-ask \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@document.pdf" \
-F "question=${GEO_Q}"
import requests
API_KEY = "YOUR_API_KEY"
GEO_Q = (
"List ALL geographic locations, addresses, cities, regions, and countries "
"mentioned in this document. For each provide the label, full text value, "
"page number, and exact bounding box."
)
with open("document.pdf", "rb") as f:
r = requests.post(
"https://api.roysa.net/document-ask",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"question": GEO_Q},
)
for loc in r.json()["references"]:
print(f"{loc['label']}: {loc['value']} (page {loc['page']})")
if loc.get("boxes"):
print(f" bbox: {loc['boxes'][0]}")
const API_KEY = "YOUR_API_KEY";
const GEO_Q = "List ALL geographic locations, addresses, cities, regions, and countries " +
"mentioned in this document. For each provide the label, full text value, " +
"page number, and exact bounding box.";
async function geoExtract(file) {
const form = new FormData();
form.append("file", file);
form.append("question", GEO_Q);
const r = await fetch("https://api.roysa.net/document-ask", {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const result = await r.json();
result.references.forEach(loc => {
console.log(`${loc.label}: ${loc.value} (page ${loc.page})`);
if (loc.boxes?.length) console.log(" bbox:", loc.boxes[0]);
});
return result;
}
REDACT_Q="Identify ALL sensitive information to redact: personal names, SSNs, \
dates of birth, addresses, phone numbers, emails, account numbers, signatures, \
and financial data. Return each with label, value, page number, and exact bounding box."
curl -X POST https://api.roysa.net/document-ask \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@document.pdf" \
-F "question=${REDACT_Q}"
import requests
API_KEY = "YOUR_API_KEY"
REDACT_Q = (
"Identify ALL sensitive information to redact: personal names, SSNs, "
"dates of birth, addresses, phone numbers, emails, account numbers, "
"signatures, and financial data. Return each with label, value, "
"page number, and exact bounding box."
)
with open("document.pdf", "rb") as f:
r = requests.post(
"https://api.roysa.net/document-ask",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"question": REDACT_Q},
)
# Apply bounding boxes as black rectangles using your PDF library
for item in r.json()["references"]:
print(f"Redact '{item['label']}' on page {item['page']}: {item.get('boxes', [])}")
const API_KEY = "YOUR_API_KEY";
const REDACT_Q = "Identify ALL sensitive information to redact: personal names, SSNs, " +
"dates of birth, addresses, phone numbers, emails, account numbers, " +
"signatures, and financial data. Return each with label, value, " +
"page number, and exact bounding box.";
async function detectRedactions(file) {
const form = new FormData();
form.append("file", file);
form.append("question", REDACT_Q);
const r = await fetch("https://api.roysa.net/document-ask", {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const result = await r.json();
// result.references → [{label, value, page, boxes:[{x1,y1,x2,y2}]}]
// Draw black rectangles over each bbox with your PDF/canvas renderer
return result.references;
}
REVIEW_Q="Review this document and provide: \
1) An overall quality/compliance score (0–100), \
2) A list of issues found with severity (high/medium/low), \
3) Specific recommendations for improvement."
curl -X POST https://api.roysa.net/document-ask \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@contract.pdf" \
-F "question=${REVIEW_Q}"
import requests
API_KEY = "YOUR_API_KEY"
REVIEW_Q = (
"Review this document and provide: "
"1) An overall quality/compliance score (0–100), "
"2) A list of issues found with severity (high/medium/low), "
"3) Specific recommendations for improvement."
)
with open("contract.pdf", "rb") as f:
r = requests.post(
"https://api.roysa.net/document-ask",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"question": REVIEW_Q},
)
result = r.json()
print(result["answer"])
# result["references"] contains flagged issues with page + bbox
const API_KEY = "YOUR_API_KEY";
const REVIEW_Q = "Review this document and provide: " +
"1) An overall quality/compliance score (0–100), " +
"2) A list of issues found with severity (high/medium/low), " +
"3) Specific recommendations for improvement.";
async function reviewDoc(file) {
const form = new FormData();
form.append("file", file);
form.append("question", REVIEW_Q);
const r = await fetch("https://api.roysa.net/document-ask", {
method: "POST", headers: {"X-API-Key": API_KEY}, body: form,
});
const result = await r.json();
console.log(result.answer);
// result.references → flagged issues with page + bbox
return result;
}