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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
# T2M API Documentation

## Overview

This document provides comprehensive documentation for the T2M (Text-to-Media) API endpoints. The API is organized into several modules: Authentication, Files, Jobs, System, and Videos.

## Base URL

```

https://your-api-domain.com/api/v1

```

## Authentication

Most endpoints require authentication. Include the authorization token in the request headers:

```

Authorization: Bearer <your-token>

```

**Public endpoints** (no authentication required):

- `GET /auth/health`
- `GET /system/health`

**Optional authentication** (enhanced data for authenticated users):

- All other `/system/*` endpoints

## Common Response Formats

### Success Response

```json

{

  "success": true,

  "data": {

    "id": "12345",

    "status": "completed"

  },

  "message": "Operation completed successfully"

}

```

### Error Response

```json

{

  "success": false,

  "error": {

    "code": "AUTH_INVALID",

    "details": "Token has expired or is malformed"

  }

}

```

### Pagination Format

```json

{

  "success": true,

  "data": {

    "items": [...],

    "pagination": {

      "page": 1,

      "items_per_page": 20,

      "total_items": 150,

      "total_pages": 8,

      "has_next": true,

      "has_previous": false,

      "next_page": 2,

      "previous_page": null

    }

  }

}

```

## Authentication Endpoints

### Health Check

- **Endpoint**: `GET /auth/health`
- **Description**: Check authentication service health
- **Authentication**: Not required
- **Response**: Service health status
- **Example Response**:

```json

{

  "status": "healthy",

  "clerk": {

    "status": "healthy",

    "response_time": "45ms",

    "last_check": "2024-01-15T10:30:00Z"

  },

  "message": "Authentication service health check completed"

}

```

### Get Authentication Status

- **Endpoint**: `GET /auth/status`
- **Description**: Get current user authentication status
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Authentication status and user info
- **Example Response (Authenticated)**:

```json

{

  "authenticated": true,

  "user_id": "user_12345",

  "email": "[email protected]",

  "email_verified": true,

  "request_context": {

    "path": "/auth/status",

    "method": "GET",

    "client_ip": "192.168.1.100"

  }

}

```

- **Example Response (Not Authenticated)**:

```json

{

  "authenticated": false,

  "message": "No authentication provided",

  "request_context": {

    "path": "/auth/status",

    "method": "GET",

    "client_ip": "192.168.1.100"

  }

}

```

### Get Current User Profile

- **Endpoint**: `GET /auth/me`
- **Description**: Get authenticated user's profile information
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: User profile data
- **Example Response**:

```json

{

  "id": "user_12345",

  "username": "john_doe",

  "full_name": "John Doe",

  "email": "[email protected]",

  "image_url": "https://example.com/avatar.jpg",

  "email_verified": true,

  "created_at": "2024-01-01T00:00:00Z",

  "last_sign_in_at": "2024-01-15T10:30:00Z"

}

```

**Note**: `created_at` and `last_sign_in_at` fields may be `null` if not available from the authentication provider.

### Get User Permissions

- **Endpoint**: `GET /auth/permissions`
- **Description**: Get user's permissions and access levels
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: User permissions and role information
- **Example Response**:

```json

{

  "user_id": "user_12345",

  "role": "USER",

  "permissions": [

    "read_files",

    "upload_files",

    "generate_videos"

  ],

  "access_level": "standard"

}

```

### Test Protected Endpoint

- **Endpoint**: `GET /auth/test-protected`
- **Description**: Test endpoint for authenticated users
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: Test response with user ID
- **Example Response**:

```json

{

  "message": "Successfully accessed protected endpoint",

  "user_id": "user_12345",

  "timestamp": "2024-01-15T10:30:00Z"

}

```

### Test Verified Endpoint

- **Endpoint**: `GET /auth/test-verified`
- **Description**: Test endpoint for verified users only
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: Test response for verified users
- **Example Response**:

```json

{

  "message": "Successfully accessed verified user endpoint",

  "user_id": "user_12345",

  "email": "[email protected]",

  "email_verified": true,

  "timestamp": "2024-01-15T10:30:00Z"

}

```

### Verify Token

- **Endpoint**: `POST /auth/verify`
- **Description**: Verify authentication token validity
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: Token verification status
- **Example Response**:

