> ## 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).

# Export

> POST /v1/export and POST /v1/export/scores: every span of a filter, or every score of a time range, as JSON Lines that load back into a store.

The two export routes send JSON Lines (`application/x-ndjson`): one JSON object per line. Right: `read`. The server sends the body in chunks while it makes it, so an export of any size fits in a few MB of server memory.

```sh Request theme={null}
curl -sN localhost:4318/v1/export -d '{"filter": {"traceId": "t2"}}'
```

```json 200 theme={null}
{"traceId":"t2","spanId":"r2","parentSpanId":null,"name":"","kind":"agent_run","model":null,"userId":"u2","sessionId":null,"service":null,"environment":null,"tags":[],"startedAt":2000,"endedAt":3000,"inputTokens":0,"outputTokens":0,"cost":null,"status":"unset","error":null,"input":"hello world","output":"","attributes":null,"events":null}
{"traceId":"t2","spanId":"m2","parentSpanId":"r2","name":"","kind":"model_generation","model":"gpt-y","userId":"u2","sessionId":null,"service":null,"environment":null,"tags":[],"startedAt":2100,"endedAt":2600,"inputTokens":10,"outputTokens":5,"cost":0.0001,"status":"unset","error":null,"input":"policy refund","output":"","attributes":null,"events":null}
```

## Export spans

`POST /v1/export` sends every span that matches the filter, one per line, oldest first. Spans with the same `startedAt` come in no promised order.

**filter** `object` (default: \{})

A [span filter](https://docs.magpiedb.com/reference/api/filters.md#span-filter). `{}` or no body: every span. A time range: `{"filter": {"from": a, "to": b}}`.

Each line is a [span](https://docs.magpiedb.com/reference/api/read-trace.md#get-every-span-of-a-trace) with every field. That is the shape that the library's `write` takes, so the lines load back into a store (`magpie-server import --format magpie`).

```sh theme={null}
curl -sN localhost:4318/v1/export -d '{"filter": {"from": 1764000000000, "to": 1764086400000}}' > spans.ndjson
```

## Export scores

`POST /v1/export/scores` sends every score, one per line, in no promised order.

**from** `integer`

Only scores with `from <= at` (ms). `at` is the time of the score, not of its trace.

**to** `integer`

Only scores with `at < to` (ms).

Scores are a second file because a score can come long after its trace. A span filter does not pick scores. For the scores of one trace, use [`GET /v1/traces/:id/scores`](https://docs.magpiedb.com/reference/api/scores#get-the-scores-of-a-trace).

## How an export behaves

* **One span per line.** A line has no line break inside. JSON escapes the control characters, and the server also writes U+0085, U+2028 and U+2029 as `\u` escapes. So tools that end a line at them (Node's `readline`, Python's `str.splitlines`) still see one span per line.
* **Chunks.** The body comes in chunks of whole lines, at most a few MB each (more if one span is bigger). The server makes the next chunk only when the one before is on its way, so it holds about three chunks. A client that goes away stops the export.
* **One commit.** The export reads the commit that the store shows when the request comes, from start to end: later writes and deletes are not in it. It keeps the files of that commit open until it ends, so a merge during a long export cannot free their disk space before.
* **Errors.** A request that cannot run (an unknown field, a bad filter) gets `400` before any line. If the export fails after its first chunk, the status is already sent: the connection ends without the end of the body. A body read to its end with no error has every line.

> [card] [Read and export](https://docs.magpiedb.com/queries/read-export.md)
>
> A guide with real exports.

> [card] [Backup and import](https://docs.magpiedb.com/operations/backup-import.md)
>
> Load an export into another store.


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