Docs/Core Concepts/Canary Tokens

Canary Tokens

Embed invisible tripwires inside your agent's context. When an attacker reads or exfiltrates your agent's system prompt or tool outputs, Trappr detects it instantly — before any damage is done.


What are canary tokens?

A canary token is a unique, trackable value embedded silently inside data that should never be read by external parties. When that value appears in an outgoing request, a log, or a response — you know something accessed it that shouldn't have.

Trappr generates canary tokens scoped to your agent and embeds them transparently. You don't change your agent logic. Trappr watches the traffic and alerts you the moment a token is seen outside its intended boundary.

Canary tokens work silently. Your agent has no awareness of them — they are injected and monitored entirely by Trappr at the gateway layer.

How it works

When your agent sends a request through the Trappr AI Gateway, canary tokens are embedded at the right moment and watched on every subsequent call.

Your Agent
sends request
Trappr Gateway
injects token
LLM Provider
processes context
Trappr
monitors response
Alert
if token seen
1
Agent routes traffic through the Trappr Gateway

Point your LLM calls at the Trappr endpoint. The gateway is fully compatible with the OpenAI SDK and other provider SDKs — no code changes needed beyond the base URL.

2
Trappr embeds a canary token in the context

On each qualifying request, Trappr silently adds a uniquely generated token — invisible to your agent and transparent to the LLM model.

3
Trappr watches all outgoing traffic

Every response, tool call, and downstream API call is checked. If a canary value appears where it shouldn't, it's flagged immediately.

4
You receive an instant alert

Alerts fire via Slack, email, or webhook with the exact context: which token was triggered, in which execution, at what timestamp.

Prerequisites

Setup

Step 1 — Create a canary token in the dashboard

Go to Dashboard → Canary Tokens → New token. Give it a name (e.g. system-prompt-guard) and select the app it belongs to. The dashboard generates a unique token string.

Step 2 — Route LLM calls through the Gateway

Update your agent to use the Trappr Gateway endpoint. The gateway is API-compatible with OpenAI, Anthropic, and most providers.

Python
import openai

client = openai.OpenAI(
    base_url="https://gateway.trappr.net/v1",
    api_key="<your-trappr-api-key>",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user",   "content": "Summarize this document."},
    ],
)
JavaScript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.trappr.net/v1",
  apiKey:  "<your-trappr-api-key>",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user",   content: "Summarize this document."      },
  ],
});
cURL
curl -X POST https://gateway.trappr.net/v1/chat/completions \
  -H "Authorization: Bearer <your-trappr-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user",   "content": "Summarize this document."}
    ]
  }'
You can keep using your existing provider API key — just set it in the Trappr dashboard under Provider Settings. Trappr forwards requests to the real provider on your behalf.

Step 3 — Verify the token is active

After routing at least one request through the gateway, go to Dashboard → Canary Tokens. You should see your token listed as Active with a last-seen timestamp.

Step 4 — Configure alerts

Under Settings → Alerts, connect a Slack channel, email address, or webhook URL. When a canary is triggered, you'll receive a notification within seconds. See the Slack alerts guide for setup.

What triggers a canary alert?

A canary alert fires when a monitored value is detected in any of the following:

Trigger locationExample scenario
LLM response contentModel echoes or references the token in its reply
Tool call argumentsAgent passes the token value to a downstream tool or API
Outgoing HTTP callsToken appears in a URL, header, or body sent to an external service
Workflow node outputsToken flows through an n8n or Make workflow node into an external step

Viewing triggered incidents

All triggered canary events are logged under Dashboard → Incidents. Each incident shows the full execution trace, the message where the token appeared, and a timestamp. You can acknowledge or investigate incidents directly from the dashboard.

Next steps