Complete API Surface & Endpoint Contracts
This page is the canonical API Reference Manual for the backend application. All business routes are versioned under /api/v1/.
1. Global Request & Response Contracts
All endpoints (except public infrastructure/auth endpoints) require one of the following authentication headers:
- Bearer Token:
Authorization: Bearer <jwt_access_token>
- API Key:
X-API-Key: <api_key_string>
- Microsoft OAuth: Session-backed or token-backed SSO verification.
Success Response (200 OK / 201 Created / 202 Accepted)
"message": "Optional operational summary"
Error Response (400 / 401 / 403 / 404 / 422 / 500)
"error_code": "ERROR_CATEGORY_CODE",
"message": "Human-readable description of the failure",
2. Complete API Endpoint Reference Matrix
A. Authentication & User Profile (/api/v1/auth/)
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
POST | /api/v1/auth/login/ | CustomLoginAPIView | None (Public) | Header: Content-Type: application/json | {"email": "string", "password": "string"} | 200 OK
{"access": "jwt", "refresh": "jwt", "user": {}} | INVALID_CREDENTIALS
ACCOUNT_DISABLED |
POST | /api/v1/auth/refresh/ | TokenRefreshAPIView | None (Public) | Header: Content-Type: application/json | {"refresh": "jwt_refresh_token"} | 200 OK
{"access": "new_jwt_token"} | TOKEN_EXPIRED
INVALID_TOKEN |
POST | /api/v1/auth/microsoft/ | MicrosoftAuthView | None (Public) | Header: Content-Type: application/json | {"access_token": "ms_oauth_token"} | 200 OK
{"access": "jwt", "user": {}, "tenants": []} | MS_AUTH_FAILED
USER_NOT_FOUND |
GET | /api/v1/auth/profile/ | UserProfileAPIView | Bearer / Session | Header: Authorization: Bearer <token> | None | 200 OK
{"id": 1, "email": "...", "roles": []} | UNAUTHORIZED |
B. Document Upload & Processing Lifecycle (/api/v1/)
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
POST | /api/v1/process-document/upload/ | DocumentUploadAPIView | Bearer / API Key | Multipart Form Data | file: binary (PDF/Image)
schema_id: int/str
country_id: int
model_id: int | 202 Accepted
{"task_id": "uuid", "status": "PENDING", "doc_id": 123} | FILE_TOO_LARGE
INVALID_MIME_TYPE
SCHEMA_NOT_FOUND |
GET | /api/v1/task-status/<task_id>/ | TaskStatusAPIView | Bearer / API Key | Path: task_id (str) | None | 200 OK
{"task_id": "...", "status": "COMPLETED", "result": {}} | TASK_NOT_FOUND |
GET | /api/v1/document-status/<doc_id>/ | DocumentStatusAPIView | Bearer / API Key | Path: doc_id (int) | None | 200 OK
{"doc_id": 123, "status": "PROCESSED", "extraction": {}} | DOCUMENT_NOT_FOUND |
GET | /api/v1/metaprocessing/<file_id>/ | MetaprocessingAPIView | Bearer / API Key | Path: file_id (int) | None | 200 OK
{"file_id": 123, "pages": [], "confidence": 0.95} | FILE_NOT_FOUND |
GET/POST | /api/v1/processing-documents/ | ProcessingDocumentViewSet | Bearer / API Key | Query: page, page_size, status | POST: ProcessingDocument payload | 200 OK (list) / 201 Created | VALIDATION_ERROR |
C. Schema Management & Schema Generation (/api/v1/schema/)
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
GET | /api/v1/schema/ | SchemaViewSet | Bearer / API Key | Query: search, page, tenant_id | None | 200 OK
{"results": [{"schema_uid": "...", "name": "..."}]} | UNAUTHORIZED |
POST | /api/v1/schema/ | SchemaViewSet | Bearer / API Key | Header: Content-Type: application/json | {"name": "...", "fields": [], "description": "..."} | 201 Created
{"schema_uid": "...", "name": "..."} | DUPLICATE_SCHEMA_NAME
INVALID_FIELDS |
GET | /api/v1/schema/<schema_uid>/ | SchemaViewSet | Bearer / API Key | Path: schema_uid (str) | None | 200 OK
{"schema_uid": "...", "fields": [...]} | SCHEMA_NOT_FOUND |
POST | /api/v1/schema/generate/ | SchemaViewSet | Bearer / API Key | Multipart Form Data | uploaded_file: binary
country_id: int
model_id: int | 202 Accepted
{"job_id": "uuid", "status": "PROCESSING"} | LLM_GENERATION_FAILED
UNSUPPORTED_FILE |
POST | /api/v1/schema/import_schemas/ | SchemaViewSet | Bearer / API Key | Multipart / JSON | {"file": "schema_backup.json"} | 200 OK
{"imported_count": 5} | INVALID_IMPORT_FORMAT |
GET | /api/v1/schema/export_schemas/ | SchemaViewSet | Bearer / API Key | Query: schema_uids (comma-separated) | None | 200 OK (JSON file download) | EXPORT_FAILED |
D. Multi-Tenancy & Org Management (/api/v1/tenants/ & /api/v1/org/)
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
GET/POST | /api/v1/tenants/ | TenantViewSet | Bearer / Admin | Query: page, search | {"name": "Tenant Name", "subdomain": "abc"} | 200 OK / 201 Created | SUBDOMAIN_EXISTS |
GET/POST | /api/v1/tenants/<tenant_id>/members/ | TenantMembershipViewSet | Bearer / TenantAdmin | Path: tenant_id | {"user_email": "...", "role": "admin"} | 200 OK / 201 Created | MEMBER_ALREADY_EXISTS |
POST | /api/v1/org/invite/ | OrgInviteView | Bearer / Admin | Header: Content-Type: application/json | {"email": "user@org.com", "role": "member"} | 200 OK
{"invite_token": "...", "status": "SENT"} | USER_ALREADY_MEMBER |
E. File Management & Secure Serving (/api/v1/files/)
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
POST | /api/v1/upload-file/ | FileUploadAPIView | Bearer / API Key | Multipart Form Data | file: binary | 201 Created
{"file_id": 456, "file_name": "..."} | VIRUS_SCAN_FAILED
FILE_TOO_LARGE |
GET | /api/v1/files/user/<file_id>/ | JWTFileServeView | Bearer JWT | Path: file_id (int) | None | 200 OK (Binary Stream) | FILE_NOT_FOUND
PERMISSION_DENIED |
GET | /api/v1/files/processed/<file_id>/ | JWTFileServeView | Bearer JWT | Path: file_id (int) | None | 200 OK (Binary Stream) | FILE_NOT_FOUND |
GET | /api/v1/preview/processed/<file_id>/ | serve_processed_file_image | Bearer / Session | Path: file_id (int) | None | 200 OK (image/png / image/jpeg) | IMAGE_GENERATION_FAILED |
F. Billing, Activity Logs, Chatbot & Infrastructure
| Method | Endpoint Route | View Class | Auth Required | Parameters / Headers | Request Body Schema | Success Response | Error Codes |
|---|
GET | /api/v1/billing/plan/ | BillingPlanView | Bearer / Admin | Query: tenant_id | None | 200 OK
{"plan_name": "Enterprise", "quota": 10000} | BILLING_RECORD_NOT_FOUND |
GET | /api/v1/billing/usage/ | BillingUsageView | Bearer / Admin | Query: month, year | None | 200 OK
{"used_pages": 450, "remaining": 9550} | UNAUTHORIZED |
GET | /api/v1/admin/activity-logs/ | ActivityLogListView | Bearer / Admin | Query: action, user_id, start_date | None | 200 OK
{"results": [{"id": "uuid", "action": "..."}]} | FORBIDDEN |
POST | /api/v1/chatbot/ | ChatbotAPIView | Public / Session | Header: Content-Type: application/json | {"message": "Hello", "conversation_id": "..."} | 200 OK
{"reply": "...", "conversation_id": "..."} | LITELLM_TIMEOUT |
GET | /api/health/ | health_check | None (Public) | None | None | 200 OK
{"status": "healthy", "database": "up"} | SERVICE_UNHEALTHY (503) |
3. Sequence Flow Diagram: Document Processing API Contract
actor Client as Frontend / API Client
participant Gateway as Django API Gateway
participant View as DocumentUploadAPIView
participant Task as Celery Worker
participant Storage as Cloud Storage / DB
Client->>Gateway: POST /api/v1/process-document/upload/ (Multipart File + Headers)
Gateway->>View: Authenticate & Validate Request
View-->>Client: 400 Bad Request / 422 Unprocessable (Error JSON)
View->>Storage: Persist uploaded file record & metadata
View->>Task: Queue background processing task (task_id)
View-->>Client: 202 Accepted {"task_id": "abc-123", "status": "PENDING"}
Client->>Gateway: GET /api/v1/task-status/abc-123/
Gateway-->>Client: 200 OK {"status": "PROCESSING" | "COMPLETED"}
4. Verification Tests
tests/unit/api/test_api_endpoints.py — Verifies route availability and URL reversing.
tests/integration/test_viewsets.py — Validates DRF viewset permissions and serializations.
tests/unit/schema/test_schema_generator_endpoints.py — Proves schema generation API contracts.