```json

{

  "verified": true,

  "user_id": "user_12345",

  "email": "[email protected]",

  "email_verified": true,

  "message": "Token verified successfully"

}

```

## File Management Endpoints

### Upload Single File

- **Endpoint**: `POST /files/upload`
- **Description**: Upload a single file
- **Headers**:
  - `Authorization: Bearer <token>` (required)
  - `Content-Type: multipart/form-data`
- **Parameters**:
  - `file` (file, required): File to upload
  - `file_type` (string, optional): File type category
  - `subdirectory` (string, optional): Target subdirectory
  - `description` (string, optional): File description
- **Response**: File upload confirmation with file ID

### Batch Upload Files

- **Endpoint**: `POST /files/batch-upload`
- **Description**: Upload multiple files at once
- **Headers**:
  - `Authorization: Bearer <token>` (required)
  - `Content-Type: multipart/form-data`
- **Parameters**:
  - `files` (file[], required): Files to upload
  - `file_type` (string, optional): File type for all files
  - `subdirectory` (string, optional): Subdirectory for all files
  - `description` (string, optional): Description for all files
- **Response**: Batch upload results

### List Files

- **Endpoint**: `GET /files`
- **Description**: List user's files with pagination and filtering
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Query Parameters**:

| Name             | Type    | Required | Default | Description                                         |
| ---------------- | ------- | -------- | ------- | --------------------------------------------------- |
| `file_type`      | string  | no       | -       | Filter by file type (document, image, video, audio) |
| `page`           | integer | no       | 1       | Page number (≥1)                                    |
| `items_per_page` | integer | no       | 20      | Items per page (1-100)                              |

- **Response**: Paginated list of files
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "items": [

      {

        "id": "file_123456",

        "filename": "document.pdf",

        "size": 2048576,

        "file_type": "document",

        "created_at": "2024-01-15T10:30:00Z"

      }

    ],

    "pagination": {

      "page": 1,

      "items_per_page": 20,

      "total_items": 150,

      "total_pages": 8,

      "has_next": true

    }

  }

}

```

### Get File Details

- **Endpoint**: `GET /files/{file_id}`
- **Description**: Get comprehensive file information including content details and metadata
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Response**: Complete file details
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "id": "file_123456",

    "filename": "document.pdf",

    "size": 2048576,

    "content_type": "application/pdf",

    "file_type": "document",

    "subdirectory": "uploads/2024",

    "description": "Important document",

    "created_at": "2024-01-15T10:30:00Z",

    "updated_at": "2024-01-15T10:30:00Z",

    "download_count": 5,

    "metadata": {

      "pages": 10,

      "author": "John Doe",

      "creation_date": "2024-01-15"

    }

  }

}

```

### Get File Metadata

- **Endpoint**: `GET /files/{file_id}/metadata`
- **Description**: Get file metadata and technical information only
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Response**: File metadata only
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "content_type": "application/pdf",

    "size": 2048576,

    "checksum": "sha256:abc123...",

    "metadata": {

      "pages": 10,

      "author": "John Doe",

      "creation_date": "2024-01-15"

    }

  }

}

