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

# Request limits

> Every limit of a write to magpie-server: what it counts, when it counts, what the client gets, and the memory measured under load.

Each limit refuses a request before it costs memory. Nothing of a refused request is written. The flags are in [Server flags, "Limits"](https://docs.magpiedb.com/reference/server.md#limits).

| limit | default | over it | counted |
| - | - | - | - |
| writes at a time | 16 run, 64 wait (no flag) | `429 BUSY`, `Retry-After: 1`; gRPC `UNAVAILABLE` | before the body is read |
| body | 64 MiB (`--max-body-bytes`) | `413`; gRPC `RESOURCE_EXHAUSTED` | before and after gzip decoding |
| spans of one request | 100,000 (`--max-spans-per-request`) | `413 TOO_MANY_SPANS` | before the decode |
| items of one list | 10,000 (`--max-list-items`) | `413 LIST_TOO_LONG` | before the decode |
| memory of the decodes in flight | 512 MiB (`--ingest-memory-mb`) | `413 DECODE_TOO_LARGE`, or wait | before the decode (an estimate) |
| bytes of one request's spans | 2 x the body limit, 128 MiB (`--max-mapped-bytes`) | `413 MAPPED_TOO_LARGE` | after the decode, before any copy |

Every `413` is gRPC `RESOURCE_EXHAUSTED`. The OTLP spec says a client does not send it again: that batch is lost. A `429` and a `503` are sent again.

## Writes at a time

At most 16 writes (OTLP exports over HTTP or gRPC, `POST /v1/scores`) read, decode and write at once. At most 64 more wait. The next gets `429` (`BUSY`).

A waiting write has not read its body: its bytes wait in the socket, not in the server. A write keeps its place until its work on the store ends, also when its client goes away. A slow client holds its place while its body arrives, until `--body-timeout` ends it. Deletes and purges take no place.

With keys, the server checks the key and its right first: before the write takes a place, and before it reads the body. A gRPC body that is not protobuf, sent with no key, gets `UNAUTHENTICATED`, not a decode error.

> [accordion] How a refused body is read over HTTP
>
> Over HTTP the `429` comes at once. The server then reads the refused body to its end and drops it, with no place and no decode: at most `--max-body-bytes`, within `--body-timeout`. So a client that sends its whole body before it reads the answer gets the `429`, not a reset.
>
> A body that says it is longer than `--max-body-bytes`, or a request with `Expect: 100-continue`, is not read. gRPC needs no such read: HTTP/2 ends the one stream (`tests/busy.rs`). Before this rule, the launch proof with 128 clients got 2,585 answers `429` and 797 exports with no answer.

## The body limit

64 MiB is the default that the OTLP spec recommends for a server and a client. An SDK's batch processor sends up to 512 spans in one export (`OTEL_BSP_MAX_EXPORT_BATCH_SIZE`).

512 model calls of 50 KB are 26.0 MB as protobuf and 26.6 MB as JSON (`tests/sdk_batch.rs`). gRPC has the same limit.

For a larger batch, raise `--max-body-bytes`, or make the SDK send fewer spans per export. Over HTTP the server still reads the rest of a body over the limit, so the client gets the `413`. It reads at most 64 MiB more (or `--max-body-bytes`, if larger), within `--body-timeout`. A longer body, or `Expect: 100-continue`, gets the `413` at once and the connection closes.

## Spans and mapped bytes

The mapping puts a copy of the resource's attributes, and the scope's name and version, into every span. A request of 30 KB with 100 spans and one resource attribute of 8 KiB became about 800 KiB of spans.

So the server measures each request after the decode and before any copy. It counts the spans, and the bytes as protobuf, where each span counts with its resource and scope.

Before D341 the default was 4 x a body limit of 16 MiB (64 MiB). Now it is 2 x the body limit: an ordinary batch maps to about its own size. 4 x 64 MiB would let 16 small requests become 4 GiB of spans. `import` measures each OTLP line the same way, with a quarter of `--memory-mb` as the byte cap and no span cap.

## The decode budget

The server counts the memory of a decode from the bytes, before it decodes. A request that alone needs more than `--ingest-memory-mb` gets `413 DECODE_TOO_LARGE`. The others take their cost from the budget and wait, with their place, until it is free.

Score writes count 1 KiB per object. An `import` line has a quarter of `--memory-mb`.

Why: an empty protobuf message is 2 bytes on the wire and 32 to 264 bytes in memory. One body of 16 MiB with 8,388,592 empty spans took the server to 2.27 GB before this rule. Now it is refused at a peak of 35 MB, and 16 of them at once at 297 MB (F78, `results/anu84-hardening/decode-budget.json`).

How much of the default budget a JSON body takes, as a factor of its bytes (`results/anu87-sdk-batch/budget-alloc.txt`, F78):

| OTLP/JSON body | counted, x its bytes | refused above about |
| - | - | - |
| GenAI spans with long prompts | 6.0 | fits up to the body limit |
| an SDK's full batch of 50 KB model calls | 4.1 (protobuf: 1.0) | fits up to the body limit |
| HTTP spans | 13.2 | 38 MiB |
| DB spans with events | 15.8 | 32 MiB |
| spans with 40 small attributes | 20.5 | 25 MiB |
| spans with an array of 100 ints | 38.4 | 13 MiB |

The count is an estimate of the decoder's memory, not a measure. `tests/budget_alloc.rs` checks that no real decode of the tested bodies is above its count; the real decode takes 1.1 to 2.6 times the bytes.

> [accordion] How a body is counted
>
> Protobuf: every message is counted from its bytes, by the schema and with no allocation. That covers spans, resources, scopes, attributes, values in lists, events, links and entity ids; a text is never read as a message. Each message in a list costs twice its Rust size, and the first of each list 4 times (a `Vec` of one item has room for 4; D276). The body's bytes count once more. In its worst shapes the real protobuf decode comes to 0.96 to 0.99 of its count.
>
> JSON (D272, D275): 64 bytes for each value and each key, plus the bytes of each text. These count again for every OTLP `AnyValue` around them: serde reads an `AnyValue` through a `flatten` field, which copies the object once more for each `AnyValue` it is in.
>
> Each object costs what it becomes:
>
> | JSON | counted |
> | - | - |
> | an object of a list in OTLP/JSON | twice the struct of its list; the first of a list twice more |
> | an attribute | 128 bytes |
> | a span | 528 bytes, also under any other key |
> | a struct its parent holds (the object of `"value"`) | nothing |
> | a score | 1 KiB |
> | the body's bytes | twice |
>
> The spans of an OTLP/JSON body are counted before the decode, as for protobuf. An array directly in an array is a `400` before the decode: serde reads a struct also from an array of its fields, which no OTLP encoder writes. Before that rule, a 2 MB body with 30 nested `arrayValue`s was counted at 4 MB and decoded to about 1 GB.

## Lists

One list of a request has at most `--max-list-items` items (D271), counted before the decode.

| list | items of |
| - | - |
| attributes | of a span, the resource, the scope, an event or a link |
| events, links | of a span |
| values | of an array or a kvlist, also nested |
| other | the resources of a request, the scopes of a resource, the ids of an entity |
| JSON query API | every array (`or`, `anySpan`, `traceIds`), the words of a `words` text, the scores of one write |
| OpenTelemetry SDKs keep 128 attributes of a span by default (`OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT`). | |

The spans of a scope are not a list here: `--max-spans-per-request` caps them, because a Collector puts thousands in one scope. In OTLP/JSON, every array but `resourceSpans[].scopeSpans[].spans` counts (D273). A protobuf field that holds one message and comes twice is a `400`. `import` has the same flag.

Why: the macOS allocator keeps the memory of a decoded very long list after the request. 16 requests of one span with 3,500,000 empty attributes left 3.4 GB before this cap. Now they are refused and leave 24 MB (F78, `results/anu84-hardening/list-cap-retention.json`). Not measured on Linux.

## Memory under load

The memory of the writes in flight is at most 16 bodies, with their decoded and mapped forms. The bodies and the mapped spans are not in the decode budget. Measured on one Mac (F99, the peak footprint of the server):

| 16 writes at once | peak |
| - | - |
| each an SDK's full batch (512 spans of 50 KB, 26 MB) | 1.0 to 1.3 GB |
| each a body at the limit of 64 MiB | 2.0 GB (JSON) to 2.7 GB (protobuf) |
| small requests (130 to 160 KB) with a resource of 100 KB, copied into each span up to the cap of 128 MiB | 5.6 GB (2.8 GB with the old cap of 64 MiB) |

No SDK sends the last shape. On a small machine, lower the SDK's batch together with `--max-body-bytes` and `--max-mapped-bytes`. See [Memory and threads](https://docs.magpiedb.com/operations/errors-memory.md#memory-and-threads).

## Other limits

* An export has no time limit and no size limit, and it holds one thread while it runs, also while a slow client reads. The number of exports at one time has no limit.
* No rate limit. Without `--auth keys` there is no authentication, and without `--tls-*` no TLS: use a private network, or a proxy that does both.
* API keys have no expiry date and no per-key limits. To revoke a key, remove its line (in effect within about 2 s).
* One store, one folder, one writer: a second writer is refused. With `--tenants-dir`, one server per tenants folder. With `--s3`, one writer per prefix.
* Tenants: other tenants' first requests wait while a tenant store opens or closes (ms; longer if a close waits for a merge). Each tenant that writes commits on its own 0.5 s timer, so commits and disk flushes grow with the number of tenants that write at once.
* Numbers in JSON answers are plain JSON numbers: `costNanos` sums above 2^53 lose precision in JavaScript.
* What the mapping does not keep: [Mapping](https://docs.magpiedb.com/reference/mapping-cost-masking.md#what-the-mapping-does-not-keep).
* Speed of the server was not measured. Do not read numbers from the tests.

> [card] [Server flags](https://docs.magpiedb.com/reference/server.md)
>
> Every flag and its default.

> [card] [Errors, memory and threads](https://docs.magpiedb.com/operations/errors-memory.md)
>
> What each error means. How much memory to give.


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