# HTTP — `POST /v1/subAccounts`

Creates a sub-account for the owner of the wallet session. Requires the
owner's Para wallet session. An API key cannot create a sub-account.
[Sub-accounts](/concepts/sub-accounts) explains how many sub-accounts an owner
can hold.

```http
POST /v1/subAccounts
Authorization: Bearer <para-jwt>
X-Tessera-Wallet: 0x... # required when the JWT has multiple EVM wallets
Content-Type: application/json
```

```json
{ "name": "mm-1" }
```

`name` is the only field, and it is required. A name has 1 to 32 characters:
ASCII letters, digits, spaces, `_`, and `-`. It starts with a letter or a
digit. `master` is reserved, in any case. Names are unique per owner, and the
comparison ignores case.

Example HTTP `200` response:

```jsonc
{
  "status": "ok",
  "data": {
    "created": true,
    "account": {
      "address": "0x9f3c5d0e7a41b2c86f1d94e03a5b7c2d18e6f0a1",
      "name": "mm-1",
      "kind": "sub",
      "slot": 1,
      "createdAtMs": 1790000000000
    },
    "allowance": {
      "allowed": 2,
      "used": 1,
      "volumeUsdc": "1532000.25",
      "nextUnlockAtUsdc": "2000000",
      "override": null
    }
  },
  "server_time_ms": 1790000000100
}
```

| Field | Meaning |
| --- | --- |
| `created` | `true` when this request created the sub-account. `false` when the owner already had a sub-account with this name. |
| `account` | The sub-account. Its fields are those of `accounts[]` in [`GET /v1/subAccounts`](/api/get-sub-accounts), without `totalCashUsdc`. |
| `allowance` | The allowance of the owner after the request, with the fields of `allowance` in `GET /v1/subAccounts`. |

Mosaiq gives the sub-account a random address. The sub-account starts with no
cash and no API key. Its exchange request budget is available at once. To use
the sub-account:

1. Move cash to it with a [`transfer`](/api/exchange#transfer).
2. Create its API key with `POST /v1/apiKeys` and its address in
   [`account`](/api/api-key#create-a-key).

## Send the same name again

A create is idempotent by name. If the owner already has a sub-account with
this name, the answer is `200` with `"created": false` and that sub-account.
The comparison ignores case, and the answer shows the name as it was first
created. A repeated create gets its sub-account back even when the owner has
no free slot. After a timeout, send the same request again.

If two creates race for the last free slot, one of them gets it and the other
fails with `limit_reached` and the detail `sub_account_limit_reached`.

## Errors

| HTTP | `code` | `detail` | Meaning |
| --- | --- | --- | --- |
| `429` | `rate_limited` | `rate_limited` | The client IP exceeded the HTTP budget. |
| `400` | `invalid_request` | `invalid_sub_account_name` | The name breaks a name rule. `msg` names the rule. |
| `400` | `invalid_request` | `invalid_json` | The body is not JSON. |
| `415` | `invalid_request` | `unsupported_media_type` | The `Content-Type` header is missing or is not `application/json`. |
| `422` | `invalid_request` | `invalid_request` | The body has an unknown field, or `name` is missing or not a string. |
| `403` | `limit_reached` | `sub_account_limit_reached` | The owner holds `allowed` sub-accounts already. `data.allowance` has the fields of `allowance`. |
| `401` | `unauthorized` | `wallet_auth_required` | The bearer is an API key. |
| `401` | `unauthorized` | `unauthorized` | Missing bearer, or the token is not a valid Para JWT. |
| `403` | `forbidden` | `not_whitelisted` | The wallet is not allowlisted. |
| `500` | `internal_error` | `internal_error` | Unexpected failure. |

The Para token and wallet-selection errors are the
[shared ones](/api/api-key#errors).

The refusal at the limit carries the allowance next to `code`, `detail`, and
`msg`:

```json
{
  "status": "error",
  "data": {
    "code": "limit_reached",
    "detail": "sub_account_limit_reached",
    "msg": "the owner holds 1 of 1 sub-accounts",
    "allowance": {
      "allowed": 1,
      "used": 1,
      "volumeUsdc": "0",
      "nextUnlockAtUsdc": "1000000",
      "override": null
    }
  },
  "server_time_ms": 1790000000100
}
```
