Complete API reference for MindTrace backend services.
Base URL: http://localhost:8000 (development)
API Version: 1.0.0
Authentication: JWT Bearer Token (for protected endpoints)
- Authentication
- Face Recognition
- Speech-to-Text
- AI Services
- Contacts
- Interactions
- Reminders
- SOS
- Statistics
- Search
- User Management
POST /auth/register
Create a new user account.
Request Body:
{
"email": "user@example.com",
"password": "securepassword123",
"name": "John Doe"
}Response: 201 Created
{
"id": 1,
"email": "user@example.com",
"name": "John Doe",
"created_at": "2024-01-01T00:00:00Z"
}POST /auth/login
Authenticate and receive JWT token.
Request Body:
{
"email": "user@example.com",
"password": "securepassword123"
}Response: 200 OK
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"user": {
"id": 1,
"email": "user@example.com",
"name": "John Doe"
}
}GET /auth/me
Get authenticated user information.
Headers:
Authorization: Bearer <token>
Response: 200 OK
{
"id": 1,
"email": "user@example.com",
"name": "John Doe",
"created_at": "2024-01-01T00:00:00Z"
}POST /face/recognize
Detect and recognize faces in an image.
Headers:
Authorization: Bearer <token>
Content-Type: multipart/form-data
Request Body (multipart/form-data):
image: [binary image file]
user_id: 1
Response: 200 OK
{
"faces": [
{
"name": "John Doe",
"relation": "Friend",
"confidence": 0.87,
"bbox": [100, 150, 300, 400],
"det_score": 0.95,
"contact_id": 123
},
{
"name": "Unknown",
"relation": "Unidentified Person",
"confidence": 0.0,
"bbox": [400, 200, 600, 500],
"det_score": 0.92
}
],
"processing_time_ms": 85
}POST /face/sync
Generate face embeddings from contact profile photos.
Headers:
Authorization: Bearer <token>
Request Body:
{
"user_id": 1
}Response: 200 OK
{
"success": true,
"count": 15,
"message": "Successfully synced 15 face embeddings"
}WebSocket /asr/stream
Real-time audio transcription via WebSocket.
Connection:
const ws = new WebSocket('ws://localhost:8000/asr/stream');Send Message:
{
"audio": "base64_encoded_audio_chunk",
"user_id": 1,
"contact_name": "John Doe",
"sample_rate": 16000
}Receive Message:
{
"transcript": "Hello, how are you doing today?",
"is_final": true,
"confidence": 0.95
}GET /asr/conversations
Retrieve stored conversation transcripts.
Headers:
Authorization: Bearer <token>
Query Parameters:
user_id(required): User IDcontact_name(optional): Filter by contactstart_date(optional): ISO 8601 dateend_date(optional): ISO 8601 datelimit(optional): Max results (default: 50)
Response: 200 OK
{
"conversations": [
{
"id": "conv_123",
"user_id": 1,
"contact_name": "John Doe",
"transcript": "Full conversation transcript...",
"start_time": "2024-01-01T10:00:00Z",
"end_time": "2024-01-01T10:15:00Z",
"duration_seconds": 900
}
],
"total": 25
}POST /ai/summarize
Generate AI-powered summary of interactions.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"user_id": 1,
"summary_type": "brief",
"days": 7,
"contact_id": 123,
"focus_areas": ["health", "family"]
}Parameters:
summary_type: "brief", "detailed", or "analytical"days: Number of days to include (optional)contact_id: Filter by specific contact (optional)focus_areas: Topics to emphasize (optional)
Response: 200 OK
{
"summary": "Over the past week, you had 5 interactions with John Doe. The main topics discussed were health concerns and family updates. You talked about scheduling a doctor's appointment and planning a family gathering...",
"interaction_count": 5,
"time_period": {
"start": "2024-01-01T00:00:00Z",
"end": "2024-01-07T23:59:59Z",
"days": 7
},
"summary_type": "brief",
"focus_areas": ["health", "family"]
}POST /ai/rag/query
Ask questions about interaction history using RAG.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"question": "What did I discuss with Sarah last week?",
"user_id": 1,
"n_results": 10,
"include_context": true
}Response: 200 OK
{
"answer": "Last week, you discussed the upcoming project deadline with Sarah. She mentioned concerns about the timeline and suggested having a team meeting to reallocate resources...",
"sources": [
{
"interaction_id": 456,
"contact_name": "Sarah",
"timestamp": "2024-01-05T14:30:00Z",
"relevance_score": 0.92,
"snippet": "We talked about the upcoming project deadline..."
}
],
"retrieved_count": 5,
"question": "What did I discuss with Sarah last week?",
"used_contacts": true,
"used_stats": false
}POST /ai/rag/multi-turn
Continue conversation with context from previous turns.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"question": "What about her family?",
"user_id": 1,
"conversation_history": [
{
"question": "What did I discuss with Sarah?",
"answer": "You discussed work projects and deadlines..."
}
],
"n_results": 5
}Response: 200 OK
{
"answer": "Regarding Sarah's family, you asked about her daughter's college applications. Sarah mentioned her daughter is applying to engineering programs...",
"sources": [...],
"retrieved_count": 3
}POST /ai/insights
Generate behavioral insights and patterns.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"user_id": 1,
"topic": "health"
}Response: 200 OK
{
"insights": "Your health-related interactions show a consistent pattern of weekly check-ins with Dr. Smith. You've discussed blood pressure management 3 times this month. Key recommendations: 1. Continue weekly monitoring. 2. Consider scheduling the follow-up appointment mentioned on Jan 5...",
"topic": "health",
"analyzed_interactions": 30,
"total_contacts": 15,
"total_interactions": 150
}GET /contacts
Get all contacts for authenticated user.
Headers:
Authorization: Bearer <token>
Query Parameters:
search(optional): Search by namerelationship(optional): Filter by relationship typelimit(optional): Max results (default: 100)offset(optional): Pagination offset
Response: 200 OK
{
"contacts": [
{
"id": 1,
"user_id": 1,
"name": "John Doe",
"relationship": "friend",
"relationship_detail": "College friend",
"phone_number": "+1234567890",
"email": "john@example.com",
"notes": "Met at university in 2015",
"visit_frequency": "weekly",
"last_seen": "2024-01-05T14:30:00Z",
"profile_photo_url": "/api/contacts/1/photo",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-05T14:30:00Z"
}
],
"total": 25,
"limit": 100,
"offset": 0
}GET /contacts/{contact_id}
Get specific contact details.
Headers:
Authorization: Bearer <token>
Response: 200 OK
{
"id": 1,
"user_id": 1,
"name": "John Doe",
"relationship": "friend",
"relationship_detail": "College friend",
"phone_number": "+1234567890",
"email": "john@example.com",
"notes": "Met at university in 2015",
"visit_frequency": "weekly",
"last_seen": "2024-01-05T14:30:00Z",
"profile_photo_url": "/api/contacts/1/photo",
"interaction_count": 45,
"last_interaction": "2024-01-05T14:30:00Z"
}POST /contacts
Create a new contact with optional profile photo.
Headers:
Authorization: Bearer <token>
Content-Type: multipart/form-data
Request Body (multipart/form-data):
name: "Jane Smith"
relationship: "family"
relationship_detail: "Sister"
phone_number: "+1234567890"
email: "jane@example.com"
notes: "Lives in Seattle"
visit_frequency: "monthly"
profile_photo: [binary image file]
Response: 201 Created
{
"id": 2,
"user_id": 1,
"name": "Jane Smith",
"relationship": "family",
"relationship_detail": "Sister",
"phone_number": "+1234567890",
"email": "jane@example.com",
"notes": "Lives in Seattle",
"visit_frequency": "monthly",
"profile_photo_url": "/api/contacts/2/photo",
"created_at": "2024-01-06T10:00:00Z"
}PUT /contacts/{contact_id}
Update contact information.
Headers:
Authorization: Bearer <token>
Content-Type: multipart/form-data
Request Body (multipart/form-data):
name: "Jane Smith-Johnson"
phone_number: "+1234567891"
notes: "Lives in Portland now"
profile_photo: [binary image file] (optional)
Response: 200 OK
{
"id": 2,
"name": "Jane Smith-Johnson",
"phone_number": "+1234567891",
"notes": "Lives in Portland now",
"updated_at": "2024-01-07T15:00:00Z"
}DELETE /contacts/{contact_id}
Delete a contact and associated data.
Headers:
Authorization: Bearer <token>
Response: 204 No Content
GET /contacts/{contact_id}/photo
Retrieve contact profile photo.
Headers:
Authorization: Bearer <token>
Response: 200 OK
Content-Type: image/jpeg
[binary image data]
GET /interactions
Get interaction history with filters.
Headers:
Authorization: Bearer <token>
Query Parameters:
user_id(required): User IDcontact_id(optional): Filter by contactstart_date(optional): ISO 8601 dateend_date(optional): ISO 8601 datelimit(optional): Max results (default: 50)offset(optional): Pagination offset
Response: 200 OK
{
"interactions": [
{
"id": 1,
"user_id": 1,
"contact_id": 123,
"contact_name": "John Doe",
"summary": "Discussed project timeline and deliverables",
"full_details": "We talked about the Q1 project timeline...",
"key_topics": ["work", "deadlines", "team"],
"location": "Office",
"timestamp": "2024-01-05T14:30:00Z",
"duration_minutes": 30,
"created_at": "2024-01-05T15:00:00Z"
}
],
"total": 150,
"limit": 50,
"offset": 0
}GET /interactions/{interaction_id}
Get specific interaction details.
Headers:
Authorization: Bearer <token>
Response: 200 OK
{
"id": 1,
"user_id": 1,
"contact_id": 123,
"contact_name": "John Doe",
"summary": "Discussed project timeline",
"full_details": "Full conversation details...",
"key_topics": ["work", "deadlines"],
"location": "Office",
"timestamp": "2024-01-05T14:30:00Z",
"duration_minutes": 30,
"transcript": "Full transcript if available...",
"created_at": "2024-01-05T15:00:00Z"
}POST /interactions
Record a new interaction.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"user_id": 1,
"contact_id": 123,
"contact_name": "John Doe",
"summary": "Discussed project timeline",
"full_details": "We talked about Q1 deliverables...",
"key_topics": ["work", "deadlines"],
"location": "Office",
"timestamp": "2024-01-05T14:30:00Z",
"duration_minutes": 30
}Response: 201 Created
{
"id": 1,
"user_id": 1,
"contact_id": 123,
"contact_name": "John Doe",
"summary": "Discussed project timeline",
"timestamp": "2024-01-05T14:30:00Z",
"created_at": "2024-01-05T15:00:00Z"
}PUT /interactions/{interaction_id}
Update interaction details.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"summary": "Updated summary",
"full_details": "Updated details...",
"key_topics": ["work", "deadlines", "budget"]
}Response: 200 OK
DELETE /interactions/{interaction_id}
Delete an interaction record.
Headers:
Authorization: Bearer <token>
Response: 204 No Content
GET /reminders
Get all reminders for user.
Headers:
Authorization: Bearer <token>
Query Parameters:
user_id(required): User IDtype(optional): Filter by type (medication, meal, activity)status(optional): Filter by status (active, completed, snoozed)
Response: 200 OK
{
"reminders": [
{
"id": 1,
"user_id": 1,
"title": "Take blood pressure medication",
"description": "Take 1 pill with water",
"type": "medication",
"scheduled_time": "08:00:00",
"days_of_week": [1, 2, 3, 4, 5],
"is_active": true,
"last_completed": "2024-01-05T08:00:00Z",
"created_at": "2024-01-01T00:00:00Z"
}
],
"total": 10
}POST /reminders
Create a new reminder.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"user_id": 1,
"title": "Take medication",
"description": "Blood pressure pill",
"type": "medication",
"scheduled_time": "08:00:00",
"days_of_week": [1, 2, 3, 4, 5],
"is_active": true
}Response: 201 Created
PUT /reminders/{reminder_id}
Update reminder details.
Response: 200 OK
DELETE /reminders/{reminder_id}
Delete a reminder.
Response: 204 No Content
POST /reminders/{reminder_id}/complete
Mark reminder as completed.
Response: 200 OK
{
"id": 1,
"status": "completed",
"completed_at": "2024-01-06T08:05:00Z"
}POST /sos/alert
Send emergency SOS alert.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"user_id": 1,
"location": {
"latitude": 47.6062,
"longitude": -122.3321
},
"message": "Emergency assistance needed",
"contact_ids": [1, 2, 3]
}Response: 201 Created
{
"alert_id": "sos_123",
"status": "sent",
"notified_contacts": 3,
"timestamp": "2024-01-06T15:30:00Z"
}GET /sos/history
Retrieve SOS alert history.
Headers:
Authorization: Bearer <token>
Response: 200 OK
{
"alerts": [
{
"id": "sos_123",
"user_id": 1,
"location": {
"latitude": 47.6062,
"longitude": -122.3321
},
"message": "Emergency assistance needed",
"status": "resolved",
"timestamp": "2024-01-06T15:30:00Z",
"resolved_at": "2024-01-06T16:00:00Z"
}
]
}GET /stats/dashboard
Get comprehensive dashboard statistics.
Headers:
Authorization: Bearer <token>
Query Parameters:
user_id(required): User ID
Response: 200 OK
{
"total_contacts": 25,
"total_interactions": 150,
"interactions_today": 3,
"interactions_this_week": 12,
"interactions_this_month": 45,
"top_contacts": [
{
"contact_id": 123,
"name": "John Doe",
"interaction_count": 20,
"last_interaction": "2024-01-05T14:30:00Z"
}
],
"recent_interactions": [...],
"interaction_trend": [
{
"date": "2024-01-01",
"count": 5
}
],
"reminders_pending": 3,
"reminders_completed_today": 2
}GET /stats/interactions
Get detailed interaction analytics.
Headers:
Authorization: Bearer <token>
Query Parameters:
user_id(required): User IDstart_date(optional): ISO 8601 dateend_date(optional): ISO 8601 date
Response: 200 OK
{
"total_interactions": 150,
"average_per_day": 5.2,
"by_contact": [...],
"by_topic": {
"work": 45,
"family": 30,
"health": 25
},
"by_day_of_week": {
"Monday": 25,
"Tuesday": 22
},
"by_hour": {
"09:00": 15,
"14:00": 20
}
}POST /search/semantic
Search interactions using semantic similarity.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"query": "health discussions",
"user_id": 1,
"n_results": 10,
"filters": {
"contact_id": 123,
"start_date": "2024-01-01",
"end_date": "2024-01-31"
}
}Response: 200 OK
{
"results": [
{
"interaction_id": 123,
"contact_name": "Dr. Smith",
"timestamp": "2024-01-03T10:00:00Z",
"content": "Discussed blood pressure management...",
"relevance_score": 0.89,
"key_topics": ["health", "medication"]
}
],
"total": 15,
"query": "health discussions"
}PUT /users/profile
Update user profile information.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"name": "John Doe",
"email": "newemail@example.com",
"phone": "+1234567890"
}Response: 200 OK
POST /users/change-password
Change user password.
Headers:
Authorization: Bearer <token>
Content-Type: application/json
Request Body:
{
"current_password": "oldpassword",
"new_password": "newpassword123"
}Response: 200 OK
All endpoints may return the following error responses:
{
"detail": "Invalid request parameters",
"errors": [
{
"field": "email",
"message": "Invalid email format"
}
]
}{
"detail": "Invalid or expired token"
}{
"detail": "Insufficient permissions"
}{
"detail": "Resource not found"
}{
"detail": "Internal server error",
"error_id": "err_123456"
}API endpoints are rate-limited to prevent abuse:
- Authentication: 5 requests per minute
- Face Recognition: 30 requests per minute
- AI Services: 10 requests per minute
- Other endpoints: 100 requests per minute
Rate limit headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1609459200
List endpoints support pagination:
Query Parameters:
limit: Number of results per page (default: 50, max: 100)offset: Number of results to skip
Response Headers:
X-Total-Count: 150
X-Page-Limit: 50
X-Page-Offset: 0
For interactive API documentation with request/response examples:
Swagger UI: http://localhost:8000/docs
ReDoc: http://localhost:8000/redoc
import requests
# Login
response = requests.post(
"http://localhost:8000/auth/login",
json={"email": "user@example.com", "password": "password"}
)
token = response.json()["access_token"]
# Recognize faces
with open("photo.jpg", "rb") as f:
response = requests.post(
"http://localhost:8000/face/recognize",
headers={"Authorization": f"Bearer {token}"},
files={"image": f},
data={"user_id": 1}
)
faces = response.json()["faces"]// Login
const response = await fetch('http://localhost:8000/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: 'user@example.com',
password: 'password'
})
});
const { access_token } = await response.json();
// Get contacts
const contacts = await fetch('http://localhost:8000/contacts', {
headers: { 'Authorization': `Bearer ${access_token}` }
}).then(r => r.json());