truss-image 0.11.1

Image toolkit with a shared Rust core across the CLI, HTTP server, and WASM demo.
Documentation
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
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
openapi: 3.0.3
info:
  title: Truss Image Server API
  version: 0.11.1
  description: |
    HTTP API for the Truss image toolkit.

    Successful transform requests return image bytes directly as `image/*` or
    `image/svg+xml`; they do not return JSON envelopes. Failures are reported as
    RFC 7807 `application/problem+json`.

    Choose an endpoint based on how the source image is supplied:

    - `GET /images/by-path`: public, cache-friendly delivery for files under the
      configured storage root.
    - `GET /images/by-url`: public, cache-friendly delivery for remote HTTP(S)
      sources.
    - `POST /images:transform`: private server-to-server transforms using a JSON body.
    - `POST /images`: private uploads using `multipart/form-data`.

    Common transform options are shared across endpoints. When `format` is omitted,
    the server first tries `Accept` negotiation and otherwise keeps the input format.

    **Watermark compositing** is available on all transform endpoints. Public GET
    endpoints accept `watermarkUrl`, `watermarkPosition`, `watermarkOpacity`, and
    `watermarkMargin` query parameters. The JSON endpoint accepts a `watermark`
    object. The multipart endpoint accepts `watermark`, `watermark_position`,
    `watermark_opacity`, and `watermark_margin` form fields.
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT

servers:
  - url: http://localhost:8080
    description: Local development

tags:
  - name: Transform
    description: Endpoints that fetch or accept an image, apply transform options, and return transformed bytes.
  - name: Health
    description: Lightweight probes for liveness and readiness checks.
  - name: Observability
    description: Operator-facing metrics and runtime diagnostics.

