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

# Ingest traces (OTLP)

> POST /v1/traces and the gRPC port: the OpenTelemetry bodies magpie-server takes, partial success, and the status an exporter gets.

`POST /v1/traces` takes OTLP over HTTP on `--http-addr` (default `127.0.0.1:4318`). The gRPC port, `--grpc-addr` (default `127.0.0.1:4317`), takes OTLP/gRPC. With API keys, the key needs the `write` right.

You do not call this route by hand: point an OpenTelemetry SDK or Collector at the server ([OpenTelemetry guide](https://docs.magpiedb.com/guides/opentelemetry.md)). How the server maps a span: [Mapping, cost and masking](https://docs.magpiedb.com/reference/mapping-cost-masking.md).

```sh Request theme={null}
curl -s localhost:4318/v1/traces -H 'content-type: application/json' -d '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"checkout"}}]},"scopeSpans":[{"spans":[{"traceId":"5b8efff798038103d269b633813fc60c","spanId":"eee19b7ec3c1b174","name":"chat gpt-4o","kind":3,"startTimeUnixNano":"1764000000000000000","endTimeUnixNano":"1764000001000000000","attributes":[{"key":"gen_ai.operation.name","value":{"stringValue":"chat"}},{"key":"gen_ai.request.model","value":{"stringValue":"gpt-4o"}}]}]}]}]}'
```

```json 200 theme={null}
{}
```

## What bodies does it take?

| | HTTP | gRPC |
| - | - | - |
| Encoding | protobuf (`application/x-protobuf`) or JSON (`application/json`) | protobuf |
| Compression | none or gzip | none or gzip |
| Content type of the answer | the content type of the request | |

The server writes spans with `upsert`: a batch that arrives twice (a retry) is stored once.

## What the server answers

| HTTP | gRPC | When | SDK retries |
| - | - | - | - |
| `200` | `OK` | Stored. A span that cannot be stored is listed in `partialSuccess` (below). | no |
| `400` | | The body cannot be decoded: it is not JSON, or its frame is not OTLP (`resourceSpans`, `scopeSpans` or `spans` is not a list of objects). The body is a `google.rpc.Status`. | no |
| `401` | `UNAUTHENTICATED` | API keys: no key, or an unknown key. | no |
| `403` | `PERMISSION_DENIED` | The key has no `write` right, or `x-magpie-tenant` is not the tenant of the key. | no |
| `413` | `RESOURCE_EXHAUSTED` | The request is too large ([server limits](https://docs.magpiedb.com/reference/server.md#limits)). | no |
| `415` | | Unknown content type or encoding. | no |
| `429` | `UNAVAILABLE` | Busy: 16 writes run and 64 wait. With `Retry-After: 1`. | yes |
| `503` | `UNAVAILABLE` | The store cannot write. On a nearly full disk the text starts with `io: DISK_FULL:`. The export passes when there is room again, with no restart ([A full disk](https://docs.magpiedb.com/operations/disk-full.md)). | yes |

## Partial success

The server refuses a bad span alone. The answer is `200` with `partialSuccess` (`rejectedSpans`, `errorMessage`), and the other spans are stored.

```json theme={null}
{"partialSuccess":{"errorMessage":"1 span(s) refused. span 1: traceId must be 16 bytes and not all zero","rejectedSpans":"1"}}
```

* A span is refused for bad ids (not 16 or 8 bytes, or all zero; in JSON also an id that is not hex), no start time, or an end before its start.
* In OTLP/JSON, a span is also refused for a value that is wrong for its field: a time that is no whole number from 0 to 2^64-1, an `intValue` that is no 64-bit integer, a `bytesValue` that is not base64, an item of `attributes` that is not an object.
* The message names the span by its number in the request and the field by its path (`span 7: attributes[1].value.intValue is not a whole number of 64 bits ...`). It does not give the value.
* A wrong value of a resource or a scope refuses the spans of that resource or scope.

> [accordion] How the server reads OTLP/JSON values
>
> The server reads values as the proto3 JSON mapping writes them:
>
> * `"doubleValue": "NaN"`, `"Infinity"` and `"-Infinity"` are those doubles. The Go Collector writes them so. The server stores them as the text `"NaN"`, as over protobuf.
> * A number may come as a text.
> * `kind` and `status.code` may be the names of their values (`"SPAN_KIND_CLIENT"`).
> * `null` is the default of any field.

> [accordion] A text cut inside an emoji
>
> JSON writers (`JSON.stringify`, Python's `json.dumps`) write the half of a UTF-16 surrogate pair that is left as an escape (`"...\ud83d"`). The server stores each such half as U+FFFD, what the protobuf exporters send for the same text. The answer is `200` with `partialSuccess`, `rejectedSpans` `0`, and the count in `errorMessage` (the OTLP spec allows a warning so).
>
> The same holds for every JSON the server reads (the query API, `import`), and for the Node and Python packages.

> [accordion] Very deep values
>
> A span has at most 64 levels ([depth rule](https://docs.magpiedb.com/reference/api/errors.md#how-deep-can-a-filter-be)). A JSON text deeper than 128 levels gets `400`. An OTLP body cannot bring a span that deep: the OTLP readers stop a deeper value first, also with `400`. Protobuf stops at 100 of its own levels (a list in a list is two). JSON stops at 128 (a list in a list is three). Over gRPC the answer is `INTERNAL`, from the gRPC library, before the server sees the body.

> [card] [OpenTelemetry guide](https://docs.magpiedb.com/guides/opentelemetry.md)
>
> Point an app, a framework or a Collector at Magpie.

> [card] [Find spans](https://docs.magpiedb.com/reference/api/search.md)
>
> Query the spans you sent.


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