# Delete a user

Delete a represented user and their associated data.

`DELETE https://api.smallworld.sh/api/v1/users/:id`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| id | path | string | Yes | Your application's user ID, URL-encoded. At most 512 characters, with no surrounding whitespace or null bytes. Encode the IDs `.` and `..` as `%2E` and `%2E%2E`: curl sends these as written, but JavaScript's `fetch` removes them even when encoded. |

## Request examples

### curl

```curl
curl --fail-with-body -X DELETE 'https://api.smallworld.sh/api/v1/users/customer_123' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY"
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/users/customer_123", {
  method: "DELETE",
  headers: { Authorization: `Bearer ${apiKey}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.delete(
    "https://api.smallworld.sh/api/v1/users/customer_123",
    headers={"Authorization": f"Bearer {api_key}"},
    timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Responses

Returns deleted: true after deletion succeeds.

### 200

Returns deleted: true after deletion succeeds.

```json
{
  "deleted": true
}
```

### 400

invalid_request: A path parameter is invalid; the message names the problem.

#### invalid_request

A path parameter is invalid; the message names the problem.

```json
{
  "statusCode": 400,
  "code": "invalid_request",
  "message": "id must be a non-empty string of at most 512 characters without surrounding whitespace or null bytes"
}
```

### 401

authentication_required: The Authorization header is missing or empty. invalid_api_key: The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

#### authentication_required

The Authorization header is missing or empty.

```json
{
  "statusCode": 401,
  "code": "authentication_required",
  "message": "Authentication is required"
}
```

#### invalid_api_key

The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

```json
{
  "statusCode": 401,
  "code": "invalid_api_key",
  "message": "The API key is invalid or revoked"
}
```

### 403

user_protected: The Playground's test user cannot be deleted. ip_not_allowed: The request came from an address outside the workspace's IP allowlist.

#### user_protected

The Playground's test user cannot be deleted.

```json
{
  "statusCode": 403,
  "code": "user_protected",
  "message": "Playground users cannot be deleted"
}
```

#### ip_not_allowed

The request came from an address outside the workspace's IP allowlist.

```json
{
  "statusCode": 403,
  "code": "ip_not_allowed",
  "message": "The source IP address is not allowed by this account's security settings"
}
```

### 404

user_not_found: The represented user does not exist in your workspace.

#### user_not_found

The represented user does not exist in your workspace.

```json
{
  "statusCode": 404,
  "code": "user_not_found",
  "message": "User not found"
}
```

### 409

user_busy: The user has a running session.

#### user_busy

The user has a running session.

```json
{
  "statusCode": 409,
  "code": "user_busy",
  "message": "User has a running session"
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

```json
{
  "statusCode": 500,
  "code": "internal_error",
  "message": "Internal server error"
}
```

## Notes

- Deletion also removes the user's sessions, files, executions, tool-call history, own connections, connect sessions, user policy overrides, group memberships, and user mounts with their files. Their groups, with the groups' connections and mounts, stay.

- A user with a running session cannot be deleted. The Playground's test user is protected.

- This is permanent. A later execution with the same external ID can create a new user but cannot recover the deleted state.
