Quickstart

Step 1: Get an API key

Contact the Sylvester team (see Support) to get an API key.

Step 2: Send an image

curl

BASE_URL="https://api.example-sylvester-host"
API_KEY="YOUR_API_KEY"

# Build the JSON body in a file (images are too large for a command-line argument).
printf '{"image":"%s"}' "$(base64 < cat.jpg | tr -d '\n')" > body.json

curl -X POST "$BASE_URL/v2/predict" \
  -H "api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  --data @body.json

Python (requests)

import base64
import requests

BASE_URL = "https://api.example-sylvester-host"
API_KEY = "YOUR_API_KEY"

with open("cat.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode("ascii")

response = requests.post(
    f"{BASE_URL}/v2/predict",
    headers={"api-key": API_KEY},
    json={"image": image_b64},
    timeout=60,
)
response.raise_for_status()
result = response.json()

if result["detection"] == "detected":
    print(result["prediction"]["label"], result["prediction"]["score"])
elif result["detection"] == "low_confidence":
    print("A cat may be present, but the photo isn't clear enough. Ask for a clearer photo.")
else:
    print("No cat found in the photo.")

JavaScript (Node.js 18+ or browser fetch)

import { readFile } from "node:fs/promises";

const BASE_URL = "https://api.example-sylvester-host";
const API_KEY = "YOUR_API_KEY";

const image = (await readFile("cat.jpg")).toString("base64");

const response = await fetch(`${BASE_URL}/v2/predict`, {
  method: "POST",
  headers: { "api-key": API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({ image }),
});

const result = await response.json();
if (!response.ok) {
  throw new Error(`${result.error.code}: ${result.error.message} (request ${result.request_id})`);
}
console.log(result.detection, result.prediction);

Step 3: Read the result

{
  "request_id": "req_743a78dbedca420f9ab7dac5dd0df7d7",
  "model": { "id": "bc-v1", "version": "0.0.34" },
  "detection": "detected",
  "prediction": {
    "label": "discomfort",
    "score": 0.32395651936531067,
    "threshold": 0.3
  },
  "cat": {
    "bounding_box": { "x_min": 56, "y_min": 74, "x_max": 1005, "y_max": 1013 },
    "detection_confidence": 0.9662923216819763
  },
  "image": { "width": 1028, "height": 1028 }
}
  • detection: whether a usable cat was found (detected, low_confidence, not_detected).
  • prediction.label: discomfort because score (0.324) is greater than threshold (0.3).
  • cat.bounding_box: where the cat is in the image, in pixels.