Spaces:
Running on Zero
Running on Zero
File size: 8,389 Bytes
e809c21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | # 📜 SaulGPT API Reference Manual
**API Version:** 2.2.0
**Cloud Base URL:** `https://lvvbaaal-legalgpt-api.hf.space`
**Local Development Base URL:** `http://localhost:8000`
**Transport Security:** HTTPS / TLS 1.3
**Authentication Scheme:** Bearer Token (JWT, 30-day validity, HS256) + BYOK Header (`X-Groq-Api-Key`)
---
## 1. Authentication Endpoints
### `POST /api/auth/signup`
Registers a new user in the PostgreSQL (or local SQLite) database.
- **Request Body:**
```json
{
"username": "advocate_sharma",
"email": "sharma@lawchambers.in",
"password": "StrongPassword123!"
}
```
- **Response (200 OK):**
```json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "advocate_sharma",
"email": "sharma@lawchambers.in"
}
}
```
### `POST /api/auth/login`
Authenticates existing users and issues a JWT token.
- **Request Body:**
```json
{
"email": "sharma@lawchambers.in",
"password": "StrongPassword123!"
}
```
- **Response (200 OK):**
```json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "advocate_sharma",
"email": "sharma@lawchambers.in"
}
}
```
### `GET /api/auth/me`
Retrieves current authenticated profile.
- **Headers:** `Authorization: Bearer <token>`
- **Response (200 OK):**
```json
{
"id": 1,
"username": "advocate_sharma",
"email": "sharma@lawchambers.in"
}
```
---
## 2. BYOK (Bring Your Own Key) Security Endpoints
### `POST /api/keys/validate`
Validates a personal Groq API key format and live cloud quota.
- **Request Body:**
```json
{
"key": "gsk_live_sample_token..."
}
```
- **Response (200 OK):**
```json
{
"valid": true,
"message": "Key is active and authenticated with Groq API"
}
```
### `GET /api/keys/status`
Checks if the server environment has a default Groq key or requires BYOK.
- **Response (200 OK):**
```json
{
"server_key_present": true,
"byok_required": false
}
```
---
## 3. Core Chat & Document Pipeline Endpoints
### `POST /api/chat`
Main conversational query endpoint. Dispatches through the 6-layer RAG pipeline, triage state machine, or document drafting interview.
- **Headers:**
- `Content-Type: application/json`
- `Authorization: Bearer <token>` *(Optional; guest session assumed if omitted)*
- `X-Groq-Api-Key: gsk_...` *(Optional; forwards personal Groq quota)*
- **Request Body:**
```json
{
"message": "Draft a legal notice for cheque bounce of Rs 75,000",
"session_id": "session_uuid_or_custom_id",
"user_id": 1,
"conv_id": 6
}
```
- **Response (200 OK):**
```json
{
"response": "**Cheque Bounce Notice** has been drafted successfully.\n\n[Download your document](https://lvvbaaal-legalgpt-api.hf.space/api/document/session_uuid_or_custom_id)",
"mode_used": "document",
"confidence_score": 0.85,
"critic_reward_score": 0.95,
"critic_deliberation": null,
"is_hallucinating": false,
"citations": [],
"remapped_laws": {
"IPC": "BNS (Bharatiya Nyaya Sanhita, 2023)",
"CrPC": "BNSS (Bharatiya Nagarik Suraksha Sanhita, 2023)"
},
"meta": {
"document_ready": true,
"document_url": "https://lvvbaaal-legalgpt-api.hf.space/api/document/session_uuid_or_custom_id"
},
"conv_id": 6,
"interview_active": false,
"interview_complete": true
}
```
### `GET /api/document/{session_id}`
Streams a generated Microsoft Word (`.docx`) file as a download attachment.
- **Response Headers:**
- `Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document`
- `Content-Disposition: attachment; filename="legal_document_{session_id}.docx"`
- `Access-Control-Allow-Origin: *`
### `GET /api/draft/state/{session_id}`
Returns active interview state, current progress percentage, and missing fields.
- **Response (200 OK):**
```json
{
"state": "interviewing",
"doc_type": "cheque_bounce",
"progress_pct": 57,
"missing_fields": ["amount", "date_of_default"],
"is_active": true
}
```
### `DELETE /api/draft/state/{session_id}`
Cancels the active drafting interview and resets the session state.
### `DELETE /api/history/{session_id}`
Purges the in-memory conversation history for a given session.
---
## 4. Pre-Trial Studio & Moot Court Endpoints
### `POST /api/trial/start`
Initializes an adversarial Moot Court chamber.
- **Request Body:**
```json
{
"case_title": "State vs. Accused (Section 103 BNS)",
"scenario_description": "Accused allegedly assaulted complainant on 10 July 2024...",
"session_id": "trial_session_001"
}
```
- **Response (200 OK):**
```json
{
"trial_id": "trial_session_001",
"judge_summary": "Issue framed under Section 103 BNS 2023...",
"petitioner_strategy": "Argue premeditation and direct ocular evidence...",
"respondent_strategy": "Assert right of private defense under Section 34 BNS..."
}
```
### `POST /api/trial/turn`
Executes an adversarial interrogation turn with the judicial cross-examiner under Section 146 BSA 2023.
- **Request Body:**
```json
{
"trial_id": "trial_session_001",
"user_statement": "The witness claims he saw the incident under street lighting from 50 meters away.",
"role": "petitioner"
}
```
### `POST /api/trial/conclude`
Concludes the moot proceedings, tallies evidence scores, and renders a judicial verdict.
### `GET /api/trial/precedents/{case_id}`
Retrieves verbatim precedent holdings and coram metadata from the 50,000+ landmark judgment index.
---
## 5. Multimodal Evidence & Section 63 BSA Certification
### `POST /api/evidence/upload`
Uploads digital evidence (audio files, WhatsApp chat exports, invoice PDFs, cheque scans) for forensic verification.
- **Form Data:**
- `file`: Binary file upload
- `session_id`: Session string
- `evidence_type`: `audio` | `document` | `cheque`
- **Response (200 OK):**
```json
{
"evidence_id": "EVID-2024-99182",
"sha256_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"certificate": {
"certificate_id": "BSA-63-2024-99182",
"pdf_url": "/api/certificates/BSA-63-2024-99182.pdf"
},
"extracted_data": {
"summary": "Audio conversation between tenant and landlord regarding rent default."
}
}
```
### `GET /api/certificates/{cert_filename}`
Serves court-admissible Section 63 BSA PDF certificates.
---
## 6. Contract Risk Evaluator (Layer 6)
### `POST /api/upload`
Evaluates contracts and master agreements up to 25,000 characters in a single pass.
- **Form Data:**
- `file`: Contract document (`.pdf`, `.docx`, `.txt`)
- `session_id`: String
- **Response (200 OK):**
```json
{
"session_id": "contract_audit_001",
"evaluation": {
"overall_score": 72,
"risk_level": "Medium Risk",
"summary": "Standard SaaS subscription agreement with void post-termination non-compete.",
"void_clauses": [
{
"clause": "Clause 14.2: Employee non-compete for 2 years across India",
"statute": "Section 27, Indian Contract Act 1872",
"remedy": "Delete non-compete; replace with strict customer non-solicitation."
}
]
}
}
```
---
## 7. Cloud Persistence & Conversations
### `GET /api/conversations`
Lists past conversations for the authenticated user from Supabase.
- **Headers:** `Authorization: Bearer <token>`
- **Response (200 OK):**
```json
{
"conversations": [
{
"id": 6,
"title": "Cheque Bounce Notice under Section 138 NIA",
"created_at": "2026-10-26T14:44:43Z",
"updated_at": "2026-10-26T14:51:03Z"
}
],
"total": 1
}
```
### `GET /api/conversations/{id}`
Loads full turn history and structured metadata for conversation ID.
- **Headers:** `Authorization: Bearer <token>`
### `DELETE /api/conversations/{id}`
Permanently deletes a conversation and cascades through messages.
---
## 8. System Diagnostics
### `GET /api/health`
Checks server vitality and returns feature capabilities.
- **Response (200 OK):**
```json
{
"status": "SaulGPT API is Online ⚖️",
"version": "2.0.0",
"features": [
"6-layer RAG",
"Contract Evaluation",
"Interactive Drafter"
]
}
```
|