This document describes all available API endpoints for Sophos.ai backend.
Base URL: http://localhost:3001/api (development)
Authentication: All endpoints require a valid JWT token in the Authorization header:
Authorization: Bearer <your_supabase_jwt_token>
POST /documents/upload
Upload and process a PDF document.
Request:
- Content-Type:
multipart/form-data - Body: FormData with
filefield (PDF file)
Response:
{
"nodes": [...],
"edges": [...],
"timeline": [...],
"actionPlan": { "phases": [...] },
"documentId": "uuid"
}Status Codes:
200- Success400- Invalid file or missing file401- Unauthorized500- Processing error
GET /documents/:documentId
Retrieve a processed document by ID.
Parameters:
documentId(path) - Document UUID
Response:
{
"nodes": [...],
"edges": [...],
"timeline": [...],
"actionPlan": { "phases": [...] },
"documentId": "uuid"
}Status Codes:
200- Success401- Unauthorized404- Document not found or access denied500- Server error
POST /youtube/process
Process a YouTube video and extract transcript.
Request:
{
"url": "https://youtube.com/watch?v=..."
}Response:
{
"videoId": "string",
"concepts": {
"nodes": [...],
"edges": [...]
},
"timeline": [...],
"actionPlan": { "phases": [...] },
"documentId": "uuid"
}Status Codes:
200- Success400- Invalid URL or transcript unavailable401- Unauthorized500- Processing error
POST /github/process
Analyze a GitHub repository's codebase.
Request:
{
"url": "https://github.com/owner/repo"
}Response:
{
"repoName": "owner/repo",
"nodes": [...],
"edges": [...],
"timeline": [...],
"actionPlan": { "phases": [...] },
"documentId": "uuid"
}Status Codes:
200- Success400- Invalid repository URL401- Unauthorized404- Repository not found or access denied500- Processing error
POST /chat
Chat with your current document using RAG (Retrieval-Augmented Generation).
Request:
{
"message": "What is this document about?",
"history": [
{ "role": "user", "content": "Previous question" },
{ "role": "assistant", "content": "Previous answer" }
],
"documentId": "uuid"
}Parameters:
message(required) - User's question/messagehistory(optional) - Array of previous messages for context (max 10)documentId(required) - Current document UUID
Response:
{
"answer": "The document discusses...",
"relevanceScores": [0.85, 0.78, 0.72],
"chunksUsed": 3
}Status Codes:
200- Success400- Missing message or documentId401- Unauthorized404- Document not found500- Processing error
POST /quiz/generate
Generate an interactive quiz from a document.
Request:
{
"documentId": "uuid",
"questionCount": 10
}Parameters:
documentId(required) - Document UUIDquestionCount(optional) - Number of questions (default: 10)
Response:
{
"questions": [
{
"question": "What is...",
"options": ["A", "B", "C", "D"],
"correct": 0,
"explanation": "..."
}
]
}Status Codes:
200- Success400- Missing or invalid documentId401- Unauthorized404- Document not found500- Generation error
All endpoints follow a consistent error response format:
{
"error": "Error message describing what went wrong"
}400 Bad Request- Invalid or miss request parameters401 Unauthorized- Missing or invalid authentication token404 Not Found- Resource not found or access denied500 Internal Server Error- Server-side processing error
Currently, there are no enforced rate limits, but consider:
- Document uploads: Limited by file size (recommended max 10MB)
- Chat: Reasonable conversation length (last 10 messages sent as context)
- Quiz generation: Limited by OpenAI API rate limits
- User logs in via Supabase Auth (frontend)
- Frontend receives JWT token
- Token passed in
Authorizationheader for all API requests - Backend validates token with Supabase
- Documents are chunked and embedded for RAG
- Embeddings stored in Supabase for efficient similarity search
- Processing may take 10-30 seconds depending on document size
- Only sends last 10 messages to backend
- Searches only the current document's chunks
- Uses OpenAI for response generation