A label is a key = value pair, for example site = Lyon or classe = 3A. A member label describes a person: it adds them to dynamic groups and can give them roles. A sensitivity label goes on a resource (knowledge base, agent, MCP server, file) to restrict access to it.
All routes are under https://. Scopes: labels:read to read, labels:write to write.
The label objectLink to the The label object section
{
"id": "9b8a7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
"org_id": "8c1f2a4e-5b6d-4e7f-9a0b-1c2d3e4f5a6b",
"key": "classe",
"value": "3A",
"color": "blue",
"kind": "member",
"source": "manual",
"created_at": 1793836800
}| Field | Description |
|---|---|
key | Lowercased, repeated spaces collapsed; letters, digits, spaces, _, . and -, up to 64 characters. |
value | Repeated spaces collapsed, case kept, up to 128 characters, no |. |
color | gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink or rose. |
kind | member or sensitivity. |
source | manual, or directory for a label that came from the directory. |
Two labels cannot have the same key and the same value (case-insensitive). In lists, each label also carries member_count and assignment_count.
List labelsLink to the List labels section
GET /labels · labels:read
| Parameter | Type | Description |
|---|---|---|
q | string | Searches the key or the value. |
kind | string | member or sensitivity. |
key | string | Only this key. |
page, limit | integer | Pagination. Sorted by key, then value. |
The response also includes colors, the list of allowed colors.
Create a labelLink to the Create a label section
POST /labels · labels:write
| Field | Type | Required | Description |
|---|---|---|---|
key | string | yes | 1 to 64 characters. |
value | string | yes | 1 to 128 characters. |
color | string | no | gray by default. |
kind | string | no | member (default) or sensitivity. |
An organization can have up to 5,000 labels. A label that already exists returns 409 with the message Cette (this label already exists).
Update a labelLink to the Update a label section
PATCH / · labels:write
Optional fields key, value, color and kind. Labeled members and resources follow the new key or value. A label named in a dynamic group’s rule cannot change its key or value: 409 , with groups, the names of the groups involved. Change their rule first.
Delete a labelLink to the Delete a label section
DELETE / · labels:write
Removes the label from every member, group and resource, and removes the roles it gave. Response: {"success": . Refused (409 ) as long as a dynamic group names it.
Assign a labelLink to the Assign a label section
POST / · labels:write
| Field | Type | Required | Description |
|---|---|---|---|
subject_type | string | yes | user (members), group or resource. |
subject_ids | list | yes | 1 to 1,000 IDs. |
resource_type | string | for resource | knowledge, agent, mcp_server or library (a file in the workspace library). |
curl https://chat.realmoon.ai/api/v1/orgs/$ORG_ID/labels/$LABEL_ID/assignments \
-H "Authorization: Bearer $MOONAI_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{"subject_type": "user", "subject_ids": ["<member id>", "<member id>"]}'import os
import requests
BASE = f"https://chat.realmoon.ai/api/v1/orgs/{os.environ['ORG_ID']}"
HEADERS = {"Authorization": f"Bearer {os.environ['MOONAI_ADMIN_KEY']}"}
r = requests.post(
f"{BASE}/labels/{os.environ['LABEL_ID']}/assignments",
headers=HEADERS,
json={"subject_type": "user", "subject_ids": ["<member id>", "<member id>"]},
timeout=30,
)
r.raise_for_status()
print(r.json()["added"])const BASE = `https://chat.realmoon.ai/api/v1/orgs/${process.env.ORG_ID}`;
const r = await fetch(`${BASE}/labels/${process.env.LABEL_ID}/assignments`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.MOONAI_ADMIN_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ subject_type: 'user', subject_ids: ['<member id>', '<member id>'] }),
});
if (!r.ok) throw new Error(await r.text());
console.log((await r.json()).added);Response: {"success": . Subjects that already have the label are skipped. Putting a label on members can add them to dynamic groups and give them roles, right away.
| Status | code | Cause |
|---|---|---|
| 400 | invalid_request | Sensitivity label on members; resource_type missing for a resource, or present for a member or a group. |
| 403 | forbidden | Labeling the key’s creator without the permission to set groups; a label that puts members into groups subject to rules or that assigns a license, when the key only acts on managed groups. |
| 403 | role_escalation | The label would give roles the key does not have. |
| 403 | license_change_forbidden | The change would move members to another license pool; it requires licenses:write. |
| 404 | not_found | Members, group or resource not found. |
Putting a label on a group or a resource requires the permission to manage labels; on members, the permission to assign them.
Remove a labelLink to the Remove a label section
DELETE / · labels:write
Same body as assigning (resource_type is ignored). Response: {"success": . Subjects without the label are skipped. Members can leave dynamic groups and lose roles.