```

### Download File

- **Endpoint**: `GET /files/{file_id}/download`
- **Description**: Download file content
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Query Parameters**:
  - `inline` (boolean, default: false): Serve inline instead of attachment
- **Response**: File content

### Stream File

- **Endpoint**: `GET /files/{file_id}/stream`
- **Description**: Stream file content
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Query Parameters**:
  - `quality` (string, default: "auto"): Stream quality
- **Response**: Streamed file content

### Get File Thumbnail

- **Endpoint**: `GET /files/{file_id}/thumbnail`
- **Description**: Get file thumbnail
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Query Parameters**:
  - `size` (string, default: "medium"): Thumbnail size (small|medium|large)
- **Response**: Thumbnail image

### Get File Analytics

- **Endpoint**: `GET /files/{file_id}/analytics`
- **Description**: Get file usage analytics
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Response**: File analytics data

### Delete File

- **Endpoint**: `DELETE /files/{file_id}`
- **Description**: Delete a file
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `file_id` (string, required): Unique file identifier
- **Response**: Deletion confirmation

### Get File Statistics

- **Endpoint**: `GET /files/stats`
- **Description**: Get user's file statistics
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Response**: File usage statistics

### Cleanup Files

- **Endpoint**: `POST /files/cleanup`
- **Description**: Cleanup files based on criteria
- **Headers**:
  - `Authorization: Bearer <token>` (required)
  - `Content-Type: application/json`
- **Request Body**: File cleanup criteria
- **Response**: Cleanup results

### Secure File Access

- **Endpoint**: `GET /files/secure/{file_id}`
- **Description**: Access files via signed URLs
- **Query Parameters**:
  - `user_id` (string, required): User ID from signed URL
  - `expires` (string, required): Expiration timestamp
  - `signature` (string, required): URL signature
  - `file_type` (string, optional): File type
  - `inline` (string, default: "false"): Serve inline
  - `size` (string, optional): Thumbnail size
  - `quality` (string, optional): Stream quality
- **Response**: Secure file access

## Job Management Endpoints

### List Jobs

- **Endpoint**: `GET /jobs`
- **Description**: List user's jobs with pagination and filtering
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Query Parameters**: Pagination and filtering parameters
- **Response**: Paginated list of jobs

### Get Job Details

- **Endpoint**: `GET /jobs/{job_id}`
- **Description**: Get comprehensive job information including status, progress, and results
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Response**: Complete job details and status
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "id": "job_789012",

    "type": "video_generation",

    "status": "completed",

    "progress": 100,

    "created_at": "2024-01-15T10:30:00Z",

    "started_at": "2024-01-15T10:30:05Z",

    "completed_at": "2024-01-15T10:35:30Z",

    "duration": 325,

    "parameters": {

      "prompt": "A beautiful sunset over mountains",

      "duration": 10,

      "quality": "1080p"

    },

    "result": {

      "file_id": "video_456789",

      "file_size": 15728640,

      "thumbnail_url": "/videos/job_789012/thumbnail"

    },

    "error": null

  }

}

```

### Get Job Logs

- **Endpoint**: `GET /jobs/{job_id}/logs`
- **Description**: Get job execution logs with filtering and pagination
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Query Parameters**:

| Name     | Type    | Required | Default | Description                                       |
| -------- | ------- | -------- | ------- | ------------------------------------------------- |
| `limit`  | integer | no       | 100     | Maximum log entries (1-1000)                      |
| `offset` | integer | no       | 0       | Log entries to skip (≥0)                          |
| `level`  | string  | no       | -       | Filter by log level (DEBUG, INFO, WARNING, ERROR) |

- **Response**: Job logs with metadata
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "logs": [

      {

        "timestamp": "2024-01-15T10:30:15Z",

        "level": "INFO",

        "message": "Video processing started",

        "details": {

          "step": "initialization",

          "progress": 0

        }

      },

      {

        "timestamp": "2024-01-15T10:30:45Z",

        "level": "INFO",

        "message": "Processing frame 100/1000",

        "details": {

          "step": "rendering",

          "progress": 10

        }

      }

    ],

    "total_logs": 250,

    "has_more": true

  }

}

