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

# Account management

> Create and revoke API keys and manage credits from code.

Beyond scraping, the client exposes two account namespaces: `client.apiKeys` for
managing your keys and `client.billing` for credits. Both authenticate with the
API key you constructed the client with.

## `client.apiKeys`

Mint, list, and revoke API keys programmatically — handy for provisioning a key
per environment or per customer.

```ts theme={"dark"}
// Create a key — the raw secret is returned exactly once. Store it now.
const created = await client.apiKeys.create({ name: 'production' });
if (created.type === 'success') {
  console.log(created.data.rawKey);
}

// List active keys, newest first.
const keys = await client.apiKeys.list();

// Revoke a key by id.
await client.apiKeys.revoke({ id: 'key_123' });
```

| Method              | Description                                                                        |
| ------------------- | ---------------------------------------------------------------------------------- |
| `create({ name? })` | Mint a new key. Returns the raw secret **once** — it can never be retrieved again. |
| `list()`            | List the account's active keys, newest first.                                      |
| `revoke({ id })`    | Revoke a key by id. Succeeds with no body.                                         |

<Warning>
  `create` returns the key's secret a single time. Store it the moment you
  receive it — Bridgly keeps only a hash and can never show it again.
</Warning>

## `client.billing`

Read your balance and top up credits.

```ts theme={"dark"}
// Current balance and billing settings.
const info = await client.billing.getInfo();
if (info.type === 'success') {
  console.log(info.data.credits);
}

// Start a credit purchase — returns a Stripe Checkout URL to open.
const checkout = await client.billing.buyCredits({ amountUsd: 20 });
if (checkout.type === 'success') {
  console.log(checkout.data); // redirect the browser here
}

// Configure auto top-up.
await client.billing.updateAutoTopUp({
  enabled: true,
  thresholdCredits: 500,
  amountUsd: 20,
});
```

| Method                                                      | Description                                                          |
| ----------------------------------------------------------- | -------------------------------------------------------------------- |
| `getInfo()`                                                 | The account's live credit balance and auto-top-up settings.          |
| `buyCredits({ amountUsd })`                                 | Start a purchase. Returns a Stripe Checkout URL to redirect to.      |
| `updateAutoTopUp({ enabled, thresholdCredits, amountUsd })` | Update auto-top-up settings. Returns the refreshed billing snapshot. |

## Result shape

Account methods return a slightly simpler result than scraping methods — a
`data` payload on success, or a `status` and `message` on error, with no credit
envelope:

```ts theme={"dark"}
type AccountResult<T> =
  | { type: 'success'; data: T }
  | { type: 'error'; status: number; message: string };
```

`revoke` returns a `VoidResult` — success carries no body:

```ts theme={"dark"}
type VoidResult =
  { type: 'success' } | { type: 'error'; status: number; message: string };
```
