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

# Errors and limits

> The error body and status codes of the magpie-server query API, the limits of a request, the depth rule and the cross-site rule.

Every error of the query API is JSON with one field: `{"error": "message"}`. OTLP errors have their own shape: see [Ingest traces (OTLP)](https://docs.magpiedb.com/reference/api/otlp.md#what-the-server-answers).

```sh Request theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"text": "refund"}}'
```

```json 400 theme={null}
{"error":"bad request body: an unknown name, expected one of `words`, `phrase`, `contains`, `prefix` at line 1 column 28 (detail sha256=1c37738e4800cdf9, 101 bytes)"}
```

## Status codes

| Code | When |
| - | - |
| `400` | The request is wrong: an unknown field, a value of the wrong type, a bad filter, a `limit` above 10,000, a filter that is too deep, a score that breaks a rule. |
| `401` | API keys: no key, an unknown key, or not `Bearer <key>`. The answer has `WWW-Authenticate: Bearer`. |
| `403` | API keys: the key does not have the right, or `x-magpie-tenant` is not the tenant of the key. Also `CROSS_SITE` (below) and `HOST_NOT_ALLOWED` ([Host names](https://docs.magpiedb.com/reference/server.md#host-names)). |
| `404` | No such trace, span or session. A delete for a tenant that has no store. |
| `405` | The path exists, the method does not. The answer has `Allow`. The server checks this before the key. |
| `408` | The body did not arrive within `--body-timeout` (60 s). |
| `413` | Too large: the body (`--max-body-bytes`, 64 MiB), one list (`--max-list-items`, 10,000 items), or the memory of the decode of a write. |
| `415` | A write without `Content-Type: application/json`. |
| `429` | `POST /v1/scores` while the server is busy: 16 writes run and 64 wait. The answer has `Retry-After: 1`. |
| `500` | An error inside the server. |
| `503` | The store cannot write now (a full disk, a tenant limit, the thread limit). The answer has `Retry-After: 1`. Queries can still answer. |

What to do for each code, and the gRPC codes: [Errors and memory](https://docs.magpiedb.com/operations/errors-memory.md).

## Limits of a request

| Limit | Value | Over it |
| - | - | - |
| `limit` of a list | default 50, at most 10,000 | `400` |
| Levels of a filter | 32 | `400` |
| Levels of a span | 64 | refused |
| Levels of JSON text | 128 (a `not` is one level, an `and` or an `or` is two) | `400` |
| Request body | 64 MiB (`--max-body-bytes`) | `413` |
| Items of one JSON array | 10,000 (`--max-list-items`) | `413` |
| Text search | see [Filters, `text`](https://docs.magpiedb.com/reference/api/filters#text) | `400` |
| Traces read by `/v1/traces/stats` | the newest 100,000 | `complete: false` |

All limits of the store and the server: [Limits](https://docs.magpiedb.com/limits.md).

## Why does a message never quote my request?

The text of a client can be private (a prompt, an email). An answer also goes to logs and proxies. So an error never quotes the request: no value, no name, no key of an attribute, no text of a filter, no header.

A `400` gives a fixed reason, the line and column (or the number of the score or span), and what the server expected. For the part it cut out, it gives the first 16 hex characters of its SHA-256 and its length. The hash can confirm a guess of the text. It cannot give the text back.

> [accordion] Details of the rule
>
> * A refused OTLP span is named by its number in the request (`span 0: traceId must be 16 bytes ...`), not by its name.
> * The rule fails closed. The server shows a message of the engine only in a shape it knows (`src/redact.rs`), with the value cut out: `invalid query: text has no searchable words (detail sha256=…)`. A message it does not know becomes `refused (a reason that is not shown)`, with its hash.
> * A number of the request is a value too. Before this rule, `{"attributes": 987654321012345}` came back in the message.
> * The gRPC port refuses an unknown `grpc-encoding` itself (`UNIMPLEMENTED`), and does not quote it.
> * The same rule holds for the problems of an `import` (its report and its stderr), also with `--mask`.
> * The library (Rust, Node, Python) gives the full message: there the caller has the data.

## How deep can a filter be?

A filter has at most 32 levels. A span has at most 64 levels. The server refuses a deeper one.

* In a filter (of a query or of a delete), each `and`, `or` and `not`, and each span condition of a trace filter (`root`, `anySpan`), is one level deeper than the filter it is in. A list or an object in a value of `attributes` counts on from there.
* In `attributes` and `events` of a span, a list or an object is one level. What is in it is one level deeper.
* A too-deep filter gets `400` with the reason. This holds for `/v1/search`, `/v1/count`, `/v1/traces/find`, `/v1/aggregate`, `/v1/scores/aggregate`, `/v1/export` and `/v1/traces/delete`.
* JSON text deeper than 128 levels gets `400`, with the reason of the JSON reader.

## Why was my request refused as cross-site?

A page of another site cannot send a request to the server (`403`, `CROSS_SITE`). Every request but `GET`, `HEAD` and `OPTIONS` must pass this check:

* When it has a `Sec-Fetch-Site` header, the value must be `same-origin` or `none`.
* Else, when it has an `Origin` header, it must hold the request's own host (`Host`).

Browsers send these headers, and a page cannot change them. curl, the OpenTelemetry SDKs and other programs send neither, so they pass.

> [accordion] Why the rule exists, and where it applies
>
> * Without keys, a page of any site that a person on this machine opens could send a `POST` to `127.0.0.1:4318/v1/traces/delete`. Before this rule, that request got `200`. With keys, a browser does not send the key by itself, but the rule holds the same.
> * The rule is the one of Go's `http.CrossOriginProtection`.
> * The gRPC port has the same rule (the host is `:authority` there). It reads a request only with the content type `application/grpc` (also `+proto`), else HTTP `415`. A page can send `text/plain` with any bytes and no preflight: before this rule, such a request wrote a span through the gRPC port.
> * A proxy that changes `Host` breaks the rule only for browsers that send no `Sec-Fetch-Site` (from before 2023).

> [card] [HTTP API](https://docs.magpiedb.com/reference/http-api.md)
>
> Every route and the right it needs.

> [card] [Errors and memory](https://docs.magpiedb.com/operations/errors-memory.md)
>
> What to do for each error, and what memory the server needs.


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