FaceApp Content Verification API: code examples (draft)
These examples follow the API description: POST /api/v1/verification and DELETE /api/v1/token, MessagePack bodies, the error code in the faceapp-error header. The Authorization: Bearer header is still a proposal there.
Each example is one small program with two commands:
verify <image>sends the image and printswatermark_detected.revokerevokes the token. After that, every request with this token is rejected withtoken_revoked.
Both read the token from the FACEAPP_CV_TOKEN environment variable. Get the token on the page /auth first.
TypeScript
Node.js 22.18 or later runs the file as is. It uses the built-in fetch and @msgpack/msgpack.
npm install @msgpack/msgpack
export FACEAPP_CV_TOKEN="<your token>"
node verify.ts verify photo.jpg
node verify.ts revoke
verify.ts:
import { readFile } from "node:fs/promises";
import { decode, encode } from "@msgpack/msgpack";
const BASE_URL = "https://content-verification.faceapp.cloud/api/v1";
const MSGPACK = "application/vnd.msgpack";
type VerificationResult = { watermark_detected: boolean };
function toError(response: Response): Error {
const code = response.headers.get("faceapp-error") ?? "no error code";
const retryAfter = response.headers.get("Retry-After");
const retry = retryAfter === null ? "" : ` (retry after ${retryAfter} s)`;
return new Error(`${response.status} ${code}${retry}`);
}
async function verifyImage(token: string, path: string): Promise<VerificationResult> {
const response = await fetch(`${BASE_URL}/verification`, {
method: "POST",
headers: { Authorization: `Bearer ${token}`, "Content-Type": MSGPACK },
body: encode({ image: await readFile(path) }),
});
if (!response.ok) throw toError(response);
return decode(new Uint8Array(await response.arrayBuffer())) as VerificationResult;
}
async function revokeToken(token: string): Promise<void> {
const response = await fetch(`${BASE_URL}/token`, {
method: "DELETE",
headers: { Authorization: `Bearer ${token}` },
});
if (!response.ok) throw toError(response);
}
const token = process.env.FACEAPP_CV_TOKEN;
if (!token) throw new Error("Set FACEAPP_CV_TOKEN to your token.");
const [command, path] = process.argv.slice(2);
if (command === "verify" && path) {
const result = await verifyImage(token, path);
console.log(`watermark_detected: ${result.watermark_detected}`);
} else if (command === "revoke") {
await revokeToken(token);
console.log("Token revoked.");
} else {
console.error("Usage: node verify.ts verify <image> | node verify.ts revoke");
process.exitCode = 2;
}
package.json (TypeScript and @types/node are needed only for type checking):
{"name":"faceapp-content-verification-example","private":true,"type":"module","dependencies":{"@msgpack/msgpack":"^3.1.3"},"devDependencies":{"@types/node":"^24.19.4","typescript":"^5.9.3"}}
Python
Python 3.10 or later, with requests and msgpack. The script declares its dependencies, so uv run installs them.
export FACEAPP_CV_TOKEN="<your token>"
uv run verify.py verify photo.jpg
uv run verify.py revoke
verify.py:
# /// script
# requires-python = ">=3.10"
# dependencies = ["msgpack>=1.0", "requests>=2.31"]
# ///
"""Verify an image or revoke a token with the FaceApp Content Verification API."""
import os
import sys
from pathlib import Path
from typing import Any
import msgpack
import requests
BASE_URL = "https://content-verification.faceapp.cloud/api/v1"
MSGPACK = "application/vnd.msgpack"
TIMEOUT_SECONDS = 60
def raise_for_error(response: requests.Response) -> None:
if response.ok:
return
code = response.headers.get("faceapp-error", "no error code")
retry_after = response.headers.get("Retry-After")
retry = f" (retry after {retry_after} s)" if retry_after else ""
raise RuntimeError(f"{response.status_code} {code}{retry}")
def verify_image(token: str, path: Path) -> dict[str, Any]:
response = requests.post(
f"{BASE_URL}/verification",
headers={"Authorization": f"Bearer {token}", "Content-Type": MSGPACK},
data=msgpack.packb({"image": path.read_bytes()}),
timeout=TIMEOUT_SECONDS,
)
raise_for_error(response)
return msgpack.unpackb(response.content)
def revoke_token(token: str) -> None:
response = requests.delete(
f"{BASE_URL}/token",
headers={"Authorization": f"Bearer {token}"},
timeout=TIMEOUT_SECONDS,
)
raise_for_error(response)
def main() -> None:
token = os.environ.get("FACEAPP_CV_TOKEN")
if not token:
sys.exit("Set FACEAPP_CV_TOKEN to your token.")
match sys.argv[1:]:
case ["verify", path]:
result = verify_image(token, Path(path))
print(f"watermark_detected: {str(result['watermark_detected']).lower()}")
case ["revoke"]:
revoke_token(token)
print("Token revoked.")
case _:
sys.exit("Usage: uv run verify.py verify <image> | uv run verify.py revoke")
if __name__ == "__main__":
main()