paths:
  /images/by-path:
    get:
      tags: [Transform]
      summary: Transform an image by storage path
      description: |
        Public, cache-friendly transform endpoint for files identified by path.
        Also supports `HEAD` requests, which return the same headers without a body.

        When the storage backend is `filesystem` (default), the `path` query
        parameter is resolved relative to `TRUSS_STORAGE_ROOT`; path traversal
        and out-of-root access are rejected. When the backend is `s3`, `gcs`,
        or `azure`, the path is used as the object key (leading `/` is stripped
        automatically).

        This endpoint requires signed URL authentication through `keyId`,
        `expires`, and `signature`.

        Output selection rules:

        - When `format` is present, that format is requested explicitly and the
          `Accept` header is ignored.
        - When `format` is omitted, the server tries `Accept` negotiation and
          otherwise keeps the input format.
        - When both `width` and `height` are present without `fit`, `contain`
          is applied.
      operationId: transformImageByPath
      security:
        - SignedUrlAuth: []
      parameters:
        - $ref: '#/components/parameters/SourcePath'
        - $ref: '#/components/parameters/SourceVersion'
        - $ref: '#/components/parameters/KeyId'
        - $ref: '#/components/parameters/Expires'
        - $ref: '#/components/parameters/Signature'
        - $ref: '#/components/parameters/Width'
        - $ref: '#/components/parameters/Height'
        - $ref: '#/components/parameters/Fit'
        - $ref: '#/components/parameters/Position'
        - $ref: '#/components/parameters/Format'
        - $ref: '#/components/parameters/Quality'
        - $ref: '#/components/parameters/Optimize'
        - $ref: '#/components/parameters/TargetQuality'
        - $ref: '#/components/parameters/Background'
        - $ref: '#/components/parameters/Rotate'
        - $ref: '#/components/parameters/AutoOrient'
        - $ref: '#/components/parameters/StripMetadata'
        - $ref: '#/components/parameters/PreserveExif'
        - $ref: '#/components/parameters/Crop'
        - $ref: '#/components/parameters/Blur'
        - $ref: '#/components/parameters/Sharpen'
        - $ref: '#/components/parameters/WatermarkUrl'
        - $ref: '#/components/parameters/WatermarkPosition'
        - $ref: '#/components/parameters/WatermarkOpacity'
        - $ref: '#/components/parameters/WatermarkMargin'
        - $ref: '#/components/parameters/Preset'
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '304':
          $ref: '#/components/responses/NotModified'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '508':
          $ref: '#/components/responses/LoopDetected'
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Transform]
      summary: Inspect transformed image headers by storage path
      description: |
        Same contract as `GET /images/by-path`, but returns headers only and no body.
      operationId: headTransformImageByPath
      security:
        - SignedUrlAuth: []
      parameters:
        - $ref: '#/components/parameters/SourcePath'
        - $ref: '#/components/parameters/SourceVersion'
        - $ref: '#/components/parameters/KeyId'
        - $ref: '#/components/parameters/Expires'
        - $ref: '#/components/parameters/Signature'
        - $ref: '#/components/parameters/Width'
        - $ref: '#/components/parameters/Height'
        - $ref: '#/components/parameters/Fit'
        - $ref: '#/components/parameters/Position'
        - $ref: '#/components/parameters/Format'
        - $ref: '#/components/parameters/Quality'
        - $ref: '#/components/parameters/Optimize'
        - $ref: '#/components/parameters/TargetQuality'
        - $ref: '#/components/parameters/Background'
        - $ref: '#/components/parameters/Rotate'
        - $ref: '#/components/parameters/AutoOrient'
        - $ref: '#/components/parameters/StripMetadata'
        - $ref: '#/components/parameters/PreserveExif'
        - $ref: '#/components/parameters/Crop'
        - $ref: '#/components/parameters/Blur'
        - $ref: '#/components/parameters/Sharpen'
        - $ref: '#/components/parameters/WatermarkUrl'
        - $ref: '#/components/parameters/WatermarkPosition'
        - $ref: '#/components/parameters/WatermarkOpacity'
        - $ref: '#/components/parameters/WatermarkMargin'
        - $ref: '#/components/parameters/Preset'
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '304':
          $ref: '#/components/responses/NotModified'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '508':
          $ref: '#/components/responses/LoopDetected'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /images/by-url:
    get:
      tags: [Transform]
      summary: Transform an image from a remote URL
      description: |
        Public, cache-friendly transform endpoint for remote HTTP(S) sources.
        Also supports `HEAD` requests, which return the same headers without a body.

        Use this when the source image is hosted elsewhere and should be fetched by
        Truss on demand. Remote fetches are subject to URL validation, redirect
        limits, and source size limits.

        This endpoint requires signed URL authentication through `keyId`,
        `expires`, and `signature`.

        Output selection rules:

        - When `format` is present, that format is requested explicitly and the
          `Accept` header is ignored.
        - When `format` is omitted, the server tries `Accept` negotiation and
          otherwise keeps the input format.
        - When both `width` and `height` are present without `fit`, `contain`
          is applied.
      operationId: transformImageByUrl
      security:
        - SignedUrlAuth: []
      parameters:
        - $ref: '#/components/parameters/SourceUrl'
        - $ref: '#/components/parameters/SourceVersion'
        - $ref: '#/components/parameters/KeyId'
        - $ref: '#/components/parameters/Expires'
        - $ref: '#/components/parameters/Signature'
        - $ref: '#/components/parameters/Width'
        - $ref: '#/components/parameters/Height'
        - $ref: '#/components/parameters/Fit'
        - $ref: '#/components/parameters/Position'
        - $ref: '#/components/parameters/Format'
        - $ref: '#/components/parameters/Quality'
        - $ref: '#/components/parameters/Optimize'
        - $ref: '#/components/parameters/TargetQuality'
        - $ref: '#/components/parameters/Background'
        - $ref: '#/components/parameters/Rotate'
        - $ref: '#/components/parameters/AutoOrient'
        - $ref: '#/components/parameters/StripMetadata'
        - $ref: '#/components/parameters/PreserveExif'
        - $ref: '#/components/parameters/Crop'
        - $ref: '#/components/parameters/Blur'
        - $ref: '#/components/parameters/Sharpen'
        - $ref: '#/components/parameters/WatermarkUrl'
        - $ref: '#/components/parameters/WatermarkPosition'
        - $ref: '#/components/parameters/WatermarkOpacity'
        - $ref: '#/components/parameters/WatermarkMargin'
        - $ref: '#/components/parameters/Preset'
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '304':
          $ref: '#/components/responses/NotModified'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '508':
          $ref: '#/components/responses/LoopDetected'
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Transform]
      summary: Inspect transformed image headers by remote URL
      description: |
        Same contract as `GET /images/by-url`, but returns headers only and no body.
      operationId: headTransformImageByUrl
      security:
        - SignedUrlAuth: []
      parameters:
        - $ref: '#/components/parameters/SourceUrl'
        - $ref: '#/components/parameters/SourceVersion'
        - $ref: '#/components/parameters/KeyId'
        - $ref: '#/components/parameters/Expires'
        - $ref: '#/components/parameters/Signature'
        - $ref: '#/components/parameters/Width'
        - $ref: '#/components/parameters/Height'
        - $ref: '#/components/parameters/Fit'
        - $ref: '#/components/parameters/Position'
        - $ref: '#/components/parameters/Format'
        - $ref: '#/components/parameters/Quality'
        - $ref: '#/components/parameters/Optimize'
        - $ref: '#/components/parameters/TargetQuality'
        - $ref: '#/components/parameters/Background'
        - $ref: '#/components/parameters/Rotate'
        - $ref: '#/components/parameters/AutoOrient'
        - $ref: '#/components/parameters/StripMetadata'
        - $ref: '#/components/parameters/PreserveExif'
        - $ref: '#/components/parameters/Crop'
        - $ref: '#/components/parameters/Blur'
        - $ref: '#/components/parameters/Sharpen'
        - $ref: '#/components/parameters/WatermarkUrl'
        - $ref: '#/components/parameters/WatermarkPosition'
        - $ref: '#/components/parameters/WatermarkOpacity'
        - $ref: '#/components/parameters/WatermarkMargin'
        - $ref: '#/components/parameters/Preset'
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '304':
          $ref: '#/components/responses/NotModified'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '508':
          $ref: '#/components/responses/LoopDetected'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /images:transform:
    post:
      tags: [Transform]
      summary: Transform an image by reference
      description: |
        Private server-to-server transform endpoint.

        The request body identifies the source image as a storage path, a remote
        URL, or an object-storage reference (bucket + key) and provides an
        optional `options` object. This is the
        most convenient endpoint for backend callers that want to authenticate with a
        Bearer token instead of generating signed public URLs.

        When `options.format` is omitted, the server tries `Accept` negotiation and
        otherwise keeps the input format.
      operationId: transformImageByReference
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransformImageRequest'
            example:
              source:
                kind: path
                path: /photos/hero.jpg
                version: v3
              options:
                width: 1600
                format: webp
                quality: 82
                optimize: auto
                targetQuality: ssim:0.98
                autoOrient: true
                stripMetadata: true
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '508':
          $ref: '#/components/responses/LoopDetected'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /images:
    post:
      tags: [Transform]
      summary: Transform an uploaded image
      description: |
        Private upload-and-transform endpoint.

        Send a `multipart/form-data` body with a required `file` part containing the
        source image or SVG, plus an optional `options` part containing JSON that
        matches `ImageTransformOptions`.

        This endpoint is useful when the caller already has the source bytes in hand
        and does not want to make the server read from a path or remote URL.
      operationId: transformUploadedImage
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/UploadImageTransformRequest'
            encoding:
              options:
                contentType: application/json
      responses:
        '200':
          $ref: '#/components/responses/ImageBinary'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalError'
        '501':
          $ref: '#/components/responses/NotImplemented'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /health:
    get:
      tags: [Health]
      summary: Comprehensive health diagnostic
      description: |
        Human-oriented diagnostic endpoint that returns version information,
        process uptime, and detailed readiness checks.
        Also supports `HEAD` requests.

        This endpoint always returns 200 OK, even when individual checks fail,
        because it is designed for dashboards and operators who need to see the
        full picture.
      operationId: getHealth
      security:
        - {}
        - BearerAuth: []
      responses:
        '200':
          description: Comprehensive health diagnostic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HealthDiagnosticResponse'
              example:
                status: ok
                service: truss
                version: 0.11.1
                uptimeSeconds: 3600
                checks:
                  - name: storageRoot
                    status: ok
                  - name: cacheDiskFree
                    status: ok
                    freeBytes: 53687091200
                    thresholdBytes: 1073741824
                  - name: transformCapacity
                    status: ok
                    current: 2
                    max: 64
                  - name: memoryUsage
                    status: ok
                    rssBytes: 134217728
                    thresholdBytes: 536870912
                maxInputPixels: 40000000
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Health]
      summary: Inspect comprehensive health diagnostic headers
      description: |
        Same contract as `GET /health`, but returns headers only and no body.
      operationId: headHealth
      security:
        - {}
        - BearerAuth: []
      responses:
        '200':
          description: Comprehensive health diagnostic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HealthDiagnosticResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /health/live:
    get:
      tags: [Health]
      summary: Liveness probe
      description: |
        Lightweight liveness probe for container orchestrators (e.g. Kubernetes
        `livenessProbe`). Returns immediately with minimal information confirming
        the process is running and can serve HTTP. Does not check external
        dependencies. Also supports `HEAD` requests.
      operationId: getLiveHealth
      responses:
        '200':
          description: Process is alive
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LivenessResponse'
              example:
                status: ok
                service: truss
                version: 0.11.1
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Health]
      summary: Inspect liveness probe headers
      description: |
        Same contract as `GET /health/live`, but returns headers only and no body.
      operationId: headLiveHealth
      responses:
        '200':
          description: Process is alive
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LivenessResponse'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /health/ready:
    get:
      tags: [Health]
      summary: Readiness probe
      description: |
        Readiness probe for container orchestrators (e.g. Kubernetes
        `readinessProbe`). Also supports `HEAD` requests. Checks that the server
        is able to accept traffic by verifying the storage root is accessible,
        the cache root (if configured) is accessible, the object-storage backend
        (if configured) is network-reachable, cache disk free space is above the
        configured threshold (`TRUSS_HEALTH_CACHE_MIN_FREE_BYTES`), process memory
        usage is below the configured limit (`TRUSS_HEALTH_MAX_MEMORY_BYTES`),
        and transform capacity is not exhausted.

        During graceful shutdown (after SIGTERM/SIGINT), this endpoint
        immediately returns 503 with a `draining` check set to `fail`, even
        before the drain period (`TRUSS_SHUTDOWN_DRAIN_SECS`, default 10s)
        expires. This allows load balancers and CDN edges to remove the
        instance from rotation before the server stops accepting connections.

        **Platform note:** RSS memory and cache disk free space are read on
        Linux only. On other platforms `TRUSS_HEALTH_MAX_MEMORY_BYTES` and
        `TRUSS_HEALTH_CACHE_MIN_FREE_BYTES` are effectively no-ops — those
        checks are omitted from the response and the remaining checks
        (object-storage reachability, transform capacity, etc.) still apply.

        The object-storage reachability check (S3, GCS, or Azure) confirms
        that the configured bucket/container exists and the service responds to
        requests. It does **not** verify IAM permissions for individual
        objects — a 403 AccessDenied response still counts as "reachable"
        because it proves the service is up and the bucket name is correct.
        Permission errors on actual object reads are surfaced as 403 on the
        transform endpoints.

        Returns 503 Service Unavailable when any check fails, signalling that
        traffic should be routed elsewhere.
      operationId: getReadyHealth
      responses:
        '200':
          description: Server is ready to accept traffic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'
              examples:
                filesystem:
                  summary: Filesystem backend
                  value:
                    status: ok
                    checks:
                      - name: storageRoot
                        status: ok
                s3:
                  summary: S3 backend
                  value:
                    status: ok
                    checks:
                      - name: storageRoot
                        status: ok
                      - name: storageBackend
                        status: ok
                gcs:
                  summary: GCS backend
                  value:
                    status: ok
                    checks:
                      - name: storageRoot
                        status: ok
                      - name: storageBackend
                        status: ok
                azure:
                  summary: Azure Blob Storage backend
                  value:
                    status: ok
                    checks:
                      - name: storageRoot
                        status: ok
                      - name: storageBackend
                        status: ok
        '503':
          description: Server is not ready to accept traffic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'
              examples:
                storageRootFail:
                  summary: Storage root inaccessible
                  value:
                    status: fail
                    checks:
                      - name: storageRoot
                        status: fail
                draining:
                  summary: Graceful shutdown in progress
                  value:
                    status: fail
                    checks:
                      - name: draining
                        status: fail
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Health]
      summary: Inspect readiness probe headers
      description: |
        Same contract as `GET /health/ready`, but returns headers only and no body.
      operationId: headReadyHealth
      responses:
        '200':
          description: Server is ready to accept traffic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'
        '503':
          description: Server is not ready to accept traffic
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'
        '429':
          $ref: '#/components/responses/TooManyRequests'

  /metrics:
    get:
      tags: [Observability]
      summary: Prometheus metrics
      description: |
        Returns metrics in Prometheus text exposition format (version 0.0.4).
        Also supports `HEAD` requests.

        By default, the endpoint does not require authentication. Operators can
        restrict access via `TRUSS_METRICS_TOKEN` (Bearer token) or disable the
        endpoint entirely via `TRUSS_DISABLE_METRICS`.
      operationId: getMetrics
      security:
        - {}
        - BearerAuth: []
      responses:
        '200':
          description: Prometheus text exposition format
          content:
            text/plain:
              schema:
                type: string
              example: |
                # HELP truss_process_up Whether the process is running.
                # TYPE truss_process_up gauge
                truss_process_up 1
                # HELP truss_http_requests_total Total HTTP requests handled.
                # TYPE truss_http_requests_total counter
                truss_http_requests_total 42
                # HELP truss_http_request_duration_seconds HTTP request duration in seconds.
                # TYPE truss_http_request_duration_seconds histogram
                truss_http_request_duration_seconds_bucket{route="/health",le="0.005"} 10
                truss_http_request_duration_seconds_bucket{route="/health",le="+Inf"} 10
                truss_http_request_duration_seconds_sum{route="/health"} 0.002
                truss_http_request_duration_seconds_count{route="/health"} 10
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '429':
          $ref: '#/components/responses/TooManyRequests'
    head:
      tags: [Observability]
      summary: Inspect Prometheus metrics headers
      description: |
        Same contract as `GET /metrics`, but returns headers only and no body.
      operationId: headMetrics
      security:
        - {}
        - BearerAuth: []
      responses:
        '200':
          description: Prometheus text exposition format
          content:
            text/plain:
              schema:
                type: string
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '429':
          $ref: '#/components/responses/TooManyRequests'

