# Teams

> Teams, the levels between the organization and the person, kept in Gateway (the sign-in provider has no teams). Teams nest: a team may have a parent team (no cycles, at most 10 levels) and a `level`, a free-text label each organization chooses. Someone added by an email not in the organization yet is a pending member until they join it. An organization can load its whole tree from a file (`POST /v1/teams/import`). Owners and admins create, rename and delete teams and manage their members; every member reads them and sets their own default team. Spend is attributed to the team named with `x-nexus-team` (or a `team` field), else the caller's default team. Team caps and person budgets are built: see Budgets. Team model policies are built: see Models.

## List teams

`GET /v1/teams`

The organization's teams, with member counts, your role in each and your default team (every member). With `tree=1`: the teams nested under their parents, with leads and headcount. The list (not the tree) pages with `limit` and `cursor`.

Permission: `teams.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `tree` | query | "1" | no | 1: return `tree` (nested) instead of `teams` |
| `depth` | query | integer | no | With tree=1: how many levels to return |
| `limit` | query | integer | no | Items per page, 1 to 500 (default 100). Without limit or cursor the answer holds the whole list. |
| `cursor` | query | string | no | NextCursor from the previous page. A cursor whose item left the list answers 400 `invalid_cursor`. |

### Responses

- `200` OK (application/json, object)
  - `teams` (array of Team)
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `description` (string)
    - `createdAt` (string (date-time), required)
    - `members` (integer, required)
    - `myRole` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean)
    - `parentId` (string): The parent team's id; absent for a top-level team.
    - `parent` (string): The parent team's slug.
    - `level` (string): The organization's own label for the team's level (e.g. department).
    - `depth` (integer, required): 1 for a top-level team.
    - `pending` (integer, required): People added by email who have not joined the organization yet.
    - `childCount` (integer, required)
  - `default` (string | null)
  - `tree` (array of TeamNode): With tree=1: the top-level teams.
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `description` (string)
    - `createdAt` (string (date-time), required)
    - `members` (integer, required)
    - `myRole` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean)
    - `parentId` (string): The parent team's id; absent for a top-level team.
    - `parent` (string): The parent team's slug.
    - `level` (string): The organization's own label for the team's level (e.g. department).
    - `depth` (integer, required): 1 for a top-level team.
    - `pending` (integer, required): People added by email who have not joined the organization yet.
    - `leads` (array of object)
      - `userId` (string)
      - `email` (string)
      - `name` (string)
      - `pending` (boolean)
    - `headcount` (integer): Distinct people in the team and every team under it, pending ones included.
    - `children` (array of TeamNode) (same shape as TeamNode)
  - `nextCursor` (string): The next page's cursor, while more items follow. Only when limit or cursor was sent.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/teams" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.teamTree(2);
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fteams)

## Create team

`POST /v1/teams`

Create a team (owners and admins), optionally under a parent team and with a level label. The slug is unique in the organization and follows the org slug rule (`pending` and `import` are reserved). An organization holds at most 2,000 teams: the next is refused with 409 `team_limit`.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `slug` (string, required)
- `name` (string)
- `description` (string)
- `parent` (string | null): The parent team's slug or id; absent or null for a top-level team.
- `level` (string): A short label of the organization's choosing: 1 to 32 lower-case letters, digits or dashes.

### Responses

- `201` Created (application/json, TeamDetail)
  - `id` (string, required)
  - `slug` (string, required)
  - `name` (string, required)
  - `description` (string)
  - `createdAt` (string (date-time), required)
  - `members` (integer, required)
  - `myRole` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
  - `isDefault` (boolean)
  - `parentId` (string): The parent team's id; absent for a top-level team.
  - `parent` (string): The parent team's slug.
  - `level` (string): The organization's own label for the team's level (e.g. department).
  - `depth` (integer, required): 1 for a top-level team.
  - `pending` (integer, required): People added by email who have not joined the organization yet.
  - `childCount` (integer, required)
  - `memberList` (array of TeamMember)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean, required)
    - `joinedAt` (string (date-time), required)
  - `pendingList` (array of PendingMember)
    - `id` (string, required)
    - `teamId` (string, required)
    - `team` (string, required): The team's slug.
    - `email` (string, required)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `home` (boolean, required): Becomes their default team when they join.
    - `addedBy` (string)
    - `createdAt` (string (date-time), required)
  - `path` (array of TeamLink): The team's ancestors, top level first; the last is its parent.
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
  - `children` (array of TeamLink & object)
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
    - `members` (integer)
    - `pending` (integer)
    - `childCount` (integer)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 | `team_limit` | The next is refused with 409 `team_limit` |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/teams" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "web",
    "name": "Web",
    "parent": "engineering",
    "level": "department"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.createTeam({ slug: "platform", name: "Platform", parent: "engineering", level: "team" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fteams)

## List pending team members

`GET /v1/teams/pending`

Pending team members: people added by an email not in the organization yet (owners and admins). With `by=person`, one row per email with all their teams and their home team, and whether Gateway can invite them.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `team` | query | string | no | Only this team (slug) |
| `by` | query | "entry" \| "person" | no | `person`: group by email (`people`); default: one row per pending membership (`pending`) |

### Responses

- `200` OK (application/json, object | object)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/teams/pending" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.pendingPeople();
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fteams%2Fpending)

## Cancel pending team members

`DELETE /v1/teams/pending`

Cancel pending team members (owners and admins): one by `id`, or every one for an `email` (optionally in one `team`).

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | query | string | no |  |
| `email` | query | string | no |  |
| `team` | query | string | no |  |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, object)
  - `cancelled` (array of PendingMember)
    - `id` (string, required)
    - `teamId` (string, required)
    - `team` (string, required): The team's slug.
    - `email` (string, required)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `home` (boolean, required): Becomes their default team when they join.
    - `addedBy` (string)
    - `createdAt` (string (date-time), required)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/teams/pending" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.cancelPendingTeamMembers({ email: "new-hire@example.com" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fteams%2Fpending)

## Import teams

`POST /v1/teams/import`

Load the organization's teams from a file, in one transaction (owners and admins). Teams are matched by slug: missing ones are created, existing ones moved, renamed and relabelled; leads and members are set by email (pending for emails not in the organization yet) and `home` sets default teams. Idempotent: the same file twice changes nothing the second time. `dryRun` returns the same diff and changes nothing; `prune` also removes what the file does not list (never spend). A dry run returns a `plan` (a hash of the diff): apply with `plan` set to it and Gateway refuses (409 `plan_changed`) if the organization changed since, so exactly the reviewed changes apply. An import that would leave more than 2,000 teams in the organization, and adds any, is refused with 409 `team_limit`.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `units` (array of object, required)
  - `slug` (string, required)
  - `name` (string)
  - `level` (string | null)
  - `parent` (string | null): The parent team's slug; absent or null for a top-level team.
  - `description` (string | null)
  - `leads` (array of string (email) | object)
  - `members` (array of string (email) | object)
- `dryRun` (boolean): Report the diff and change nothing.
- `prune` (boolean): Also remove memberships and pending entries the file does not list from its teams, and delete teams it does not list (their spend stays).
- `plan` (string): A dry run's plan: apply only if the result is still exactly that (else 409 plan_changed). [pattern ^[0-9a-f]{16}$]

### Responses

- `200` OK (application/json, TeamImportDiff)
  - `dryRun` (boolean, required)
  - `prune` (boolean, required)
  - `created` (array of string, required)
  - `moved` (array of object, required)
    - `slug` (string)
    - `from` (string)
    - `to` (string)
  - `renamed` (array of object, required)
    - `slug` (string)
    - `from` (string)
    - `to` (string)
  - `relevelled` (array of object, required)
    - `slug` (string)
    - `from` (string)
    - `to` (string)
  - `membershipsAdded` (array of object, required)
    - `team` (string)
    - `email` (string)
    - `role` (string)
  - `rolesChanged` (array of object, required)
    - `team` (string)
    - `email` (string)
    - `from` (string)
    - `to` (string)
  - `membershipsRemoved` (array of object, required)
    - `team` (string)
    - `email` (string)
    - `role` (string)
  - `pending` (array of object, required)
    - `team` (string)
    - `email` (string)
    - `role` (string)
  - `pendingRemoved` (array of object, required)
    - `team` (string)
    - `email` (string)
  - `defaults` (array of object, required)
    - `email` (string)
    - `team` (string)
    - `pending` (boolean)
  - `deleted` (array of string, required)
  - `warnings` (array of string, required)
  - `totals` (object, required)
    - `teams` (integer)
    - `memberships` (integer)
    - `pending` (integer)
  - `plan` (string, required): A short hash of this diff; pass it back as plan to apply exactly what a dry run showed.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 | `plan_changed` | Apply with `plan` set to it and Gateway refuses (409 `plan_changed`) if the organization changed since, so exactly the reviewed changes apply |
| 409 | `team_limit` | An import that would leave more than 2,000 teams in the organization, and adds any, is refused with 409 `team_limit` |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/teams/import" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "units": [
      {
        "slug": "engineering",
        "level": "department",
        "leads": [
          {
            "email": "lead@example.com"
          }
        ]
      },
      {
        "slug": "platform",
        "parent": "engineering",
        "level": "team",
        "members": [
          {
            "email": "dev@example.com",
            "home": true
          }
        ]
      }
    ],
    "dryRun": true
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.importTeams({ units: [{ slug: "platform", parent: "engineering", members: ["ada@example.com"] }], dryRun: true });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fteams%2Fimport)

## Get team

`GET /v1/teams/{slug}`

A team, its members, pending members, path (ancestors) and child teams (every member).

Permission: `teams.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |

### Responses

- `200` OK (application/json, TeamDetail)
  - `id` (string, required)
  - `slug` (string, required)
  - `name` (string, required)
  - `description` (string)
  - `createdAt` (string (date-time), required)
  - `members` (integer, required)
  - `myRole` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
  - `isDefault` (boolean)
  - `parentId` (string): The parent team's id; absent for a top-level team.
  - `parent` (string): The parent team's slug.
  - `level` (string): The organization's own label for the team's level (e.g. department).
  - `depth` (integer, required): 1 for a top-level team.
  - `pending` (integer, required): People added by email who have not joined the organization yet.
  - `childCount` (integer, required)
  - `memberList` (array of TeamMember)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean, required)
    - `joinedAt` (string (date-time), required)
  - `pendingList` (array of PendingMember)
    - `id` (string, required)
    - `teamId` (string, required)
    - `team` (string, required): The team's slug.
    - `email` (string, required)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `home` (boolean, required): Becomes their default team when they join.
    - `addedBy` (string)
    - `createdAt` (string (date-time), required)
  - `path` (array of TeamLink): The team's ancestors, top level first; the last is its parent.
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
  - `children` (array of TeamLink & object)
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
    - `members` (integer)
    - `pending` (integer)
    - `childCount` (integer)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/teams/platform" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.team("platform");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fteams%2F%7Bslug%7D)

## Update team

`PATCH /v1/teams/{slug}`

Change a team (owners and admins): its slug, name, description or level, or move it under another parent (`parent: null` makes it top-level; no cycles, at most 10 levels). Past spend keeps the slug it had; a moved team keeps its history and rollups follow the current tree.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `slug` (string)
- `name` (string)
- `description` (string | null)
- `parent` (string | null): The new parent's slug or id, or null for the top level.
- `level` (string | null): The level label; null clears it.

### Responses

- `200` OK (application/json, TeamDetail)
  - `id` (string, required)
  - `slug` (string, required)
  - `name` (string, required)
  - `description` (string)
  - `createdAt` (string (date-time), required)
  - `members` (integer, required)
  - `myRole` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
  - `isDefault` (boolean)
  - `parentId` (string): The parent team's id; absent for a top-level team.
  - `parent` (string): The parent team's slug.
  - `level` (string): The organization's own label for the team's level (e.g. department).
  - `depth` (integer, required): 1 for a top-level team.
  - `pending` (integer, required): People added by email who have not joined the organization yet.
  - `childCount` (integer, required)
  - `memberList` (array of TeamMember)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean, required)
    - `joinedAt` (string (date-time), required)
  - `pendingList` (array of PendingMember)
    - `id` (string, required)
    - `teamId` (string, required)
    - `team` (string, required): The team's slug.
    - `email` (string, required)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `home` (boolean, required): Becomes their default team when they join.
    - `addedBy` (string)
    - `createdAt` (string (date-time), required)
  - `path` (array of TeamLink): The team's ancestors, top level first; the last is its parent.
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
  - `children` (array of TeamLink & object)
    - `id` (string, required)
    - `slug` (string, required)
    - `name` (string, required)
    - `level` (string)
    - `members` (integer)
    - `pending` (integer)
    - `childCount` (integer)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X PATCH "$NEXUS_URL/v1/teams/platform" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "parent": "engineering",
    "level": "team"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.updateTeam("platform", { parent: "engineering", level: "team" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#patch%3A%2Fv1%2Fteams%2F%7Bslug%7D)

## Delete team

`DELETE /v1/teams/{slug}`

Delete a team and its memberships (owners and admins). A team with child teams is refused (409 `has_children`) unless `cascade=1`, which deletes the whole subtree. Spend attributed to any of them keeps the team's id and slug.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |
| `cascade` | query | "1" | no | 1: also delete every team under it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, object)
  - `deleted` (boolean)
  - `id` (string)
  - `slug` (string)
  - `teams` (array of string): Every team deleted (slugs).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `has_children` | A team with child teams is refused (409 `has_children`) unless `cascade=1`, which deletes the whole subtree |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/teams/platform" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.deleteTeam("platform");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fteams%2F%7Bslug%7D)

## Add team member

`POST /v1/teams/{slug}/members`

Add someone to a team, by userId or email (owners and admins). An email of someone not in the organization yet is kept as a pending membership (202) until they join it. The first team someone joins becomes their default, unless `home` makes this one it.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `userId` (string)
- `email` (string)
- `role` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
- `home` (boolean): Make this their default (home) team; for a pending member, when they join.

### Responses

- `201` Created (application/json, object)
  - `team` (string)
  - `member` (TeamMember)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `isDefault` (boolean, required)
    - `joinedAt` (string (date-time), required)
  - `pending` (false)
- `202` Pending: not in the organization yet (application/json, object)
  - `pending` (true)
  - `team` (string)
  - `entry` (PendingMember): Someone added to a team by an email not in the organization yet; they join the team when they join the organization.
    - `id` (string, required)
    - `teamId` (string, required)
    - `team` (string, required): The team's slug.
    - `email` (string, required)
    - `role` ("lead" | "member", required): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
    - `home` (boolean, required): Becomes their default team when they join.
    - `addedBy` (string)
    - `createdAt` (string (date-time), required)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/teams/platform/members" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ada@example.com",
    "role": "member",
    "home": true
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.addTeamMember("platform", { email: "ada@example.com", role: "member", home: true });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fteams%2F%7Bslug%7D%2Fmembers)

## Remove team member

`DELETE /v1/teams/{slug}/members/{userId}`

Take someone out of a team (owners and admins). If it was their default, another of their teams becomes it.

Permission: `teams.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |
| `userId` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, object)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/teams/platform/members/user_123" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.removeTeamMember("platform", "<user id>");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fteams%2F%7Bslug%7D%2Fmembers%2F%7BuserId%7D)

## Set default team

`PUT /v1/people/{userId}/default-team`

Set a default team: your own (`me`), among the teams you are in; anyone's for owners and admins. `{"team": null}` clears it.

Permission: `teams.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `userId` | path | string | yes | A user id, or `me` |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `team` (string | null, required)

### Responses

- `200` OK (application/json, object)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/people/user_123/default-team" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "team": "web"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.setDefaultTeam("platform");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#put%3A%2Fv1%2Fpeople%2F%7BuserId%7D%2Fdefault-team)

## Get team budget

`GET /v1/teams/{slug}/budget`

A team's cap, as the caller may see it. An owner or admin gets the cap on that team and nothing from the teams above it (`scope: cap`): its limit, period, mode, spent, reserved, what is left and when it resets. A member of the team gets only what is left for them along the team's path, with the period and reset of the cap that binds (`scope: own`); the limit, spent and reserved of a team above theirs are never shown. `budget` is null when no cap applies. 404 `unknown_team`; 403 `not_in_team` for a member who is not in the team.

Permission: `teams.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |

### Responses

- `200` OK (application/json, TeamBudget)
  - `team` (object, required)
    - `slug` (string, required)
    - `name` (string, required)
  - `scope` ("cap" | "own", required): `cap`: an owner or admin reads the cap on this team. `own`: a member reads what is left for them.
  - `budget` (object | null, required): The cap on this team (`cap`), or the cap that binds along the team's path (`own`); null when none applies
    - `remainingUsd` (number, required): What is left for the period, never below 0. Deprecated: read `remainingUsdDecimal`, the exact decimal string (root rule 9).
    - `remainingUsdDecimal` (string): `remainingUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `remainingUsd`.
    - `period` ("day" | "week" | "month", required): How often the cap resets
    - `resetsAt` (string (date-time), required)
    - `limitUsd` (number): Owners and admins only (`scope: cap`). Deprecated: read `limitUsdDecimal`, the exact decimal string (root rule 9).
    - `limitUsdDecimal` (string): `limitUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `limitUsd`.
    - `mode` ("hard_stop"): Owners and admins only
    - `spentUsd` (number): Owners and admins only: settled this period, in the team and the teams under it. Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
    - `spentUsdDecimal` (string): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`.
    - `reservedUsd` (number): Owners and admins only: held by calls in progress. Deprecated: read `reservedUsdDecimal`, the exact decimal string (root rule 9).
    - `reservedUsdDecimal` (string): `reservedUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `reservedUsd`.
    - `updatedAt` (string (date-time)): Owners and admins only
  - `canManage` (boolean, required): Whether the caller may set the cap (owners and admins)
- `403` A member who is not in the team (`not_in_team`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such team (`unknown_team`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `not_in_team` | 404 `unknown_team`; 403 `not_in_team` for a member who is not in the team |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such team (`unknown_team`) |
| 404 | `unknown_team` | 404 `unknown_team`; 403 `not_in_team` for a member who is not in the team |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/teams/platform/budget" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.teamBudget("platform");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fteams%2F%7Bslug%7D%2Fbudget)

## Set team budget

`PUT /v1/teams/{slug}/budget`

Set a team's cap (owners and admins): an amount in US dollars per day, week or month, counted for the team and every team under it, and a stop mode. `hard_stop` refuses the call; `warn` and `approval` answer 400 `mode_not_available` until they are built. Cutting a cap below what the team used refuses the next call and leaves calls in progress alone. Audited as budget.team_changed, before and after. With `dryRun: true` it checks and answers the same, and changes nothing. The amount is `amountUsd` (a number, deprecated, or a decimal string) or `amountUsdDecimal`, read exactly. 400 `invalid_amount`, `too_many_decimals`, `amount_mismatch`, `invalid_period`, `invalid_mode`; 404 `unknown_team`.

Permission: `budgets.manage` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `slug` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `amountUsd` (number | string): The cap for the period; 0 refuses every call. The cap for the period in US dollars: a JSON number (deprecated) or a decimal string with at most 6 decimals (`"12.245"`), read exactly. Send `amountUsdDecimal` instead to send only a string. [min 0; max 1000000]
- `amountUsdDecimal` (string): The cap for the period as a decimal string in US dollars, at most 6 decimals, never below 0; read exactly into micro-dollars, never through a float. With `amountUsd` too, both must name the same amount (400 `amount_mismatch`). [pattern ^[0-9]+(\.[0-9]{1,6})?$]
- `period` ("day" | "week" | "month", required): UTC calendar day, ISO week (from Monday) or month
- `mode` ("hard_stop" | "warn" | "approval"): Only `hard_stop` is available; the others answer 400 `mode_not_available` [default "hard_stop"]
- `warnAtPercent` (number): For mode `warn`, which is not available yet
- `dryRun` (boolean): Check the cap and answer what would change; change nothing

### Responses

- `200` OK (application/json, TeamBudgetChange)
  - `dryRun` (boolean, required)
  - `team` (object, required)
    - `slug` (string, required)
    - `name` (string, required)
  - `before` (object | null, required)
    - `limitUsd` (number, required): Deprecated: read `limitUsdDecimal`, the exact decimal string (root rule 9).
    - `limitUsdDecimal` (string): `limitUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `limitUsd`.
    - `period` ("day" | "week" | "month", required)
    - `mode` ("hard_stop", required)
  - `after` (object, required)
    - `limitUsd` (number, required): Deprecated: read `limitUsdDecimal`, the exact decimal string (root rule 9).
    - `limitUsdDecimal` (string): `limitUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `limitUsd`.
    - `period` ("day" | "week" | "month", required)
    - `mode` ("hard_stop", required)
- `400` Not a valid cap (`invalid_amount`, `too_many_decimals`, `amount_mismatch`, `invalid_period`, `invalid_mode`, `mode_not_available`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` Only owners and admins set a cap (`role_required`): a member without `budgets.manage` (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such team (`unknown_team`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not a valid cap (`invalid_amount`, `too_many_decimals`, `amount_mismatch`, `invalid_period`, `invalid_mode`, `mode_not_available`) |
| 400 | `mode_not_available` | `hard_stop` refuses the call; `warn` and `approval` answer 400 `mode_not_available` until they are built |
| 400 | `invalid_amount` | 400 `invalid_amount`, `too_many_decimals`, `amount_mismatch`, `invalid_period`, `invalid_mode`; 404 `unknown_team` |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such team (`unknown_team`) |
| 404 | `unknown_team` | 400 `invalid_amount`, `too_many_decimals`, `amount_mismatch`, `invalid_period`, `invalid_mode`; 404 `unknown_team` |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/teams/platform/budget" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#put%3A%2Fv1%2Fteams%2F%7Bslug%7D%2Fbudget)
