Your first skin analysis
This goes one step beyond Getting started: capture an image in a browser, send it to the Skin Analysis API, and render the response into a small UI.
The example uses plain HTML and fetch so it ports trivially into React, Vue, or any framework. About 60 lines of code, no build step.
The full example
Section titled “The full example”<!doctype html><html><head><meta charset="utf-8"><meta name="color-scheme" content="light dark"><title>Revieve demo</title></head><body> <input type="file" id="file" accept="image/jpeg" /> <button id="go" disabled>Analyze</button> <p>…or try a sample photo: <span id="samples"></span></p> <pre id="out"></pre>
<script type="module">const PARTNER_ID = "jmlv6b2qtS";const BASE = "https://partner-test.revieve.com/api/3";
const file = document.getElementById("file");const go = document.getElementById("go");const out = document.getElementById("out");
file.addEventListener("change", () => { go.disabled = !file.files[0]; });
// Sample photos served next to these docs (licensed model images).// Picking one puts it into the file input, exactly as if the user had chosen it.for (let i = 1; i <= 18; i++) { const img = Object.assign(document.createElement("img"), { src: `/demos/models/m${i}.jpg`, width: 52, height: 52, alt: `Sample ${i}`, style: "cursor:pointer;border-radius:50%;margin:0 2px;object-fit:cover" }); img.addEventListener("click", async () => { const blob = await (await fetch(img.src)).blob(); const dt = new DataTransfer(); dt.items.add(new File([blob], `sample-${i}.jpg`, { type: "image/jpeg" })); file.files = dt.files; file.dispatchEvent(new Event("change")); }); document.getElementById("samples").append(img);}
go.addEventListener("click", async () => { out.textContent = "Analyzing...";
const url = new URL(`${BASE}/analyzeImage/`); url.searchParams.set("skintone", "0"); // 0 = no user input (automatic) url.searchParams.set("gender", "unknown"); // unknown, female or male url.searchParams.set("components", [ "wrinkles", "redness", "hyperpigmentation", "acne", ].join(","));
const form = new FormData(); form.append("partner_id", PARTNER_ID); form.append("image", file.files[0]);
const res = await fetch(url, { method: "POST", body: form }); const data = await res.json();
if (data.message === "Error") { out.textContent = `Failed: ${data.status?.find((s) => s.isError === 1)?.description ?? "unknown"}`; return; }
out.textContent = data.results .map((r) => `${r.description.padEnd(20)} ${r.value == null ? "n/a" : (r.value * 100).toFixed(0)}`) .join("\n");});</script></body></html>What it does, step by step
Section titled “What it does, step by step”-
The user picks a JPEG. Anything ≥ 600×600 px works. The sample strip loads one of the docs’ model photos into the same file input, so the rest of the code does not care where the image came from.
-
We build the URL. Always send
skintoneandgender; without them the server falls back to fixed defaults that may not match your user. If you don’t know them, sendskintone=0andgender=unknownto let the analysis estimate them. Optional:components(we ask for four). The full list is in the API reference. -
We POST a multipart form. The body has
partner_idandimage. Browsers set theContent-Typeboundary automatically. -
We branch on the response shape.
data.message === "OK"— no global quality issues. Individual metrics can still fail: check each result’smessageandlocal_warnings.data.message === "Warning"— results are usable, but image quality is reduced; consider a UX nudge (“try better lighting”).data.message === "Error"— the analysis could not run andresultsisnull; show thedescriptionof the firststatus[]entry withisError: 1(earlier entries can be warnings).
-
We render
results. Each entry we asked for here has avaluebetween 0 and 1 — multiply by 100 for percentage UI. Not every metric works this way: integer/categorical findings (e.g.skin_age,skin_type) leavevaluenull and carry their result insum_measures[]instead — see below.
Where to go from here
Section titled “Where to go from here”- For richer rendering, the
measurement_locations[]andmask_shapesfields drive overlay visualizations. See Interpreting results. - For integer and categorical findings (skin age, skin type, undertone, hair type, eye color), look at
sum_measures[]rather than the top-levelvalue— for these,valueis null. - For real-time AR try-on, use Revieve VTO — the Skin Analysis API is for still-image scoring only.
Common quality issues
Section titled “Common quality issues”| Symptom | Likely cause | Fix |
|---|---|---|
idx: 100 (input format) | Image is not a colour (RGB) image, e.g. grayscale. | Send a colour image. |
idx: 101 (resolution) | Image smaller than 600×600. | Recapture at higher resolution — don’t upscale. |
idx: 301 (face too small) | Face too small in the frame. | Prompt the user to move closer. |
idx: 103/104 (lighting) | Over- or under-exposed. | Reshoot in even lighting; warn the user. |
idx: 201 (no face) | Face is occluded or out of frame. | Prompt the user to recentre. |
idx: 308 (overexposure) | Hot spot from direct flash. | Use more diffuse light. |