PhotoCheck API

PhotoCheck API in Java

To check a photo for AI generation and faces in Java, POST it to https://photocheckapi.com/api/v1/analyze with your key as a Bearer token. The response is JSON with ai.score, faces.count and the file's metadata. The example below is complete and runs as it is.

1. Set your key

shell
export PHOTOCHECK_API_KEY="pc_live_…"

No key yet? Leave the header out: you get 5 keyless calls a day to try it. Credit packs start at $4.95.

2. Check a photo

Java
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
import java.util.UUID;

public class PhotoCheck {
  public static void main(String[] args) throws Exception {
    String boundary = UUID.randomUUID().toString();
    byte[] image = Files.readAllBytes(Path.of("photo.jpg"));
    byte[] head = ("--" + boundary + "\r\n"
        + "Content-Disposition: form-data; name=\"image\"; filename=\"photo.jpg\"\r\n"
        + "Content-Type: image/jpeg\r\n\r\n").getBytes();
    byte[] tail = ("\r\n--" + boundary + "--\r\n").getBytes();

    HttpRequest req = HttpRequest.newBuilder(URI.create("https://photocheckapi.com/api/v1/analyze"))
        .header("Authorization", "Bearer " + System.getenv("PHOTOCHECK_API_KEY"))
        .header("Content-Type", "multipart/form-data; boundary=" + boundary)
        .POST(HttpRequest.BodyPublishers.ofByteArrays(java.util.List.of(head, image, tail)))
        .build();

    HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println(res.statusCode() + " " + res.body());
  }
}

Notes

  • Java 11+ HttpClient, no dependencies. Parse the JSON with Jackson or Gson.
  • Simpler still: send the raw bytes with Content-Type: image/jpeg and skip multipart.
  • Swap /analyze for /faces, /ai-detect or /metadata to run one check. Each costs the same one credit.
  • Branch on error.type rather than the HTTP status alone; the full list is in the error reference.

Other languages

cURL, JavaScript (Node.js), Python, PHP, Go, Ruby, C# (.NET), Rust.