> For the complete documentation index, see [llms.txt](https://docs.meganova.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.meganova.ai/api-reference/platform-api/search/create-request-group.md).

# Create Request Group

Mint a signed request group so one prompt's search fan-out bills as a single unit.

```
POST {API_URL}/serverless/search/group
```

Issues a signed token identifying **one user prompt**. Send it as `X-Request-Group-Id` on every `/search` call belonging to that prompt: the first is billed, the rest are free fan-out, up to the token's budget and expiry.

> **Token Plan keys only.** Ordinary keys keep passing any string they like as `X-Request-Group-Id` — their dedup spends nothing but their own daily quota, so there is nothing for a signature to protect. This endpoint returns `403` for them.

## Why this exists

A request group decides what is free, so whoever controls the group identifier controls what gets billed. For ordinary keys that only affects the caller's own daily quota. For a Token Plan key it decides how much of a paid monthly allowance is consumed, and a plain string is an unverifiable claim that N calls belong to one prompt.

The token is that claim, signed by the server. A client cannot widen the budget, extend the expiry, or use a token minted for a different subscription or key.

## Request

No body. Authentication identifies the subscription and the key.

```bash
curl -X POST https://api.meganova.ai/api/v1/serverless/search/group \
  -H "Authorization: Bearer sk-..."
```

## Response

```json
{
  "status": "success",
  "message": "Request group created",
  "data": {
    "token": "mgs1.eyJiIjoxMCwiZSI6MTc4NjAyODQwMCwi...",
    "group_id": "abf15924-e656-4731-b18a-3dbd76f2c484",
    "expires_at": 1786028400,
    "budget": 10
  }
}
```

| Field             | Meaning                                                                                                                    |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `data.token`      | Send this verbatim as `X-Request-Group-Id`. Roughly 180 characters.                                                        |
| `data.group_id`   | The identifier recorded in usage telemetry — useful for correlating your own logs with what admin sees. Not what you send. |
| `data.expires_at` | Epoch seconds. Default lifetime 10 minutes.                                                                                |
| `data.budget`     | Calls allowed under this group, including the billed first one. Default 10.                                                |

Both limits are signed into the token, so this response is the only place either is set.

## Using it

```python
import requests

BASE = "https://api.meganova.ai/api/v1"
H = {"Authorization": f"Bearer {KEY}"}

# once per user prompt
group = requests.post(f"{BASE}/serverless/search/group", headers=H).json()["data"]

# every search for that prompt carries the same token
for q in ["capital of Canada", "population of Ottawa", "Ottawa timezone"]:
    requests.post(
        f"{BASE}/serverless/search",
        headers={**H, "X-Request-Group-Id": group["token"], "Content-Type": "application/json"},
        json={"query": q, "max_results": 3},
    )
# one billable unit, three searches
```

Mint a new token per prompt. Carrying one across unrelated prompts is not rejected, but its budget and expiry are fixed at mint time, so it simply runs out sooner — and the calls under it stop being attributable to the prompt that caused them, which is what the group is for.

## What happens without a token

A Token Plan key that sends an unsigned `X-Request-Group-Id` is **not rejected** — the call succeeds. It simply earns nothing: the server assigns a fresh group, so that call is billed as the standalone prompt it cannot be proven not to be. Fan-out sent this way is billed per call.

So an unsigned group is not an error, it is just the expensive way to do it.

## Errors

| Status                     | Cause                                                                                                                                                                                                                                                                   |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401`                      | Missing or invalid key.                                                                                                                                                                                                                                                 |
| `403`                      | The key is not a Token Plan member key.                                                                                                                                                                                                                                 |
| `400` on a later `/search` | The `X-Request-Group-Id` you sent is a malformed, altered, or expired token, or belongs to another subscription or key. A bad signature is rejected rather than quietly downgraded, so this always means something is wrong with the token rather than with the search. |
| `429` on a later `/search` | The group's fan-out budget is spent. Mint a new group for the next prompt.                                                                                                                                                                                              |

## Related

* [Search Query](https://docs.meganova.ai/api-reference/platform-api/search/search-query.md) — the `X-Request-Group-Id` header
* [Web Search overview](https://docs.meganova.ai/api-reference/platform-api/search.md) — how Token Plan keys bill
* [Libra OS Integration Guide](https://docs.meganova.ai/enterprise/token-plan.md)
