Quickstart
Install the sensor, score from your backend, and act on the verdict.
This walks through the full two-sided integration: the browser sensor (client) and
the score call (server). The two are tied together by a shared session_id.
1. Get your keys
From the dashboard, create an organization and grab two keys:
- A publishable site key (
pk_live_…) — public, used by the browser sensor. - A secret API key (
vg_live_…) — server-side only, used to call the scoring API.
2. Install the browser sensor
Add the sensor to the <head> of the page that hosts your AI feature:
html
<script async src="https://cdn.vectoral.cloud/v1/sensor.js?siteKey=pk_live_xxx&endpoint=https://api.vectoral.cloud/v1/sensor/collect"></script>
Then forward the sensor's session id to your backend on the request that triggers the LLM call:
js
fetch("/api/generate", {
method: "POST",
headers: { "X-Vectoral-Session": window.vectoral.sessionId },
body: JSON.stringify({ /* ... */ }),
});
3. Score from your backend
In the route that calls the LLM, score before running inference:
js
const sessionId = req.headers["x-vectoral-session"];
const res = await fetch("https://api.vectoral.cloud/v1/score", {
method: "POST",
headers: {
Authorization: "Bearer vg_live_xxx",
"Content-Type": "application/json",
},
body: JSON.stringify({
account_id: user.id,
session_id: sessionId,
request: {
ip: clientIp,
user_agent: req.headers["user-agent"],
model_requested: "gpt-4",
estimated_prompt_tokens: 100,
},
}),
});
const { score, tier, blocked, signals_fused } = await res.json();
if (blocked || tier === "high") {
return res.status(403).json({ error: "blocked" });
}
4. Feed back results (recommended)
After the LLM responds, send token and cost telemetry so future scores get sharper:
bash
curl -X POST https://api.vectoral.cloud/v1/events/post-call \
-H "Authorization: Bearer vg_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"account_id": "user_abc123",
"session_id": "sess_xyz",
"model": "gpt-4",
"prompt_tokens": 1247,
"completion_tokens": 340,
"inference_cost_usd": 0.0234
}'