# Run a sidecar

Run the Trace worker beside your own model and send Provenance only signed canary readings; prompts and completions never leave your infrastructure.

Use the sidecar when your model runs on your own GPUs. The trace worker reads the canary neurons next to your model, signs the readings with a key you hold, and sends Provenance only the readings and a prompt hash. Your [canary policies](https://provenanceauth.com/docs/trace/guides/canary-policies.md) then read them with `canary_source: "sidecar"`.

**Before you begin:** a [registry build](https://provenanceauth.com/docs/trace/guides/registry-builds.md) of your model with its canary sets, a running [trace worker](https://provenanceauth.com/docs/self-host/trace-worker.md), `openssl`, and an account key on any plan (the examples use the sandbox Enterprise key).

## Keys and billing

Every plan can run a sidecar. The Free trial and Pro hold one active worker key, Growth five and Enterprise any number; revoke a key to free its place. Each reading Provenance accepts counts as one [signed reading](https://provenanceauth.com/docs/account/plans-and-usage.md#signed-readings) for your account, against your plan's included readings; a refused reading counts nothing. To send fewer, set a [sampling rate](#sampling).

## 1. Create a signing key and register its public half

Generate an EC P-256 key pair and keep the private half on your worker. Register the public half with [`POST /v1/trace/worker_keys`](https://provenanceauth.com/docs/api/sidecar.md#post-v1-trace-worker-keys):

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x

openssl ecparam -name prime256v1 -genkey -noout -out sidecar.key.pem
openssl ec -in sidecar.key.pem -pubout -out sidecar.pub.pem

curl -s $PROVENANCE_API/v1/trace/worker_keys \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d "{ \"name\": \"gpu-pod-eu-1\", \"public_key_pem\": $(jq -Rs . sidecar.pub.pem) }" | tee worker-key.json
```

**Node**

```ts
import { readFileSync } from "node:fs";
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const key = await prov.trace.workerKeys.create({ name: "gpu-pod-eu-1", publicKeyPem: readFileSync("sidecar.pub.pem", "utf8") });
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
key = prov.trace.worker_keys.create(name="gpu-pod-eu-1", public_key_pem=open("sidecar.pub.pem").read())
```

```json
{
  "id": "wk_b61c4a263fb72bbdb1871916",
  "object": "trace_worker_key",
  "name": "gpu-pod-eu-1",
  "alg": "ES256",
  "created_at": "2026-10-24T13:18:21.528Z",
  "revoked_at": null,
  "last_seen_at": null,
  "public_key_pem": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEjmvCLMKvTx8C9If7PObCQCSNe3Ly\nDZCC+vxLGJt3vSVVUJtoEWfn0Kkql3oGzN4bk09pHJ7W28Os+8o9f6f1Mw==\n-----END PUBLIC KEY-----\n"
}
```

Only EC P-256 public keys are accepted. The console's **Developers → API keys → Sidecar** tab does the same.

## 2. Start the worker in sidecar mode

Run the worker with the private key, the key's ID and your API URL:

```bash
export TRACE_SIGNING_KEY_ID=$(jq -r .id worker-key.json)
TRACE_WORKER_BACKEND=hf TRACE_MODEL=<your Hugging Face model> \
TRACE_SIDECAR=1 TRACE_SIGNING_KEY_PEM="$(cat sidecar.key.pem)" \
PROVENANCE_API_URL=$PROVENANCE_API \
  provenance-trace-worker serve --port 8090
```

### Sampling

Set `TRACE_READING_SAMPLE_RATE` on the worker to read a share of requests (from `0` to `1`; the default `1` reads every request). The choice comes from the prompt hash, so the same prompt is always read or always skipped. At `0.1`, about one request in ten is read and sent.

A skipped request answers `"sampled": false` with no `trace_id`: nothing is signed, sent or billed, and a canary policy that needs a sidecar reading for it sees none. A request with `kill_switch` is always read, since the kill switch needs the readings to stop your model. A value outside `0` to `1` makes the worker answer `503` `sidecar_not_configured`.

## 3. Read the canaries before your agent acts

Your agent or gateway calls the worker. The worker reads the canaries, signs the reading and posts it to Provenance, then returns the `trace_id`:

**curl**

```bash norun
curl localhost:8090/v1/sidecar/read \
  -H "Authorization: Bearer $TRACE_WORKER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model_version_id": "qwen2.5-0.5b-instruct@7ae55760-ad6c88b2",
    "messages": [{ "role": "user", "content": "Summarize this vendor email." }],
    "canary_sets": ["prompt_injection"]
  }'
```

**Node**

```ts
const reading = await (await fetch("http://localhost:8090/v1/sidecar/read", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.TRACE_WORKER_TOKEN}`, "Content-Type": "application/json" },
  body: JSON.stringify({ model_version_id: "qwen2.5-0.5b-instruct@7ae55760-ad6c88b2", messages, canary_sets: ["prompt_injection"] }),
})).json();
```

**Python**

```python
import httpx

reading = httpx.post(
    "http://localhost:8090/v1/sidecar/read",
    headers={"Authorization": f"Bearer {os.environ['TRACE_WORKER_TOKEN']}"},
    json={"model_version_id": "qwen2.5-0.5b-instruct@7ae55760-ad6c88b2", "messages": messages, "canary_sets": ["prompt_injection"]},
).json()
```

```json
{
  "trace_id": "trc_6f1c2a9e0b7d4e3a8c5f1b2d3e4f5a6b",
  "readings": { "prompt_injection": { "score": 1, "tripped": true, "threshold": 1 } },
  "backend": "hf",
  "posted": {
    "id": "trd_01M5Q1C4X2ZK9V7T6R5P4N3M2L",
    "object": "trace_reading",
    "trace_id": "trc_6f1c2a9e0b7d4e3a8c5f1b2d3e4f5a6b",
    "canary_hash": "9d3b5f2a7c1e8b4d6f0a2c4e6b8d0f1a3c5e7b9d1f3a5c7e9b1d3f5a7c9e1b3d",
    "model_version_id": "qwen2.5-0.5b-instruct@7ae55760-ad6c88b2",
    "received_at": "2026-10-24T13:20:00.000Z"
  }
}
```

Pass that `trace_id` to [`POST /v1/mandate/intents`](https://provenanceauth.com/docs/api/intent-tokens.md#post-v1-mandate-intents) or [`POST /v1/mandate/assessments`](https://provenanceauth.com/docs/api/intent-tokens.md#post-v1-mandate-assessments). Add `kill_switch` and generation settings to the same call and the worker generates the completion itself, stopping between tokens on a trip; the completion stays with you, and the signed reading adds a `trip` claim. See [Trace rules on model output](https://provenanceauth.com/docs/trace/guides/trace-rules.md#on-model-output).

## 4. Optional: revoke a key

Readings signed by a revoked key are rejected from then on:

**curl**

```bash
export WORKER_KEY_ID=$(jq -r .id worker-key.json)
curl -X DELETE $PROVENANCE_API/v1/trace/worker_keys/$WORKER_KEY_ID \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
await prov.trace.workerKeys.revoke(key.id);
```

**Python**

```python
prov.trace.worker_keys.revoke(key["id"])
```

```json
{ "id": "wk_b61c4a263fb72bbdb1871916", "object": "trace_worker_key", "deleted": true }
```

## Label neurons with your own key

The worker can label neurons of your registry build with your own Anthropic key and post the labels, signed with your worker key, to [`POST /v1/trace/labels`](https://provenanceauth.com/docs/api/sidecar.md#post-v1-trace-labels). Only the labels are sent, never prompt or example text, and Provenance bills nothing for them. Install the `labels` extra and run `provenance-trace-worker label`; see [neuron labels](https://provenanceauth.com/docs/trace/guides/neuron-labels.md#label-with-your-own-key).

## The reading format

The worker posts each reading to [`POST /v1/trace/readings`](https://provenanceauth.com/docs/api/sidecar.md#post-v1-trace-readings) as `{"token": "<JWS>"}`. It needs no API key: the signature authenticates it.

| Part | Contents |
| --- | --- |
| Header | `alg: ES256`, `typ: provenance-trace-reading+jwt`, `kid`: the worker key ID |
| Required claims | `trace_id` (`trc_` and 32 hex characters, minted by you), `model_version_id`, `prompt_hash`, `readings`, `iat` |
| Optional claims | `session` (`agent_id`, `agent_session_id`, so the reading teaches that agent's [baseline](https://provenanceauth.com/docs/trace/concepts/baselines.md)), `predictions` (probe outputs, see [predictive preflight](https://provenanceauth.com/docs/trace/guides/predictive-preflight.md)), `trip` (when the kill switch fired) |

`iat` must be within 15 minutes, and no more than 60 seconds in the future. Provenance computes the `canary_hash` from the claims. A `trace_id` is accepted once per account.

**Limitations:** a sidecar reading proves that a key you registered signed these readings for this prompt hash at about this time. Which hardware and weights produced them is yours to vouch for, because you run the model.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `public_key_pem` | Not an EC P-256 public key | Generate the key with `prime256v1`. |
| `401` [`trace_reading_signature_invalid`](https://provenanceauth.com/docs/platform/errors.md#trace_reading_signature_invalid) | A bad signature, or an unknown or revoked key | Check `TRACE_SIGNING_KEY_ID` matches a live key. |
| `409` [`trace_reading_replayed`](https://provenanceauth.com/docs/platform/errors.md#trace_reading_replayed) | The `trace_id` was already ingested | Mint a new `trace_id` per reading. |
| `402` [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required) on `worker_keys` | Your plan's active worker keys are in use | Revoke a key, or move to a plan with more. |
| `402` [`trial_ended`](https://provenanceauth.com/docs/platform/errors.md#trial_ended) on a reading | The Free trial ended, or its 1,000 signed readings are used | Choose a plan. |
| `402` [`spend_cap_reached`](https://provenanceauth.com/docs/platform/errors.md#spend_cap_reached) on a reading | Your account reached its monthly spend cap | Raise or remove the cap. |
| `503` `sidecar_not_configured` from the worker | Sidecar mode is missing a setting | Set `TRACE_SIDECAR`, the signing key and its ID, and `PROVENANCE_API_URL`. |

## See also

- [Run the trace worker](https://provenanceauth.com/docs/self-host/trace-worker.md)
- [Server configuration](https://provenanceauth.com/docs/self-host/configuration.md)
- [Canary policies](https://provenanceauth.com/docs/trace/guides/canary-policies.md)
