# REST API list responses: why total counts every match

> /projects, /tags and /proxies returned bare arrays in version 1. Now every list carries total, and it says 344 when the page holds 50.

Source: https://mosaicbrowser.com/blog/every-list-one-shape

## Why every list in our API answers in one shape

/projects, /tags and /proxies returned bare arrays in version 1. Now every list carries total, and it says 344 when the page holds 50.

![344: total said 344 while the page held 50](https://mosaicbrowser.com/covers/every-list-one-shape.webp)

A list endpoint should answer with an object, not a bare array, and that object should carry `total`: the number of rows that matched the filters, not the number on this page. That is the rule Mosaic's local API follows for every collection. We arrived at it the usual way, by shipping three different shapes first.

## Three shapes in version 1

The first version of `/api/v1` answered a list in whichever shape the route's author reached for:

- a bare array from `/projects`, `/tags` and `/proxies`
- `{ total, profiles }` from `/profiles`
- a bare `{ engines }`, with no count, from `/engines`

A caller had to remember which was which. Worse, the bare arrays were stuck. A JSON array has no room for a second field, so the day a count or a page was needed on `/proxies`, every script reading it as an array would have broken.

Every collection is now `{ total, <items> }`, with the list under a key named for what it holds:

```
{ "total": 12, "proxies": [ ... ] }
{ "total": 3, "projects": [ ... ] }
{ "total": 2, "engines": [ ... ], "install": { ... } }

```

The key is the noun, not a generic `items`, because a response read in a log or pasted into a chat should say what it is. The fixed part is that `total` sits at the top of every list and the list itself is never the whole body. A route that needs to say more adds a field beside them, as `/engines` does with the install state, and nobody's parser breaks.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: REST API](https://mosaicbrowser.com/features/rest-api)

## Why the total count in a list response counts every match

`/profiles` is the collection that grows. Libraries run to hundreds of profiles, and before paging the only way to read one was all of it on every poll. So it takes `limit` and `offset`:

```
GET /api/v1/profiles?projectId=p_shop&limit=50&offset=100

```

and answers:

```
{ "total": 344, "limit": 50, "offset": 100, "profiles": [ ... 50 rows ... ] }

```

`total` is 344 there, not 50. The caller can already count the rows it got. What it cannot see from the page is whether there is a next one. With `total` counting every row that matched the project, search and tag filters, the loop is plain arithmetic: keep going while `offset + limit < total`. If `total` meant the page, the only way to find the end would be to ask for a page past it and get nothing back, which is one wasted request on every full read.

Some APIs answer this with a `hasMore` flag or a cursor instead, usually because counting a huge table is expensive. Our store is on the same computer and counting a few thousand profiles in memory costs next to nothing, so we give the full number and the caller gets both answers from it.

## What paging refuses

Two choices in `pageOf`, the one function every paged route uses:

1. **Absent means everything.** With no `limit`, REST returns the whole collection. Adding paging did not change what an existing script received. A cap of 1,000 per request stops one call from serialising an unbounded library.
2. **Wrong means a 400.** `?limit=abc`, `-1` or `2.5` is refused with `limit must be a whole number of 0 or more.` Treating an unreadable value as absent would hand back every row, and the caller would believe its paging worked.

## The same rule, on the surface nobody asked

The rule was written for REST, and a check (`check:api-behaviour`) held REST to it. MCP is the other public door to the same store, the one an AI assistant calls, and nothing had asked it the same question. When we did, against the running app with the same data in the same minute, seven tools disagreed with their REST twins:

| Tool | REST | MCP |
| --- | --- | --- |
| `list_projects` | `{ total, projects }` | bare array |
| `list_profiles` | `{ total, profiles }` | bare array, no paging |
| `list_proxies` | `{ total, proxies }` | bare array |
| `list_folders` | `{ total, folders }` | bare array |
| `list_scenarios` | `{ total, scenarios }` | bare array |
| `list_engines` | `{ total, engines }` | bare array |
| `list_running` | none | bare array |

`list_profiles` was the one that cost something. With no `total` a model paging a library could not tell whether there was more, and with no `limit` it received every row at once: eight hundred profiles into one context window, because the REST route had grown paging and its twin had not. Warm-up presets drifted on both surfaces together, a bare `{ presets, defaults }` with no count, so there was no correct copy to compare the wrong one against.

All of them carry `total` now. `list_profiles` takes `limit` and `offset` with a default of 100 and a maximum of 500, and its own description tells the model that `total` counts every match. How an assistant uses that over a real library is in [letting an AI assistant run profiles over MCP](https://mosaicbrowser.com/blog/ai-assistant-runs-profiles).

## A rule nobody checks drifts

The check now walks fourteen tools plus the paging contract on both surfaces. We put each fault back to watch it fire, and the two lines it printed were the right ones:

```
MCP list_engines returns a bare array; every collection returns { total, engines }.
MCP list_profiles limit=1 returned 40 profiles.

```

If you are designing a list response, the short version is what we would have saved ourselves: an object from day one, the list under a named key, `total` for every match, and a 400 for a limit you cannot read. The full route list for Mosaic is on the [REST API](https://mosaicbrowser.com/features/rest-api) page, the tools on the [MCP server](https://mosaicbrowser.com/features/mcp-server) page, and a worked script in [the local API guide](https://mosaicbrowser.com/guides/anti-detect-browser-local-api).

## Questions

### Should a REST API return a bare array or an object for a list?

An object. A bare JSON array has nowhere to put a count, a page position or a note, so adding any of them later breaks every caller that expects an array. An object with the items under a named key can grow without breaking anyone.

### Should total be the number of items returned or the number that matched?

The number that matched the filters, before paging. The length of the returned list is already visible to the caller. Only the full count tells them whether another page exists and how many requests it will take to read everything.

### What should an API do with limit=abc?

Refuse it with a 400 that names the field. Treating an unreadable limit as absent quietly returns the whole collection, and the caller never learns its paging was ignored. Mosaic answers limit must be a whole number of 0 or more.

### Do Mosaic's MCP tools return lists in the same shape as REST?

Yes. The MCP list tools answer with the same total plus a named list as their REST twins, and list_profiles takes limit and offset. A check calls both surfaces against the running app and fails when one drifts.

## Related

[Anti-detect browser REST API: profiles from your scripts](https://mosaicbrowser.com/features/rest-api): Mosaic's anti-detect browser REST API runs on 127.0.0.1 with API keys. Create and start profiles, then attach Puppeteer or Playwright over CDP.

[An anti-detect browser MCP server for your AI assistant](https://mosaicbrowser.com/features/mcp-server): Mosaic's anti-detect browser MCP server lets Claude or any MCP client create, launch and drive your profiles. 150+ tools, off by default, key-gated.

[Anti-detect browser local API: what it is and what to check](https://mosaicbrowser.com/guides/anti-detect-browser-local-api): An anti-detect browser local API is an HTTP server on 127.0.0.1 that creates, starts and stops profiles and hands your script a DevTools endpoint.

[Letting an AI assistant run browser profiles over MCP](https://mosaicbrowser.com/blog/ai-assistant-runs-profiles): Mosaic's MCP server lets Claude or any MCP client create, start and drive browser profiles. Three faults we found when a model was the caller.









[A regex that lost its backslashes inside a template literal](https://mosaicbrowser.com/blog/regex-in-template-literal): A template literal turns \s into s, so a regex shipped inside one matches nothing and throws nothing. It hid five of our detector rows as unread.

[Thirty tabs open: why a test suite needs a fresh tab per site](https://mosaicbrowser.com/blog/one-tab-per-detector): Captcha popups and ad windows left about 30 tabs open in our detector runner. Now each test gets its own tab, and a sweep closes every stray when it ends.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
