API keys can carry an optional set of scopes that restrict what the key is allowed to do. The flagship use-case: hand an MCP server (or any LLM agent reasoning over your trace history) aDocumentation Index
Fetch the complete documentation index at: https://docs.trulayer.ai/llms.txt
Use this file to discover all available pages before exploring further.
query-scoped key so it can read traces, evals, and metrics but cannot ingest new spans, create feedback, or mutate any resource. If the key leaks, the blast radius is bounded to read access.
Why scopes exist
A TruLayer key without scopes carries full access to every endpoint for its tenant — the same powers the dashboard UI has. That is the right default for your backend services and SDK initialization, but it is the wrong default for:- MCP servers connected to Claude, Cursor, Windsurf, or any other LLM client. The server should be able to answer “show me recent failures” without being able to forge traces or revoke other keys.
- Analytical clients and BI pipelines that only read metrics and eval results.
- LLM agents that reason over trace history as part of their prompt context — scoping prevents prompt-injection from escalating into data mutation.
ingest, feedback-write, etc.) will be introduced the same way.
Available scopes
| Scope | Grants |
|---|---|
query | Read-only access to traces, evals, metrics, anomalies, projects, and the semantic-search endpoint. No writes, no key management, no billing. |
Back-compat: empty scopes = full access
Keys created before the scopes feature — and keys you create without passing anyscopes — have an empty scopes array and retain their legacy full access. Only keys that explicitly declare scopes are restricted by the scope middleware.
This means you can safely roll out scoped keys alongside existing integrations without touching any currently deployed service.
Creating a scoped key in the dashboard
- Sign in to app.trulayer.ai.
- Navigate to Settings → API keys.
- Click New Key.
- Give the key a descriptive name (e.g.
claude-mcp-readonly). - Under Scopes, select
query. - Click Create. Copy the displayed key — it will never be shown again.
Creating a scoped key via the API
secret field is returned exactly once. Store it in your secret manager immediately.
Omit scopes (or pass an empty array) to create a legacy full-access key.
Using a scoped key from the SDKs
Scoped keys are ordinary bearer tokens — initialize the SDK the same way you always have.403 with error code scope_forbidden — your client should treat it like any other authorization failure.
What to do if you need write access
If an MCP tool or agent genuinely needs to write (for example, to submit feedback), create a second key with the appropriate scope rather than relaxing an existing one. Keep the read path and the write path on separate keys so you can revoke one without disrupting the other.Related reading
- Dashboard — Settings → API keys — full key lifecycle (create, rotate, revoke, audit)
- Semantic search over spans — the canonical read-only endpoint MCP servers call