> ## 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.
> Install the library with `cargo add magpiedb`, `npm install magpiedb` or `pip install magpiedb`. Get the server from the GitHub Releases download or the Docker image `ghcr.io/intojhanurag/magpie-server`, as the quick start shows.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.
> `magpie-server doctor` checks a running server. An AI agent can query the traces over MCP at `/mcp` on the HTTP port (page guides/mcp).

# Delete and purge

> POST /v1/traces/delete removes whole traces for privacy; POST /v1/purge takes the bytes of deleted data off the disk.

Deletes are for privacy: they remove whole traces, with every span, the summary and the scores. Both routes need the `write` right and `Content-Type: application/json`, also with no body.

```sh Request theme={null}
curl -s localhost:4318/v1/traces/delete -H 'content-type: application/json' -d '{"traceIds": ["t2"]}'
```

```json 200 theme={null}
{"tracesDeleted":1,"spansDeleted":2,"scoresDeleted":4,"segmentsTouched":1,"segmentsWithDeleted":2}
```

## Delete traces

`POST /v1/traces/delete` takes exactly one of these fields.

**userId** `string`

Every trace that has a span of this user. A trace with spans of two users goes whole.

**sessionId** `string`

Every trace that has a span of this session, and every score on the session.

**traceIds** `string[]`

These traces. The scores of a listed trace go also when the trace has no span.

**filter** `object`

Every trace that [`/v1/traces/find`](https://docs.magpiedb.com/reference/api/traces-find) gives for this [trace filter](https://docs.magpiedb.com/reference/api/filters.md#trace-filter). A filter with no condition gets `400`: it matches every trace.

**tracesDeleted** `integer`

**spansDeleted** `integer`

**scoresDeleted** `integer`

**segmentsTouched** `integer`

Span segments that held a deleted span.

**segmentsWithDeleted** `integer`

Segments (files) of the store that still hold the bytes of deleted data, from this delete or earlier ones. `0`: no file holds them.

* The answer comes after the commit. From then on no route gives the data. A crash leaves the store before the delete or after it.
* A span that arrives after the delete stays, also a span of the same user.
* With tenants, a delete works in the store of the request's tenant only. A tenant with no store gets `404`.
* A filter whose text is over the word limit of `contains` and `prefix` gets `400`. The server checks this at the call and again when the delete runs. Nothing is deleted, the store takes requests as before, and no later start of the server runs that delete.

## Purge deleted data

The bytes of deleted spans stay in the files of the store until the server writes those files again. `POST /v1/purge` writes them again now, and answers when it is done. On a large store that takes minutes: give the client a long timeout. It takes no body.

```sh theme={null}
curl -s -X POST localhost:4318/v1/purge -H 'content-type: application/json'
```

**segmentsRewritten** `integer`

Segments written again without their deleted data.

**docsRewritten** `integer`

Live documents written again: the cost.

**docsRemoved** `integer`

Deleted documents that left the files.

**segmentsWithDeleted** `integer`

`0`: no file of the store holds data that was deleted before the call.

**bytesBefore** `integer`

Bytes of all files of the store before the purge. `bytesAfter`: after it.

> [card] [Data lifecycle](https://docs.magpiedb.com/operations/data-lifecycle.md)
>
> Retention, deletes and purges in production.

> [card] [Filters](https://docs.magpiedb.com/reference/api/filters.md#trace-filter)
>
> Every field of a trace filter.


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