{
  "openapi": "3.0.3",
  "info": {
    "title": "DFDetect Image Scan API",
    "version": "1.0.0",
    "description": "Analyze a user-authorized JPEG or PNG for face manipulation signals. This mode processes images in memory and does not write image artifacts."
  },
  "servers": [
    {
      "url": "https://api.deepfake-detect.com"
    }
  ],
  "paths": {
    "/v1/upload": {
      "post": {
        "operationId": "analyzeImageForFaceManipulation",
        "summary": "Scan an image for per-face manipulation signals",
        "parameters": [
          {
            "name": "mode",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "scan"
              ],
              "default": "scan"
            },
            "description": "Required for ephemeral processing. The legacy upload API uses the same route with a different retention policy."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "scan_image"
                ],
                "properties": {
                  "scan_image": {
                    "type": "string",
                    "format": "binary",
                    "description": "JPEG or PNG up to 2 MiB and 20 million pixels."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scan completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResult"
                },
                "examples": {
                  "singleFace": {
                    "summary": "One detected face",
                    "value": {
                      "status": "faces_detected",
                      "model_version": "efficientnet-b7-8a205583d43f",
                      "face_count": 1,
                      "image": {
                        "width": 640,
                        "height": 480
                      },
                      "faces": [
                        {
                          "id": 1,
                          "box": {
                            "left": 24,
                            "top": 32,
                            "right": 216,
                            "bottom": 252
                          },
                          "real_face_score": 0.68,
                          "interpretation": "inconclusive"
                        }
                      ]
                    }
                  },
                  "twoFaces": {
                    "summary": "Two detected faces",
                    "value": {
                      "status": "faces_detected",
                      "model_version": "efficientnet-b7-8a205583d43f",
                      "face_count": 2,
                      "image": {
                        "width": 640,
                        "height": 480
                      },
                      "faces": [
                        {
                          "id": 1,
                          "box": {
                            "left": 60,
                            "top": 38,
                            "right": 240,
                            "bottom": 242
                          },
                          "real_face_score": 0.14,
                          "interpretation": "leans_manipulated"
                        },
                        {
                          "id": 2,
                          "box": {
                            "left": 382,
                            "top": 48,
                            "right": 566,
                            "bottom": 248
                          },
                          "real_face_score": 0.91,
                          "interpretation": "leans_real"
                        }
                      ]
                    }
                  },
                  "noFaces": {
                    "summary": "No detected faces",
                    "value": {
                      "status": "no_faces_detected",
                      "model_version": "efficientnet-b7-8a205583d43f",
                      "face_count": 0,
                      "image": {
                        "width": 640,
                        "height": 480
                      },
                      "faces": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing, malformed, or invalid image.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "The image or request exceeds the size limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "The gateway is throttling requests. Back off before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "The scan could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The scan service is temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ScanResult": {
        "type": "object",
        "required": [
          "status",
          "model_version",
          "face_count",
          "image",
          "faces"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "faces_detected",
              "no_faces_detected"
            ]
          },
          "model_version": {
            "type": "string",
            "description": "Identifier for the deployed classification checkpoint.",
            "example": "efficientnet-b7-8a205583d43f"
          },
          "face_count": {
            "type": "integer",
            "minimum": 0
          },
          "image": {
            "type": "object",
            "required": [
              "width",
              "height"
            ],
            "properties": {
              "width": {
                "type": "integer",
                "minimum": 1
              },
              "height": {
                "type": "integer",
                "minimum": 1
              }
            }
          },
          "faces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Face"
            }
          }
        }
      },
      "Face": {
        "type": "object",
        "required": [
          "id",
          "box",
          "real_face_score",
          "interpretation"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "minimum": 1
          },
          "box": {
            "type": "object",
            "required": [
              "left",
              "top",
              "right",
              "bottom"
            ],
            "properties": {
              "left": {
                "type": "integer",
                "minimum": 0
              },
              "top": {
                "type": "integer",
                "minimum": 0
              },
              "right": {
                "type": "integer",
                "minimum": 0
              },
              "bottom": {
                "type": "integer",
                "minimum": 0
              }
            },
            "description": "Pixel coordinates from the upper-left of the decoded image. Right and bottom are exclusive. Boxes include crop margin."
          },
          "real_face_score": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Model score for the real-face class. Treat the score as one signal when evaluating an image."
          },
          "interpretation": {
            "type": "string",
            "enum": [
              "leans_manipulated",
              "inconclusive",
              "leans_real"
            ],
            "description": "Below 0.2 leans manipulated. From 0.2 to below 0.8 is inconclusive. At 0.8 and above the model leans real."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
