# Create tenant

> Source: https://truto.one/docs/api-reference/admin/tenants/create/

`POST /tenant`

Resource: **Tenants**

## Request body

- **`id`** _(string)_
  Your identifier for the tenant. URL-path-safe: letters, digits, and `. _ : @ + -`. Up to 255 characters. Immutable — cannot be changed later.
- **`name`** _(string)_
  Display name. Defaults to `id` when omitted.
- **`metadata`** _(object)_
  Free-form JSON object. Stored and returned verbatim.
- **`environment_id`** _(string)_
  Which environment to create the tenant in. Required for session auth; ignored for API tokens (inferred from the token).

## Response body

- **`id`** _(string)_
  The tenant identifier — caller-chosen, URL-path-safe, and immutable once created. Composite primary key with `environment_id`, so the same value can exist independently in `development`, `staging`, and `production`. Must match `^[A-Za-z0-9._:@+-]{1,255}$`.
- **`environment_id`** _(string)_
  The environment this tenant belongs to.
- **`name`** _(string)_
  Display name shown in the dashboard. Defaults to the tenant `id` on create if not supplied; can be edited later via `PATCH /tenant/{id}`.
- **`metadata`** _(object)_
  Free-form JSON object stored verbatim. Truto does not interpret this field — use it for tier, region, billing plan, or any other customer attribute your app cares about.
- **`created_at`** _(string)_
  The date and time when the tenant was created.
- **`updated_at`** _(string)_
  The date and time when the tenant was last updated.

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/tenant' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": "acme-corp",
  "name": "Acme Corp",
  "metadata": {
    "tier": "gold",
    "region": "wnam"
  },
  "environment_id": "8a2b104d-74a6-47f2-b93e-c6b611e82391"
}'
```

### JavaScript

```javascript
const body = {
  "id": "acme-corp",
  "name": "Acme Corp",
  "metadata": {
    "tier": "gold",
    "region": "wnam"
  },
  "environment_id": "8a2b104d-74a6-47f2-b93e-c6b611e82391"
};

const response = await fetch('https://api.truto.one/tenant', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/tenant"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "id": "acme-corp",
    "name": "Acme Corp",
    "metadata": {
        "tier": "gold",
        "region": "wnam"
    },
    "environment_id": "8a2b104d-74a6-47f2-b93e-c6b611e82391"
}

response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())
```
