Account & Org

View as Markdown

Issue API keys, isolate customers into subaccounts, and meter usage per subaccount from a single organization.

The apiKeys, subaccounts, and usage clients are reachable two ways: directly on the client (bctrl.apiKeys) or grouped under bctrl.account.apiKeys. Both point at the same client.

Who am I

Check the actor behind the current API key:

1const me = await bctrl.auth.whoami();

API keys

1const created = await bctrl.apiKeys.create({ name: "ci-key" });
2console.log(created.secret); // shown once - store it now
3console.log(created.data.id);
4
5const { data } = await bctrl.apiKeys.list();
6await bctrl.apiKeys.delete(created.data.id);

The secret is returned only at creation time. Issue a key scoped to a subaccount with subaccountId.

Subaccounts

Each subaccount is an isolated, separately-billed environment for one of your customers, under your organization.

1const sub = await bctrl.subaccounts.create({
2 name: "Acme Corp",
3 externalId: "acme",
4});
5
6const { data } = await bctrl.subaccounts.list();
7const one = await bctrl.subaccounts.get(sub.id);
8
9await bctrl.subaccounts.update(sub.id, { name: "Acme Inc" });
10await bctrl.subaccounts.archive(sub.id);

A parent-org key can act on any subaccount with ?subaccountId=; a subaccount-scoped key is automatically confined to its own subaccount.

Usage

Read organization usage, or per-subaccount usage:

1const org = await bctrl.usage.get();
2const perSub = await bctrl.subaccounts.usage.list();

Next