# 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](https://app.vectoral.com), 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.

> [!WARNING]
>
> The secret key is shown once. Store it securely and never ship it to the browser.

**2. Install the browser sensor**

Add the sensor to the `<head>` of the page that hosts your AI feature:

```html theme={null}
<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 theme={null}
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 theme={null}
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" });
}
```

> [!WARNING]
>
> Check `blocked` as well as `tier`. It means an operator blocked the account, or a
> spend cap tripped — decisions your own product already made, which shouldn't be
> downgraded to "probably fine" just because the behavioral score is low. See
> [hard controls](https://docs.vectoral.si/concepts.md#hard-controls).

**4. Feed back results (recommended)**

After the LLM responds, send token and cost telemetry so future scores get
sharper:

```bash theme={null}
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
  }'
```

> [!TIP]
>
> When the score response shows `signals_fused: true`, the browser signal was
> successfully joined to the account score — your two-sided integration is working.
