> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Leave Space

> Leave a space

Removes the authenticated user's membership from a space and from its child spaces, and ends their membership of those spaces' chats. A ban in a child space is kept: leaving does not clear it.

## Path Parameters

<ParamField path="spaceId" type="string" required>
  UUID of the space to leave.
</ParamField>

## Response

<ResponseField name="message" type="string">
  Confirmation message.
</ResponseField>

## Errors

<AccordionGroup>
  <Accordion title="No Membership — 404">
    A service key acted for a user who has no membership in the space.

    ```json theme={null}
    { "error": "You are not a member of this space.", "code": "space/not-member" }
    ```
  </Accordion>

  <Accordion title="Not a Member — 403">
    The user is not an active member of the space (for example, banned), including when a service key acts for them.

    ```json theme={null}
    { "error": "Space membership required", "code": "space/membership-required" }
    ```
  </Accordion>

  <Accordion title="Creator Cannot Leave — 400">
    ```json theme={null}
    { "error": "The space creator cannot leave the space. Transfer ownership or delete the space instead.", "code": "space/creator-cannot-leave" }
    ```
  </Accordion>

  <Accordion title="Last Admin — 400">
    The user is the last admin of this space:

    ```json theme={null}
    { "error": "You are the last admin of this space. Promote another member to admin before leaving, or delete the space.", "code": "space/last-admin" }
    ```

    or of one of its child spaces, named by `spaceId`:

    ```json theme={null}
    { "error": "You are the last admin of a child space. Promote another member to admin there before leaving.", "code": "space/last-admin", "spaceId": "…" }
    ```
  </Accordion>
</AccordionGroup>

See also: [useLeaveSpace](/v8/hooks/spaces/use-leave-space)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.