> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Packages and server binaries are not published yet: build from source, as the quick start shows. Check the status note on the introduction page before you suggest `cargo add`, `npm install` or `pip install`.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.

# Tenants: one store per customer

> Give each customer its own store with --tenants-dir and per-tenant API keys.

With `--tenants-dir`, each tenant has its own store in its own folder. No query sees the spans of another tenant. To delete a tenant, stop the server and delete its folder.

The tenant of a request comes from its API key. Make keys for two tenants:

```sh theme={null}
magpie-server keygen --tenant acme --rights write >> tenant-keys.jsonl 2> acme-app.txt
magpie-server keygen --tenant acme --rights read >> tenant-keys.jsonl 2> acme-dashboard.txt
magpie-server keygen --tenant globex --rights read,write >> tenant-keys.jsonl 2> globex.txt
ACME_APP=$(tail -n 1 acme-app.txt) ACME_DASHBOARD=$(tail -n 1 acme-dashboard.txt) GLOBEX=$(tail -n 1 globex.txt)
```

```sh theme={null}
magpie-server --tenants-dir ./tenants --auth keys --keys-file tenant-keys.jsonl
```

The app of `acme` sends one agent run. `scripts/send-trace.sh` makes a run with three spans:

```sh theme={null}
"$REPO/scripts/send-trace.sh" --url http://127.0.0.1:4318 --key "$ACME_APP" > /dev/null
sleep 2   # the next commit makes it searchable
```

`acme`'s dashboard sees it. `globex` has no store yet (`404`). The app key cannot read (`403`):

```sh theme={null}
curl -s localhost:4318/v1/count -H "authorization: Bearer $ACME_DASHBOARD" -d '{}'; echo
curl -s -o /dev/null -w '%{http_code}\n' localhost:4318/v1/count -H "authorization: Bearer $GLOBEX" -d '{}'
curl -s -o /dev/null -w '%{http_code}\n' localhost:4318/v1/count -H "authorization: Bearer $ACME_APP" -d '{}'
```

```text theme={null}
{"count":3}
404
403
```

* A tenant id is 1 to 64 characters of `a-z`, `0-9`, `_` and `-`. Lower case only.
* A tenant's store is made at its first write, opens at its first request, and closes after `--tenant-idle-secs` (300) with no request. At most `--max-open-tenants` (100) stores are open at once ([Memory and threads](https://docs.magpiedb.com/operations/errors-memory.md#memory-and-threads)).
* `--auth trusted-header` is the other way: the server trusts the header `x-magpie-tenant`. Use it only behind a proxy or a Collector that checks the caller and sets the header.
* One mask policy, one price table and one retention for all tenants in this version.
* Not with `--s3` ([Limits](https://docs.magpiedb.com/limits.md#server)).

> [!WARNING]
>
> `--auth trusted-header` trusts the `x-magpie-tenant` header. Use it only behind a proxy that authenticates the caller.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.