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

# Sub-Accounts

> Manage sub-accounts with the PHP SDK

Sub-accounts let you provision isolated messaging environments for your customers with independent API keys and spending controls.

## Create Sub-Account

```php theme={null}
$result = $client->subAccounts->create([
    'name' => 'Client ABC',
    'externalId' => 'client_123',
    'creditLimit' => 100000, // $1,000.00 in cents
    'metadata' => [
        'plan' => 'enterprise',
        'region' => 'us-east',
    ],
]);

// Save this — only shown once
echo $result->subAccount->apiKey . "\n";
echo $result->subAccount->id . "\n";
echo $result->subAccount->status . "\n"; // active
```

<Warning>
  The `apiKey` field is only included in the creation response. Store it securely.
</Warning>

## Get Sub-Account

```php theme={null}
$result = $client->subAccounts->get([
    'id' => 'jx7abc123def456',
]);

echo $result->subAccount->name . "\n";
echo $result->subAccount->status . "\n";
echo $result->subAccount->totalSpent . "\n";
echo $result->subAccount->creditLimit . "\n";
```

## List Sub-Accounts

```php theme={null}
$result = $client->subAccounts->list([
    'limit' => 50,
]);

foreach ($result->items as $sub) {
    echo $sub->name . ": $" . number_format($sub->totalSpent / 100, 2) . " spent\n";
}

// Paginate
$nextPage = $client->subAccounts->list([
    'limit' => 50,
    'cursor' => $result->nextCursor,
]);
```

## Update Sub-Account

```php theme={null}
$result = $client->subAccounts->update([
    'id' => 'jx7abc123def456',
    'creditLimit' => 200000, // Increase to $2,000
    'metadata' => ['plan' => 'enterprise-plus'],
]);

echo $result->subAccount->creditLimit . "\n"; // 200000
```

### Suspend a Sub-Account

```php theme={null}
$client->subAccounts->update([
    'id' => 'jx7abc123def456',
    'status' => 'inactive',
]);

// Re-activate later
$client->subAccounts->update([
    'id' => 'jx7abc123def456',
    'status' => 'active',
]);
```

## Get Sub-Account Balance

```php theme={null}
$balance = $client->subAccounts->getBalance([
    'id' => 'jx7abc123def456',
]);

echo "Team balance: $" . number_format($balance->balance / 100, 2) . "\n";
echo "Sub-account spent: $" . number_format($balance->totalSpent / 100, 2) . "\n";
echo "Credit limit: $" . number_format($balance->creditLimit / 100, 2) . "\n";
echo $balance->isSubAccount . "\n"; // true
```

## Deactivate Sub-Account

```php theme={null}
$result = $client->subAccounts->deactivate([
    'id' => 'jx7abc123def456',
]);

echo "Keys revoked: " . $result->keysRevoked . "\n";
```

## API Keys

### List API Keys

```php theme={null}
$result = $client->subAccounts->apiKeys->list([
    'id' => 'jx7abc123def456',
]);

foreach ($result->items as $key) {
    echo $key->name . " (" . $key->keyPrefix . "...): " . $key->environment . "\n";
}
```

### Create API Key

```php theme={null}
$result = $client->subAccounts->apiKeys->create([
    'id' => 'jx7abc123def456',
    'name' => 'Production Key',
    'environment' => 'live',
]);

// Save this — only shown once
echo "New key: " . $result->apiKey->key . "\n";
```

### Revoke API Key

```php theme={null}
$client->subAccounts->apiKeys->revoke([
    'id' => 'jx7abc123def456',
    'keyId' => 'key_id_here',
]);
```