```

### Cancel Job

- **Endpoint**: `POST /jobs/{job_id}/cancel`
- **Description**: Cancel a running job
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Response**: Cancellation confirmation

### Delete Job

- **Endpoint**: `DELETE /jobs/{job_id}`
- **Description**: Delete a job and its data
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Response**: Deletion confirmation

## System Monitoring Endpoints

### System Health Check

- **Endpoint**: `GET /system/health`
- **Description**: Get overall system health status
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: System health metrics

### System Metrics

- **Endpoint**: `GET /system/metrics`
- **Description**: Get detailed system metrics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: System performance metrics

### Queue Status

- **Endpoint**: `GET /system/queue`
- **Description**: Get job queue status and statistics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Queue status and metrics

### Cache Information

- **Endpoint**: `GET /system/cache`
- **Description**: Get cache status and information
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Cache metrics and status

### Cache Metrics

- **Endpoint**: `GET /system/cache/metrics`
- **Description**: Get detailed cache metrics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Cache performance metrics

### Cache Report

- **Endpoint**: `GET /system/cache/report`
- **Description**: Get comprehensive cache report
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Detailed cache report

### Performance Summary

- **Endpoint**: `GET /system/performance`
- **Description**: Get system performance summary
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Query Parameters**:
  - `hours` (integer, default: 1): Time range in hours
- **Response**: Performance summary

### Connection Statistics

- **Endpoint**: `GET /system/connections`
- **Description**: Get connection statistics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Connection metrics

### Async Statistics

- **Endpoint**: `GET /system/async`
- **Description**: Get asynchronous processing statistics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Async processing metrics

### Deduplication Statistics

- **Endpoint**: `GET /system/deduplication`
- **Description**: Get deduplication statistics
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Deduplication metrics

### Invalidate Cache

- **Endpoint**: `POST /system/cache/invalidate`
- **Description**: Invalidate cache entries
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Query Parameters**:
  - `pattern` (string, optional): Cache key pattern
  - `user_id` (string, optional): User-specific cache
- **Response**: Cache invalidation results

### Warm Cache

- **Endpoint**: `POST /system/cache/warm`
- **Description**: Pre-warm cache with frequently accessed data
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Cache warming results

### Optimize Performance

- **Endpoint**: `POST /system/optimize`
- **Description**: Trigger system performance optimization
- **Headers**:
  - `Authorization: Bearer <token>` (optional)
- **Response**: Optimization results

## Video Processing Endpoints

### Generate Video

- **Endpoint**: `POST /videos/generate`
- **Description**: Create a new video generation job
- **Headers**:
  - `Authorization: Bearer <token>` (required)
  - `Content-Type: application/json`
- **Request Body**: Job creation parameters
- **Response**: Job creation confirmation with job ID

### Get Job Status

- **Endpoint**: `GET /videos/{job_id}/status`
- **Description**: Get video generation job status
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Response**: Job status and progress

### Download Video

- **Endpoint**: `GET /videos/{job_id}/download`
- **Description**: Download generated video
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Query Parameters**:
  - `inline` (boolean, default: false): Serve inline instead of attachment
- **Response**: Video file content

### Stream Video

- **Endpoint**: `GET /videos/{job_id}/stream`
- **Description**: Stream generated video
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Query Parameters**:
  - `quality` (string, default: "auto"): Stream quality (auto|720p|1080p)
- **Response**: Streamed video content

### Get Video Metadata

- **Endpoint**: `GET /videos/{job_id}/metadata`
- **Description**: Get comprehensive video metadata and technical information
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Response**: Detailed video metadata
- **Example Response**:

```json

{

  "success": true,

  "data": {

    "job_id": "job_789012",

    "video": {

      "duration": 10.5,

      "width": 1920,

      "height": 1080,

      "fps": 30,

      "bitrate": 5000000,

      "codec": "h264",

      "format": "mp4",

      "file_size": 15728640

    },

    "audio": {

      "codec": "aac",

      "bitrate": 128000,

      "sample_rate": 44100,

      "channels": 2

    },

    "generation": {

      "prompt": "A beautiful sunset over mountains",

      "model": "t2v-v2.1",

      "seed": 12345,

      "created_at": "2024-01-15T10:30:00Z"

    }

  }

}

```

### Get Video Thumbnail

- **Endpoint**: `GET /videos/{job_id}/thumbnail`
- **Description**: Get video thumbnail
- **Headers**:
  - `Authorization: Bearer <token>` (required)
- **Path Parameters**:
  - `job_id` (string, required): Unique job identifier
- **Query Parameters**:
  - `size` (string, default: "medium"): Thumbnail size (small|medium|large)
- **Response**: Video thumbnail image

## Error Handling

### Error Codes

| Code                  | HTTP Status | Description                     |
| --------------------- | ----------- | ------------------------------- |
| `AUTH_REQUIRED`       | 401         | Authentication required         |
| `AUTH_INVALID`        | 401         | Invalid authentication token    |
| `AUTH_EXPIRED`        | 401         | Authentication token expired    |
| `PERMISSION_DENIED`   | 403         | Insufficient permissions        |
| `RESOURCE_NOT_FOUND`  | 404         | Requested resource not found    |
| `VALIDATION_ERROR`    | 400         | Request validation failed       |
| `RATE_LIMIT_EXCEEDED` | 429         | Rate limit exceeded             |
| `SERVER_ERROR`        | 500         | Internal server error           |
| `SERVICE_UNAVAILABLE` | 503         | Service temporarily unavailable |

### Error Response Examples

**Invalid Authentication (401)**

```json

