File size: 6,928 Bytes
4854e2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
311
312
313
314
315
316
"""Comprehensive API Testing Examples"""

# Authentication Examples
## Register New User
POST http://localhost:8000/api/auth/register
Content-Type: application/json

{
  "email": "harsh@company.com",
  "password": "SecurePassword123",
  "full_name": "Harsh Kumar"
}

### Expected Response (201)
{
  "user": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "email": "harsh@company.com",
    "full_name": "Harsh Kumar",
    "role": "user",
    "tenant_id": "660e8400-e29b-41d4-a716-446655440000",
    "is_active": true,
    "created_at": "2024-01-15T10:30:00Z"
  },
  "tokens": {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "token_type": "bearer",
    "expires_in": 1800
  },
  "tenant": {
    "id": "660e8400-e29b-41d4-a716-446655440000",
    "name": "org-company.com",
    "plan": "free",
    "api_quota": 10000,
    "created_at": "2024-01-15T10:30:00Z"
  }
}

## Login
POST http://localhost:8000/api/auth/login
Content-Type: application/json

{
  "email": "harsh@company.com",
  "password": "SecurePassword123"
}

### Expected Response (200)
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "bearer",
  "expires_in": 1800
}

## Refresh Token
POST http://localhost:8000/api/auth/refresh
Content-Type: application/json

{
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

### Expected Response (200)
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "bearer",
  "expires_in": 1800
}

## Get Current User
GET http://localhost:8000/api/auth/me
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "harsh@company.com",
  "full_name": "Harsh Kumar",
  "role": "user",
  "tenant_id": "660e8400-e29b-41d4-a716-446655440000",
  "is_active": true,
  "created_at": "2024-01-15T10:30:00Z"
}

---

# Face Operations Examples

## Register Face (Form Data with File)
POST http://localhost:8000/api/face/register
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: multipart/form-data

person_id: EMP001
name: Harsh Kumar
image: @/path/to/harsh_photo.jpg
metadata: {"department": "Engineering", "designation": "Senior Developer"}

### Expected Response (201)
{
  "id": "770e8400-e29b-41d4-a716-446655440000",
  "person_id": "EMP001",
  "name": "Harsh Kumar",
  "image_url": "s3://face-embeddings/...",
  "face_quality_score": 0.92,
  "created_at": "2024-01-15T10:35:00Z"
}

## Register Multiple Faces for Same Person
POST http://localhost:8000/api/face/register
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: multipart/form-data

person_id: EMP001
name: Harsh Kumar
image: @/path/to/harsh_photo_2.jpg
metadata: {}

---

## Recognize Faces (Upload Frame)
POST http://localhost:8000/api/face/recognize
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: multipart/form-data

image: @/path/to/test_frame.jpg
threshold: 0.5
return_bboxes: true

### Expected Response (200)
{
  "faces_detected": 2,
  "recognized": [
    {
      "person_id": "EMP001",
      "name": "Harsh Kumar",
      "confidence": 0.96,
      "bbox": [100, 150, 250, 350],
      "embedding_id": "770e8400-e29b-41d4-a716-446655440000"
    },
    {
      "person_id": "EMP002",
      "name": "John Doe",
      "confidence": 0.88,
      "bbox": [400, 200, 550, 450],
      "embedding_id": "880e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "unrecognized_count": 0,
  "processing_time_ms": 245.67
}

## List Registered Embeddings
GET http://localhost:8000/api/face/embeddings?skip=0&limit=100
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Optional filters:
GET http://localhost:8000/api/face/embeddings?person_id=EMP001&skip=0&limit=100

### Expected Response (200)
[
  {
    "id": "770e8400-e29b-41d4-a716-446655440000",
    "person_id": "EMP001",
    "name": "Harsh Kumar",
    "image_url": "s3://face-embeddings/...",
    "face_quality_score": 0.92,
    "embedding_dim": 512,
    "face_angle": "frontal",
    "created_at": "2024-01-15T10:35:00Z",
    "updated_at": "2024-01-15T10:35:00Z"
  }
]

## Get Recognition Logs
GET http://localhost:8000/api/face/logs?skip=0&limit=100
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
[
  {
    "id": "990e8400-e29b-41d4-a716-446655440000",
    "recognized_person_id": "EMP001",
    "confidence": 0.96,
    "source": "api",
    "timestamp": "2024-01-15T10:40:00Z"
  }
]

## Delete Embedding
DELETE http://localhost:8000/api/face/embeddings/770e8400-e29b-41d4-a716-446655440000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
{
  "message": "Embedding deleted successfully"
}

---

# Admin Endpoints

## Get Analytics
GET http://localhost:8000/api/admin/analytics
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
{
  "total_tenants": 1,
  "total_users": 5,
  "total_face_embeddings": 42,
  "total_recognition_logs": 156,
  "total_api_calls": 1024,
  "recognitions_today": 25,
  "faces_registered_today": 3
}

## List All Users
GET http://localhost:8000/api/admin/users?skip=0&limit=100
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "email": "harsh@company.com",
    "full_name": "Harsh Kumar",
    "role": "user",
    "tenant_id": "660e8400-e29b-41d4-a716-446655440000",
    "is_active": true,
    "created_at": "2024-01-15T10:30:00Z",
    "face_embeddings_count": 3
  }
]

## Delete User (Admin Only)
DELETE http://localhost:8000/api/admin/users/550e8400-e29b-41d4-a716-446655440000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

### Expected Response (200)
{
  "message": "User deleted successfully"
}

---

# Health & Status

## Health Check
GET http://localhost:8000/health

### Expected Response (200)
{
  "status": "healthy",
  "app": "Face Inference SaaS Platform",
  "version": "1.0.0"
}

## Root Info
GET http://localhost:8000/

### Expected Response (200)
{
  "app": "Face Inference SaaS Platform",
  "version": "1.0.0",
  "docs": "/docs",
  "openapi_schema": "/openapi.json"
}

---

# Error Responses

## Invalid Credentials (401)
{
  "detail": "Invalid email or password"
}

## Unauthorized (401)
{
  "detail": "Not authenticated"
}

## Forbidden (403)
{
  "detail": "Admin access required"
}

## Not Found (404)
{
  "detail": "Embedding not found"
}

## Validation Error (422)
{
  "detail": [
    {
      "loc": ["body", "email"],
      "msg": "invalid email format",
      "type": "value_error.email"
    }
  ]
}

## No Faces Detected (400)
{
  "detail": "No faces detected in image"
}

## Server Error (500)
{
  "detail": "Face recognition failed"
}