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

# Count spans

> POST /v1/count: the number of spans that match a filter.

`POST /v1/count` returns the number of spans that match a filter. Right: `read`.

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

```json 200 theme={null}
{"count":3}
```

## Body

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

A [span filter](https://docs.magpiedb.com/reference/api/filters.md#span-filter). Left out: every span.

## Answer

**count** `integer`

The number of matching spans.

> [card] [Find spans](https://docs.magpiedb.com/reference/api/search.md)
>
> The matching spans, in pages.

> [card] [Filters](https://docs.magpiedb.com/reference/api/filters.md)
>
> Every field of a span filter.


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