{

  "success": false,

  "error": {

    "code": "AUTH_INVALID",

    "details": "Token has expired or is malformed"

  }

}

```

**Resource Not Found (404)**

```json

{

  "success": false,

  "error": {

    "code": "RESOURCE_NOT_FOUND",

    "message": "File not found",

    "details": "File with ID 'file_123456' does not exist or you don't have access"

  }

}

```

**Validation Error (400)**

```json

{

  "success": false,

  "error": {

    "code": "VALIDATION_ERROR",

    "message": "Request validation failed",

    "details": {

      "file_type": [

        "Invalid file type. Must be one of: document, image, video, audio"

      ],

      "page": ["Page must be greater than 0"]

    }

  }

}

```

**Rate Limit Exceeded (429)**

```json

{

  "success": false,

  "error": {

    "code": "RATE_LIMIT_EXCEEDED",

    "message": "Rate limit exceeded",

    "details": "You have exceeded the limit of 100 uploads per hour. Try again in 45 minutes."

  }

}

```

## Rate Limits

- **General API**: 1000 requests per hour per user
- **File Upload**: 100 uploads per hour per user
- **Video Generation**: 10 jobs per hour per user
- **System Endpoints**: 500 requests per hour per user

## Code Examples

### cURL Examples

**Upload a file**

```bash

curl -X POST "https://api.example.com/api/v1/files/upload" \

  -H "Authorization: Bearer your-token-here" \

  -F "[email protected]" \

  -F "file_type=document" \

  -F "description=Sample document"

```

**Generate video**

```bash

curl -X POST "https://api.example.com/api/v1/videos/generate" \

  -H "Authorization: Bearer your-token-here" \

  -H "Content-Type: application/json" \

  -d '{

    "prompt": "A beautiful sunset over mountains",

    "duration": 10,

    "quality": "1080p"

  }'

```

**Get job status**

```bash

curl -X GET "https://api.example.com/api/v1/jobs/job_789012" \

  -H "Authorization: Bearer your-token-here"

```

**Get system metrics**

```bash

curl -X GET "https://api.example.com/api/v1/system/metrics" \

  -H "Authorization: Bearer your-token-here"

```

### Python Examples

**File Management**

```python

import requests



headers = {"Authorization": "Bearer your-token-here"}

base_url = "https://api.example.com/api/v1"



# Upload file

with open("example.txt", "rb") as f:

    files = {"file": f}

    data = {"file_type": "document", "description": "Sample document"}

    response = requests.post(f"{base_url}/files/upload", headers=headers, files=files, data=data)

    file_data = response.json()

    print(f"File uploaded: {file_data['data']['id']}")



# List files

response = requests.get(f"{base_url}/files", headers=headers, params={"page": 1, "items_per_page": 10})

files = response.json()

print(f"Found {files['data']['pagination']['total_items']} files")

```

**Job Management**

```python

# Get job logs

job_id = "job_789012"

response = requests.get(f"{base_url}/jobs/{job_id}/logs", headers=headers, params={"limit": 50, "level": "INFO"})

logs = response.json()

print(f"Retrieved {len(logs['data']['logs'])} log entries")



# Cancel job

response = requests.post(f"{base_url}/jobs/{job_id}/cancel", headers=headers)

if response.json()['success']:

    print("Job cancelled successfully")

```

**Video Processing**

```python

# Generate video

job_data = {

    "prompt": "A beautiful sunset over mountains",

    "duration": 10,

    "quality": "1080p"

}

response = requests.post(f"{base_url}/videos/generate", headers=headers, json=job_data)

job = response.json()

job_id = job['data']['job_id']

print(f"Video generation started: {job_id}")



# Check status

response = requests.get(f"{base_url}/videos/{job_id}/status", headers=headers)

status = response.json()

print(f"Job status: {status['data']['status']} ({status['data']['progress']}%)")

```

**System Monitoring**

```python

# Get system metrics