components:
  securitySchemes:
    SignedUrlAuth:
      type: apiKey
      in: query
      name: signature
      description: |
        HMAC-SHA256 signed URL authentication.
        Requires `keyId`, `expires`, and `signature` query parameters on public
        image endpoints.

        The canonical form is:
        `METHOD\nAUTHORITY\nREQUEST_PATH\nCANONICAL_QUERY`

        In practice, callers usually generate these URLs with `truss sign` or an
        equivalent implementation that matches the server's canonicalization rules.
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: opaque
      description: |
        Bearer token authentication for private server-to-server and upload endpoints.

  parameters:
    SourcePath:
      name: path
      in: query
      required: true
      description: |
        Source path resolved relative to `TRUSS_STORAGE_ROOT`.
        A leading slash is allowed, but the final resolved path must stay under the
        storage root.
      schema:
        type: string
        minLength: 1
      example: /photos/hero.jpg
    SourceUrl:
      name: url
      in: query
      required: true
      description: |
        Remote HTTP(S) URL to fetch the source image from.
        Private-network and loopback targets may be rejected depending on server configuration.
      schema:
        type: string
        format: uri
      example: https://example.com/images/hero.png
    SourceVersion:
      name: version
      in: query
      required: false
      description: |
        Optional cache-busting version tag for the source.
        This value becomes part of the cache key but is not fetched from the origin.
      schema:
        type: string
        minLength: 1
      example: v3
    KeyId:
      name: keyId
      in: query
      required: true
      description: Key identifier that selects the shared secret used for signed URL verification.
      schema:
        type: string
        minLength: 1
      example: public-demo
    Expires:
      name: expires
      in: query
      required: true
      description: |
        Expiration time as a Unix timestamp in seconds.
        Requests are rejected after this instant.
      schema:
        type: integer
        format: int64
        minimum: 1
      example: 1893456000
    Signature:
      name: signature
      in: query
      required: true
      description: Lowercase hex-encoded HMAC-SHA256 signature
      schema:
        type: string
        minLength: 1
      example: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
    Width:
      name: width
      in: query
      required: false
      description: |
        Requested output width in pixels.
        When `height` is omitted, the image is resized proportionally.
      schema:
        type: integer
        minimum: 1
      example: 1200
    Height:
      name: height
      in: query
      required: false
      description: |
        Requested output height in pixels.
        When `width` is omitted, the image is resized proportionally.
      schema:
        type: integer
        minimum: 1
      example: 630
    Fit:
      name: fit
      in: query
      required: false
      description: |
        Resize strategy. Only meaningful when both width and height are set.
        Defaults to `contain`.

        - `contain`: fit inside the box without cropping
        - `cover`: fill the box, cropping excess
        - `fill`: stretch to the exact box
        - `inside`: like contain, but never upscale
      schema:
        type: string
        enum: [contain, cover, fill, inside]
        default: contain
      example: cover
    Position:
      name: position
      in: query
      required: false
      description: |
        Crop anchor for cover mode and padding placement.
        Only meaningful when both width and height are set.
        Defaults to `center`.
      schema:
        type: string
        enum: [center, top, right, bottom, left, top-left, top-right, bottom-left, bottom-right]
        default: center
      example: top
    Format:
      name: format
      in: query
      required: false
      description: |
        Output image format.
        When present, the `Accept` header is ignored.
        `svg` output is only valid for SVG input.
      schema:
        type: string
        enum: [jpeg, png, webp, avif, bmp, tiff, svg]
      example: webp
    Quality:
      name: quality
      in: query
      required: false
      description: |
        Encoding quality for lossy formats (jpeg, webp, avif).
        Returns 400 for lossless formats.
      schema:
        type: integer
        minimum: 1
        maximum: 100
      example: 82
    Optimize:
      name: optimize
      in: query
      required: false
      description: |
        Optimization mode for the final encoding stage.
        `none` preserves the existing behavior.
        `auto` picks a format-appropriate strategy.
        `lossless` uses only pixel-preserving techniques.
        `lossy` may reduce quality to save more bytes.
      schema:
        type: string
        enum: [none, auto, lossless, lossy]
        default: none
      example: auto
    TargetQuality:
      name: targetQuality
      in: query
      required: false
      description: |
        Perceptual target used by lossy optimization, for example `ssim:0.98`
        or `psnr:42`. Requires `optimize=auto` or `optimize=lossy`.
        SSIM must be in `(0,1]`; PSNR must be greater than `0`.
      schema:
        oneOf:
          - type: string
            pattern: '^ssim:(?:0\.[0-9]*[1-9][0-9]*|1(?:\.0+)?)$'
          - type: string
            pattern: '^psnr:(?:0\.[0-9]*[1-9][0-9]*|[1-9][0-9]*(?:\.[0-9]+)?)$'
      example: ssim:0.98
    Background:
      name: background
      in: query
      required: false
      description: |
        Background color as RRGGBB or RRGGBBAA hex (no leading #).
        Mainly visible when padding or flattening transparency into opaque formats.
      schema:
        type: string
        pattern: '^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$'
      example: ffffff
    Rotate:
      name: rotate
      in: query
      required: false
      description: Rotation in degrees, applied after EXIF auto-orient
      schema:
        type: integer
        enum: [0, 90, 180, 270]
        default: 0
      example: 90
    AutoOrient:
      name: autoOrient
      in: query
      required: false
      description: |
        Apply EXIF orientation when the input provides it, then reset the orientation tag.
        Most useful for JPEG camera images.
      schema:
        type: boolean
        default: true
      example: true
    StripMetadata:
      name: stripMetadata
      in: query
      required: false
      description: |
        Remove metadata from the output when `true`.
        Set this to `false` to keep supported metadata where the output encoder can retain it.
      schema:
        type: boolean
        default: true
      example: true
    PreserveExif:
      name: preserveExif
      in: query
      required: false
      description: |
        Preserve EXIF data only. Requires `stripMetadata=false`.
        When `stripMetadata=false` and `preserveExif=false`, the server keeps all metadata
        that the selected output encoder supports.
        Returns 400 when output format is SVG.
      schema:
        type: boolean
        default: false
      example: false
    Crop:
      name: crop
      in: query
      required: false
      description: |
        Explicit pixel crop as `x,y,width,height`.
        Applied after auto-orient and rotation but before resize.
        The region must fit within the (possibly rotated) source dimensions.
        Not supported for SVG inputs.
      schema:
        type: string
        pattern: '^\d+,\d+,[1-9]\d*,[1-9]\d*$'
      example: "100,50,800,600"
    Preset:
      name: preset
      in: query
      required: false
      description: |
        Name of a server-side transform preset.
        Presets are defined via `TRUSS_PRESETS` or `TRUSS_PRESETS_FILE`.
        Explicit query parameters override preset values.
      schema:
        type: string
        minLength: 1
      example: thumbnail
    Blur:
      name: blur
      in: query
      required: false
      description: |
        Apply Gaussian blur with the given sigma value.
        Valid range is 0.1 to 100.0. Higher values produce a stronger blur.
        Not supported for SVG inputs.
      schema:
        type: number
        format: float
        minimum: 0.1
        maximum: 100.0
      example: 3.0
    Sharpen:
      name: sharpen
      in: query
      required: false
      description: |
        Apply unsharp-mask (sharpen) filter with the given sigma value.
        Valid range is 0.1 to 100.0. Higher values produce stronger sharpening.
        Not supported for SVG inputs.
      schema:
        type: number
        format: float
        minimum: 0.1
        maximum: 100.0
      example: 2.0
    WatermarkUrl:
      name: watermarkUrl
      in: query
      required: false
      description: |
        HTTP(S) URL of a watermark image to composite onto the output.
        Must be a raster format (PNG, JPEG, WebP, BMP, TIFF); SVG is not supported.
        Subject to SSRF protection and the remote watermark size limit
        (`TRUSS_MAX_WATERMARK_BYTES`, default 10 MB).
        For multipart uploads the `watermark` file field has a fixed 10 MB cap.
      schema:
        type: string
        format: uri
      example: https://example.com/logo.png
    WatermarkPosition:
      name: watermarkPosition
      in: query
      required: false
      description: |
        Where to place the watermark on the output image.
        Requires `watermarkUrl` to be set; requests are rejected otherwise.
      schema:
        type: string
        enum: [center, top, right, bottom, left, top-left, top-right, bottom-left, bottom-right]
        default: bottom-right
      example: bottom-right
    WatermarkOpacity:
      name: watermarkOpacity
      in: query
      required: false
      description: |
        Watermark opacity (1–100).
        Requires `watermarkUrl` to be set; requests are rejected otherwise.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
      example: 50
    WatermarkMargin:
      name: watermarkMargin
      in: query
      required: false
      description: |
        Margin in pixels from the nearest edge.
        Requires `watermarkUrl` to be set; requests are rejected otherwise.
      schema:
        type: integer
        minimum: 0
        default: 10
      example: 10

  schemas:
    PathImageSource:
      type: object
      description: Source image stored under the server's configured storage root.
      additionalProperties: false
      required: [kind, path]
      properties:
        kind:
          type: string
          enum: [path]
        path:
          type: string
          minLength: 1
        version:
          type: string
          minLength: 1
      example:
        kind: path
        path: /photos/hero.jpg
        version: v3
    UrlImageSource:
      type: object
      description: Source image fetched from a remote HTTP(S) URL.
      additionalProperties: false
      required: [kind, url]
      properties:
        kind:
          type: string
          enum: [url]
        url:
          type: string
          format: uri
        version:
          type: string
          minLength: 1
      example:
        kind: url
        url: https://example.com/images/hero.png
        version: v3
    StorageImageSource:
      type: object
      description: |
        Source image stored in an S3-compatible, GCS, or Azure Blob Storage
        backend. Requires the `s3`, `gcs`, or `azure` feature and the
        corresponding `TRUSS_STORAGE_BACKEND` value.
      additionalProperties: false
      required: [kind, key]
      properties:
        kind:
          type: string
          enum: [storage]
        bucket:
          type: string
          minLength: 1
          description: >-
            Bucket name (or Azure container name). Defaults to
            `TRUSS_S3_BUCKET`, `TRUSS_GCS_BUCKET`, or `TRUSS_AZURE_CONTAINER`
            when omitted.
        key:
          type: string
          minLength: 1
          description: Object key within the bucket (or Azure container).
        version:
          type: string
          minLength: 1
      example:
        kind: storage
        key: photos/hero.jpg
    ImageSource:
      description: >-
        Exactly one source descriptor: a storage path, a remote URL, or an
        object-storage reference.
      oneOf:
        - $ref: '#/components/schemas/PathImageSource'
        - $ref: '#/components/schemas/UrlImageSource'
        - $ref: '#/components/schemas/StorageImageSource'
      discriminator:
        propertyName: kind
        mapping:
          path: '#/components/schemas/PathImageSource'
          url: '#/components/schemas/UrlImageSource'
          storage: '#/components/schemas/StorageImageSource'
    ImageTransformOptions:
      type: object
      description: |
        Shared transform options used by the JSON and multipart endpoints.
        The same semantics also apply to equivalent query parameters on public GET endpoints.
      additionalProperties: false
      properties:
        width:
          type: integer
          minimum: 1
          description: Requested output width in pixels.
        height:
          type: integer
          minimum: 1
          description: Requested output height in pixels.
        fit:
          type: string
          enum: [contain, cover, fill, inside]
          default: contain
          description: Resize strategy used when both width and height are present.
        position:
          type: string
          enum: [center, top, right, bottom, left, top-left, top-right, bottom-left, bottom-right]
          default: center
          description: Crop anchor or padding placement for bounded resizes.
        format:
          type: string
          enum: [jpeg, png, webp, avif, bmp, tiff, svg]
          description: Explicit output format. When omitted, the server negotiates or keeps the input format.
        quality:
          type: integer
          minimum: 1
          maximum: 100
          description: Quality for lossy outputs (`jpeg`, `webp`, `avif`).
        optimize:
          type: string
          enum: [none, auto, lossless, lossy]
          default: none
          description: Optimization mode for the final encoding stage.
        targetQuality:
          description: >-
            Perceptual target used by lossy optimization, for example
            `ssim:0.98` or `psnr:42`. SSIM must be in `(0,1]`; PSNR must be
            greater than `0`. Requires `optimize=auto` or `optimize=lossy`.
          oneOf:
            - type: string
              pattern: '^ssim:(?:0\.[0-9]*[1-9][0-9]*|1(?:\.0+)?)$'
            - type: string
              pattern: '^psnr:(?:0\.[0-9]*[1-9][0-9]*|[1-9][0-9]*(?:\.[0-9]+)?)$'
        background:
          type: string
          pattern: '^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$'
          description: Background color for padding or flattening transparency.
        rotate:
          type: integer
          enum: [0, 90, 180, 270]
          default: 0
          description: Extra clockwise rotation applied after auto-orientation.
        autoOrient:
          type: boolean
          default: true
          description: Apply EXIF orientation when present.
        stripMetadata:
          type: boolean
          default: true
          description: Remove metadata from the output when `true`.
        preserveExif:
          type: boolean
          default: false
          description: Preserve EXIF only. Requires `stripMetadata=false`.
        crop:
          type: string
          pattern: '^\d+,\d+,[1-9]\d*,[1-9]\d*$'
          description: >-
            Explicit pixel crop as `x,y,width,height`. Applied after auto-orient
            and rotation but before resize. Not supported for SVG inputs.
        blur:
          type: number
          format: float
          minimum: 0.1
          maximum: 100.0
          description: >-
            Gaussian blur sigma (0.1–100.0). Higher values produce a stronger blur.
            Not supported for SVG inputs; the server will reject the request
            with an error if blur is specified for an SVG source.
        sharpen:
          type: number
          format: float
          minimum: 0.1
          maximum: 100.0
          description: >-
            Sharpen sigma (0.1–100.0). Higher values produce stronger sharpening.
            Not supported for SVG inputs; the server will reject the request
            with an error if sharpen is specified for an SVG source.
        preset:
          type: string
          minLength: 1
          description: >-
            Name of a server-side transform preset. Explicit fields override preset values.
      example:
        width: 1600
        height: 900
        fit: cover
        position: center
        format: webp
        quality: 82
        optimize: auto
        targetQuality: ssim:0.98
        autoOrient: true
        stripMetadata: true
    WatermarkPayload:
      type: object
      description: |
        Watermark overlay configuration for the JSON transform endpoint.
        The `url` field is required and must point to a raster image (PNG, JPEG, WebP, BMP, TIFF).
        SVG watermarks are not supported.
      additionalProperties: false
      required: [url]
      properties:
        url:
          type: string
          format: uri
          description: HTTP(S) URL of the watermark image. Subject to SSRF protection.
        position:
          type: string
          enum: [center, top, right, bottom, left, top-left, top-right, bottom-left, bottom-right]
          default: bottom-right
          description: Where to place the watermark on the output image.
        opacity:
          type: integer
          minimum: 1
          maximum: 100
          default: 50
          description: Watermark opacity (1–100).
        margin:
          type: integer
          minimum: 0
          default: 10
          description: Margin in pixels from the nearest edge.
      example:
        url: https://example.com/logo.png
        position: bottom-right
        opacity: 50
        margin: 10
    TransformImageRequest:
      type: object
      description: JSON request body for transforming a path- or URL-based source.
      additionalProperties: false
      required: [source]
      properties:
        source:
          $ref: '#/components/schemas/ImageSource'
        options:
          $ref: '#/components/schemas/ImageTransformOptions'
        watermark:
          $ref: '#/components/schemas/WatermarkPayload'
      example:
        source:
          kind: path
          path: /photos/hero.jpg
        options:
          width: 1600
          format: webp
          quality: 82
          optimize: auto
    UploadImageTransformRequest:
      type: object
      description: |
        Multipart request body containing the source file, optional transform options,
        and optional watermark overlay fields.
      additionalProperties: false
      required: [file]
      properties:
        file:
          type: string
          format: binary
          description: The image or SVG file to transform.
        options:
          $ref: '#/components/schemas/ImageTransformOptions'
        watermark:
          type: string
          format: binary
          description: Watermark image file (PNG, JPEG, WebP, BMP, or TIFF). SVG is not supported.
        watermark_position:
          type: string
          enum: [center, top, right, bottom, left, top-left, top-right, bottom-left, bottom-right]
          default: bottom-right
          description: Where to place the watermark on the output image. Requires a `watermark` file field.
        watermark_opacity:
          type: integer
          minimum: 1
          maximum: 100
          default: 50
          description: Watermark opacity (1–100). Requires a `watermark` file field.
        watermark_margin:
          type: integer
          minimum: 0
          default: 10
          description: Margin in pixels from the nearest edge. Requires a `watermark` file field.
    LivenessResponse:
      type: object
      description: Minimal liveness payload confirming the process is running.
      additionalProperties: false
      required: [status, service, version]
      properties:
        status:
          type: string
          enum: [ok]
        service:
          type: string
          enum: [truss]
        version:
          type: string
          description: Semantic version of the running binary.
          example: "0.11.1"
    ReadinessResponse:
      type: object
      description: Readiness payload with individual dependency checks.
      additionalProperties: false
      required: [status, checks]
      properties:
        status:
          type: string
          enum: [ok, fail]
        checks:
          type: array
          items:
            $ref: '#/components/schemas/HealthCheck'
    HealthDiagnosticResponse:
      type: object
      description: Comprehensive diagnostic payload with version, uptime, and checks.
      additionalProperties: false
      required: [status, service, version, uptimeSeconds, checks, maxInputPixels]
      properties:
        status:
          type: string
          enum: [ok, fail]
        service:
          type: string
          enum: [truss]
        version:
          type: string
          description: Semantic version of the running binary.
          example: "0.11.1"
        uptimeSeconds:
          type: integer
          format: int64
          minimum: 0
          description: Seconds since the server process started.
        checks:
          type: array
          items:
            $ref: '#/components/schemas/HealthCheck'
        maxInputPixels:
          type: integer
          format: int64
          minimum: 1
          description: Maximum input image pixel count allowed before decode.
    HealthCheck:
      type: object
      description: Individual dependency check result.
      additionalProperties: false
      required: [name, status]
      properties:
        name:
          type: string
          description: Name of the checked dependency.
          example: storageRoot
        status:
          type: string
          enum: [ok, fail]
        freeBytes:
          type: integer
          format: int64
          minimum: 0
          description: Free bytes on the cache disk (cacheDiskFree check only).
        thresholdBytes:
          type: integer
          format: int64
          minimum: 1
          description: >-
            Configured threshold in bytes. Present on cacheDiskFree and
            memoryUsage checks when a threshold is configured.
        rssBytes:
          type: integer
          format: int64
          minimum: 0
          description: Process resident set size in bytes (memoryUsage check only, Linux).
        current:
          type: integer
          format: int64
          minimum: 0
          description: Current number of in-flight transforms (transformCapacity check only).
        max:
          type: integer
          format: int64
          minimum: 1
          description: Maximum concurrent transforms allowed (transformCapacity check only).
        recovering:
          type: boolean
          description: Present and `true` while a hysteresis-tracked resource check remains in its recovery margin.
    ProblemDetail:
      type: object
      description: RFC 7807 Problem Details
      required: [type, title, status, detail]
      properties:
        type:
          type: string
          example: "about:blank"
        title:
          type: string
          example: "Bad Request"
        status:
          type: integer
          example: 400
        detail:
          type: string
          example: "missing required query parameter: path"

  responses:
    ImageBinary:
      description: |
        Transformed image or sanitized SVG bytes.
        The exact response media type depends on the selected output format.
      headers:
        Cache-Control:
          description: |
            `public, max-age=3600, stale-while-revalidate=60` for public GET endpoints.
            `no-store` for private endpoints.
          schema:
            type: string
        ETag:
          description: SHA-256 based entity tag in the form `"sha256-<hex>"`
          schema:
            type: string
        Vary:
          description: Set to `Accept` when content negotiation was used
          schema:
            type: string
        Cache-Status:
          description: RFC 9211 cache status (`"truss"; hit` or `"truss"; fwd=miss`)
          schema:
            type: string
        Age:
          description: Seconds since the response was cached (only on cache hits)
          schema:
            type: integer
        X-Content-Type-Options:
          description: Always set to `nosniff`
          schema:
            type: string
        Content-Disposition:
          description: Always `inline; filename="truss.<ext>"`
          schema:
            type: string
        Content-Security-Policy:
          description: Set to `sandbox` for SVG output only
          schema:
            type: string
      content:
        image/jpeg:
          schema:
            type: string
            format: binary
        image/png:
          schema:
            type: string
            format: binary
        image/webp:
          schema:
            type: string
            format: binary
        image/avif:
          schema:
            type: string
            format: binary
        image/bmp:
          schema:
            type: string
            format: binary
        image/tiff:
          schema:
            type: string
            format: binary
        image/svg+xml:
          schema:
            type: string
            format: binary
    NotModified:
      description: ETag matched the If-None-Match header (GET and HEAD)
      headers:
        ETag:
          schema:
            type: string
        Cache-Control:
          schema:
            type: string
        Cache-Status:
          schema:
            type: string
    BadRequest:
      description: Invalid request parameters or body
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
          example:
            type: about:blank
            title: Bad Request
            status: 400
            detail: fit requires both width and height
    Unauthorized:
      description: Authentication failed or missing
      headers:
        WWW-Authenticate:
          description: Set to `Bearer` for Bearer token endpoints
          schema:
            type: string
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    Forbidden:
      description: Access denied (e.g. path traversal attempt)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    NotFound:
      description: Source file or route not found
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    NotAcceptable:
      description: |
        `Accept` header negotiation failed because none of the requested response media types
        matched the formats supported by the server.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    PayloadTooLarge:
      description: Request body or remote source exceeds size limit
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    UnprocessableEntity:
      description: Input image exceeds the configured pixel limit (`TRUSS_MAX_INPUT_PIXELS`)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
          example:
            type: about:blank
            title: Unprocessable Entity
            status: 422
            detail: "input image has 50000000 pixels, server limit is 40000000"
    UnsupportedMediaType:
      description: |
        Unsupported input format, unsupported output format, or wrong request `Content-Type`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    InternalError:
      description: Internal server error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    NotImplemented:
      description: Requested transform is not supported
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    BadGateway:
      description: Remote origin fetch failed
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    ServiceUnavailable:
      description: Server overloaded or required configuration missing
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    TooManyRequests:
      description: Request was rejected by the per-IP rate limiter
      headers:
        Retry-After:
          description: Seconds to wait before retrying the request
          schema:
            type: integer
        X-Request-Id:
          schema:
            type: string
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'
    LoopDetected:
      description: Too many redirects when fetching remote source
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetail'