---
title: "Leave Team"
method: POST
path: "/teams/{team_id}/leave"
tags: ["teams"]
---

# Leave Team

`POST /teams/{team_id}/leave`

Leave a team voluntarily.

Routes to :func:`sole_member_leave_team_atomic` when the caller is
the only member (no transfer plan required) and to
:func:`leave_team_atomic` otherwise. Owners cannot leave without
transferring ownership first — the lifecycle helper raises 400 in
that case.

Args:
    team_id: Team the caller is leaving.
    body: Optional ``{transfer_plan: {resource_type: {row_id: target|"delete"}}}``.
        Required for multi-member teams when the caller owns rows;
        ignored for sole-member teams.
    auth: Authenticated user context.

Returns:
    :class:`TeamLeaveResponse`. ``new_active_team_id`` is the team
    the caller's active-team snapped to (earliest remaining
    membership) or ``None`` when they have none left.

Raises:
    HTTPException: 400 if the caller is the team owner; 404 if not
        a member; 409 with ``{detail: "owned_resources_unresolved",
        unresolved: {...}}`` when the transfer plan is incomplete;
        409 ``transfer_target_not_member`` when a target is not a
        current member.

## Path parameters

- `team_id` string, required

## Request body

- LeaveTeamRequest — Optional transfer plan accompanying a leave-team request. The plan resolves every row the leaving user owns in the team: transfer to another current member (any role) by user UUID, or ``"delete"`` to remove the row inside the leave transaction. Sole-member leaves omit the plan entirely. Attributes: transfer_plan: ``{resource_type: {row_id: target_user_id|"delete"}}``. Empty/absent when the user owns nothing or is the sole member of the team.
  - `transfer_plan` object

## Response `200`

Successful Response

- TeamLeaveResponse — Response model for leaving a team.
  - `success` boolean, required
  - `message` string, required
  - `team_id` string, required
  - `new_active_team_id` string, nullable

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/pioneer/apis/brain-api.md) · [All operations](https://skmtc.net/pioneer/apis/brain-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/pioneer/brain-api/versions/31dfe831e079/schema)