response = requests.get(f"{base_url}/system/metrics", headers=headers)

metrics = response.json()

print(f"CPU usage: {metrics['data']['cpu_usage']}%")

print(f"Memory usage: {metrics['data']['memory_usage']}%")



# Get queue status

response = requests.get(f"{base_url}/system/queue", headers=headers)

queue = response.json()

print(f"Jobs in queue: {queue['data']['pending_jobs']}")

```

### JavaScript Examples

**File Management**

```javascript

const headers = {

  Authorization: "Bearer your-token-here",

};

const baseUrl = "https://api.example.com/api/v1";



// Upload file

const formData = new FormData();

formData.append("file", fileInput.files[0]);

formData.append("file_type", "document");

formData.append("description", "Sample document");



fetch(`${baseUrl}/files/upload`, {

  method: "POST",

  headers: headers,

  body: formData,

})

  .then((response) => response.json())

  .then((data) => console.log("File uploaded:", data.data.id));



// List files with pagination

fetch(`${baseUrl}/files?page=1&items_per_page=10`, {

  headers: headers,

})

  .then((response) => response.json())

  .then((data) =>

    console.log(`Found ${data.data.pagination.total_items} files`)

  );

```

**Job Management**

```javascript

// Get job logs

const jobId = "job_789012";

fetch(`${baseUrl}/jobs/${jobId}/logs?limit=50&level=INFO`, {

  headers: headers,

})

  .then((response) => response.json())

  .then((data) =>

    console.log(`Retrieved ${data.data.logs.length} log entries`)

  );



// Cancel job

fetch(`${baseUrl}/jobs/${jobId}/cancel`, {

  method: "POST",

  headers: headers,

})

  .then((response) => response.json())

  .then((data) => {

    if (data.success) console.log("Job cancelled successfully");

  });

```

**Video Processing**

```javascript

// Generate video

const jobData = {

  prompt: "A beautiful sunset over mountains",

  duration: 10,

  quality: "1080p",

};



fetch(`${baseUrl}/videos/generate`, {

  method: "POST",

  headers: { ...headers, "Content-Type": "application/json" },

  body: JSON.stringify(jobData),

})

  .then((response) => response.json())

  .then((data) => {

    const jobId = data.data.job_id;

    console.log("Video generation started:", jobId);



    // Poll for status

    const checkStatus = () => {

      fetch(`${baseUrl}/videos/${jobId}/status`, { headers })

        .then((response) => response.json())

        .then((status) => {

          console.log(

            `Status: ${status.data.status} (${status.data.progress}%)`

          );

          if (status.data.status === "processing") {

            setTimeout(checkStatus, 5000); // Check again in 5 seconds

          }

        });

    };

    checkStatus();

  });

```

**System Monitoring**

```javascript

// Get system metrics

fetch(`${baseUrl}/system/metrics`, { headers })

  .then((response) => response.json())

  .then((data) => {

    console.log(`CPU usage: ${data.data.cpu_usage}%`);

    console.log(`Memory usage: ${data.data.memory_usage}%`);

  });



// Get queue status

fetch(`${baseUrl}/system/queue`, { headers })

  .then((response) => response.json())

  .then((data) => console.log(`Jobs in queue: ${data.data.pending_jobs}`));

```

## Support

For API support and questions, please contact:

- Email: [email protected]
- Documentation: https://docs.example.com
- Status Page: https://status.example.com

## Webhooks

The T2M API supports webhook notifications for long-running operations like video generation.

### Webhook Configuration

Configure webhook URLs in your account settings or via the API:

```bash

curl -X POST "https://api.example.com/api/v1/webhooks" \

  -H "Authorization: Bearer your-token-here" \

  -H "Content-Type: application/json" \

  -d '{

    "url": "https://your-app.com/webhooks/t2m",

    "events": ["job.completed", "job.failed"],

    "secret": "your-webhook-secret"

  }'

```

### Webhook Events

| Event           | Description                     |
| --------------- | ------------------------------- |
| `job.started`   | Job processing has begun        |
| `job.progress`  | Job progress update (every 10%) |
| `job.completed` | Job completed successfully      |
| `job.failed`    | Job failed with error           |
| `job.cancelled` | Job was cancelled               |

### Webhook Payload Example

**Job Completed**

```json

