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

# Read and export

> Read one trace or one span, read a big trace in pages, and export spans as JSON Lines.

## Read one trace

Every span with its text:

```sh theme={null}
curl -s localhost:4318/v1/traces/t2
```

```json theme={null}
{"spans":[{"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}]}
```

A trace with very many spans (an agent that ran for hours) can be hundreds of MB. Read its tree in pages without the text, then the text of one span:

```sh theme={null}
curl -s 'localhost:4318/v1/traces/t1/spans?limit=2'
```

```json theme={null}
{"count":3,"spans":[{"spanId":"r1","parentSpanId":null,"name":"chat","kind":"agent_run","model":null,"startedAt":1000,"endedAt":5000,"hasError":false,"inputTokens":0,"outputTokens":0,"cost":null},{"spanId":"m1","parentSpanId":"r1","name":"","kind":"model_generation","model":"gpt-x","startedAt":1100,"endedAt":1600,"hasError":false,"inputTokens":100,"outputTokens":50,"cost":0.0015}],"nextCursor":"eyJsaXN0IjoidHJhY2Ugc3BhbnMiLCJzb3J0Ijoib2xkZXN0IiwidGltZSI6MTEwMCwiaWQiOiJtMSIsImlkMiI6IiIsIm4iOjF9"}
```

```sh theme={null}
curl -s localhost:4318/v1/traces/t1/spans/m1
```

```json theme={null}
{"traceId":"t1","spanId":"m1","parentSpanId":"r1","name":"","kind":"model_generation","model":"gpt-x","userId":"u1","sessionId":"s1","service":null,"environment":null,"tags":[],"startedAt":1100,"endedAt":1600,"inputTokens":100,"outputTokens":50,"cost":0.0015,"status":"unset","error":null,"input":"what is the refund policy","output":"the refund policy is thirty days","attributes":null,"events":null}
```

## Export

`POST /v1/export` sends every span that matches a span filter, one JSON object per line, oldest first. The lines have the shape that a write takes, so they load back into a store (`magpie-server import --format magpie`). It streams: the server holds only a few MB, for a store of any size.

```sh theme={null}
curl -sN localhost:4318/v1/export -d '{"filter": {"traceId": "t2"}}' | jq -c '{traceId, spanId, kind, input}'
```

```json theme={null}
{"traceId":"t2","spanId":"r2","kind":"agent_run","input":"hello world"}
{"traceId":"t2","spanId":"m2","kind":"model_generation","input":"policy refund"}
```

`POST /v1/export/scores` does the same for scores (`{"from": a, "to": b}` on the time of the score).


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