# Update sub-account

> Update sub-account. Requires a parent project API key; sub-account API keys receive HTTP 403.

`PATCH https://api.zavu.dev/v1/sub-accounts/{id}`

Update sub-account. Requires a parent project API key; sub-account API keys receive HTTP 403.

## Parameters

- `id` (path, string, required): Sub-account ID.

## Body

- `name` (string)
- `externalId` (string)
- `creditLimit` (integer, nullable)
- `metadata` (object)
- `status` (string): `active` and `inactive` are set with PATCH. `pending_deletion` is read-only: the sub-account was deactivated with DELETE, its API keys are revoked, and it is removed after 14 days. One of: `active`, `inactive`, `pending_deletion`.

## Responses

### 200

Sub-account updated.

- `subAccount` (object, required)
  - `id` (string, required)
  - `name` (string, required)
  - `externalId` (string, nullable): External reference ID set by the parent account.
  - `status` (string, required): `active` and `inactive` are set with PATCH. `pending_deletion` is read-only: the sub-account was deactivated with DELETE, its API keys are revoked, and it is removed after 14 days. One of: `active`, `inactive`, `pending_deletion`.
  - `totalSpent` (integer, required): Total amount spent by this sub-account in cents.
  - `creditLimit` (integer, nullable): Spending cap in cents. When reached, messages from this sub-account will be blocked.
  - `metadata` (object, nullable)
  - `apiKey` (string): API key for the sub-account. Only returned on creation.
  - `createdAt` (string<date-time>, required)

### 400

Invalid request.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 403

Forbidden. Sub-account API keys cannot manage sub-accounts.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Sub-account not found.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 409

Another sub-account in the team already has this `externalId`.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X PATCH "https://api.zavu.dev/v1/sub-accounts/id_abc123" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "string"
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.subAccounts.update("id_abc123", {
  name: "string",
});

console.log(result);
```