{

  "event": "job.completed",

  "timestamp": "2024-01-15T10:35:30Z",

  "data": {

    "job_id": "job_789012",

    "type": "video_generation",

    "status": "completed",

    "result": {

      "file_id": "video_456789",

      "download_url": "https://api.example.com/api/v1/videos/job_789012/download",

      "thumbnail_url": "https://api.example.com/api/v1/videos/job_789012/thumbnail"

    }

  }

}

```

### Webhook Security

Verify webhook authenticity using the signature header:

```python

import hmac

import hashlib



def verify_webhook(payload, signature, secret):

    expected = hmac.new(

        secret.encode('utf-8'),

        payload.encode('utf-8'),

        hashlib.sha256

    ).hexdigest()

    return hmac.compare_digest(f"sha256={expected}", signature)



# In your webhook handler

signature = request.headers.get('X-T2M-Signature')

if verify_webhook(request.body, signature, webhook_secret):

    # Process webhook

    pass

```

## Advanced Features

### Batch Operations

**Batch File Upload**

```bash

curl -X POST "https://api.example.com/api/v1/files/batch-upload" \

  -H "Authorization: Bearer your-token-here" \

  -F "[email protected]" \

  -F "[email protected]" \

  -F "[email protected]" \

  -F "file_type=document"

```

### Signed URLs for Secure Access

Generate temporary signed URLs for file access without authentication:

```python

# Request signed URL

response = requests.post(f"{base_url}/files/{file_id}/signed-url",

                        headers=headers,

                        json={"expires_in": 3600})  # 1 hour

signed_url = response.json()['data']['url']



# Use signed URL (no auth required)

file_response = requests.get(signed_url)

```

### Streaming and Quality Options

**Video Streaming with Quality Selection**

```bash

# Stream in different qualities

curl "https://api.example.com/api/v1/videos/job_789012/stream?quality=720p" \

  -H "Authorization: Bearer your-token-here"

```

**Thumbnail Sizes**

```bash

# Get different thumbnail sizes

curl "https://api.example.com/api/v1/videos/job_789012/thumbnail?size=large" \

  -H "Authorization: Bearer your-token-here"

```

## Performance Optimization

### Caching

The API implements intelligent caching. Use these endpoints to manage cache:

```bash

# Warm cache for better performance

curl -X POST "https://api.example.com/api/v1/system/cache/warm" \

  -H "Authorization: Bearer your-token-here"



# Invalidate specific cache patterns

curl -X POST "https://api.example.com/api/v1/system/cache/invalidate" \

  -H "Authorization: Bearer your-token-here" \

  -d "pattern=user:123:*"

```

### Request Optimization

- Use pagination for large datasets
- Implement client-side caching for frequently accessed data
- Use appropriate quality settings for streaming
- Batch operations when possible

## Monitoring and Analytics

### System Health Monitoring

```bash

# Check overall system health

curl "https://api.example.com/api/v1/system/health"



# Get detailed performance metrics

curl "https://api.example.com/api/v1/system/performance?hours=24" \

  -H "Authorization: Bearer your-token-here"

```

### File Analytics

Track file usage and performance:

```bash

curl "https://api.example.com/api/v1/files/file_123456/analytics" \

  -H "Authorization: Bearer your-token-here"

```

## Migration Guide

### From v1.0 to v1.1

**Breaking Changes:**

- `GET /files/{id}/info` is now `GET /files/{id}` (consolidated endpoints)
- Error response format now includes `details` field
- Pagination format standardized across all endpoints

**New Features:**

- Webhook support for job notifications
- Batch file operations
- Enhanced error details
- Signed URL support

**Migration Steps:**

1. Update endpoint URLs for file info
2. Update error handling to use new format
3. Implement webhook handlers for better UX
4. Use batch operations for improved performance

## Changelog

### v1.1.0 (2024-01-15)

- Added webhook support
- Introduced batch file operations
- Enhanced error responses with details
- Added signed URL generation
- Improved pagination format
- Added system performance endpoints

### v1.0.0 (2023-12-01)

- Initial API release
- Basic CRUD operations for files
- Video generation capabilities
- Job management system
- System monitoring endpoints