# Create a team

`POST https://evohub.io/api/v1/teams`

Part of the [Organization API](https://docs-dev.evohub.io/organization.md) reference · operationId `createTeam`.

Creates a team, optionally with its first members. A member id that is not in
the organization is skipped.

**Permission (API-key scope):** `identity:team:write`.

## Authorization

Any one of:

- `bearerAuth` (identity:team:write)
- `apiKeyHeader` (identity:team:write)

Where:

- `bearerAuth`: HTTP Bearer — An EvoHub API key (`evohub_…`) as a bearer token.
- `apiKeyHeader`: API key in the header `X-API-Key` — An EvoHub API key (`evohub_…`).

## Request body (required)

Content type: `application/json`

Type: `object`

- `name` (string, required, min length 1, max length 100)
- `slug` (string)
- `description` (string)
- `members` (array of object)
  - `user_id` (string, required)
  - `role` (TeamMemberRole, one of `admin`, `member`, `viewer`, default `member`)

## Responses

### 201 — The team.

Content type: `application/json`

Type: `object`

- `data` (Team, required)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `description` (string)
  - `org_id` (string, required)
  - `member_count` (integer, required)
  - `member_ids` (array of string, required)
  - `created_at` (string (date-time), required)
  - `updated_at` (string (date-time), required)
- `success` (boolean, required, value `true`)

### 400 — Not JSON (`INVALID_BODY`), or the name is empty or longer than 100 characters (`VALIDATION_ERROR`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

### 401 — No API key was sent, or it is unknown, revoked or expired (`UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

### 403 — The key lacks the scope this endpoint needs (`FORBIDDEN`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

### 409 — A team with that name or slug exists (`TEAM_NAME_TAKEN`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

### 429 — Too many requests (`RATE_LIMITED`). Wait `Retry-After` seconds.

Headers:

- `Retry-After` (integer): Seconds to wait.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

### 500 — Something went wrong on EvoHub's side (`INTERNAL_ERROR`). Retry later.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The response's `X-Request-ID`; quote it to support.

## Example request

```bash
curl -X POST 'https://evohub.io/api/v1/teams' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "name": "Platform",
  "slug": "platform",
  "members": [
    {
      "role": "member",
      "user_id": "usr_7a3c9e10-b2d4-4f6a-8c1e-5d7f9a0b2c3e"
    }
  ],
  "description": "Owns the core API"
}'
```
