# POST /api/v1/agents/roles

> Create an agent role

- **Tag:** agents
- **Operation ID:** `agents_create_role`

## Description

Add an agent to the team. The claude_code and codex engines run on the firm's own subscriptions and are for DayZero staff only (AGENT_003). Business admins only.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Request body

Schema: `AgentRoleCreate`

- `name` (string · required) — Short role name, e.g. Bookkeeper.
- `title` (string)
- `instructions` (string) — Standing instructions (markdown).
- `skills` (array · AgentSkill) → `AgentSkill`
  - `name` (string · required)
  - `description` (string)
  - `body` (string) — Markdown the role reads when the skill applies.
  - `enabled` (boolean)
  - `learned` (boolean)
- `engine` (string) (one of: native, claude_code, codex) — native runs DayZero's own loop on Gemini (every role); claude_code and codex run the firm's CLIs on its subscriptions (DayZero staff only).
- `model` (string) — Model id for the engine; null = the engine's default (google/gemini-4-argon).
- `scope` (string) (one of: read, changes) — read never proposes; changes files gated writes as proposed changes.
- `allowed_tools` (array · string) — Tool access: tool names, group:<mount> (a whole tool group) and server:<handle> (a connected MCP server); null = every tool its scope allows. AGENT_026 for a token it cannot hold.
- `params` (object)
- `spend_cap_usd_month` (string) — Monthly spend cap in USD; new runs refuse above it and a run in flight stops before its next turn once it is reached.
- `max_cost_usd_run` (string) — Default cost limit of one run in USD; null = no per-run limit.
- `browser` (boolean) — Drives a real browser with saved logins (Claude Code or Codex only).
- `library_key` (string)
- `persona` (AgentPersonaUpdate) — Face and vibe; what is left out gets the first color and body no other role on the team has, and the steady vibe.

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_AgentRoleOut_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (AgentRoleOut)

### 400 — Bad Request - Invalid input

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 401 — Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 403 — Forbidden - Insufficient permissions

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 409 — Conflict - Resource already exists or is in an incompatible state

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 422 — Validation Error

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/agents/roles' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/agents/roles', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "name": "string"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {'name': 'string'}

response = httpx.post("https://api.ondayzero.com/api/v1/agents/roles", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/agents/agents-create-role
- OpenAPI slice: https://www.ondayzero.com/docs/reference/agents/agents-create-role/openapi.json
- Other endpoints in **agents**: https://www.ondayzero.com/docs/reference/agents (markdown bundle: https://www.ondayzero.com/docs/reference/agents.md, OpenAPI: https://www.ondayzero.com/docs/reference/agents/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
