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

# TypeScript SDK

<Card title="GitHub">
  [https://github.com/bronlabs/bron-sdk-js](https://github.com/bronlabs/bron-sdk-js)
</Card>

## Install

```bash theme={"system"}
npm install @bronlabs/bron-sdk
```

## Authenticate

<Note>
  Need a JWK keypair? Install the [Bron CLI](/sdk/cli) and run `bron config init --name default --workspace <workspaceId> --key-file ~/.config/bron/keys/me.jwk --generate-key` — it generates the JWK, stores it at `0600`, prints the public half to paste into the Bron UI, and registers the profile. Same key file works directly with the SDK via `BRON_API_KEY_FILE`.
</Note>

```sh theme={"system"}
export BRON_API_KEY='{"kty":"EC","x":"VqW0Rzw4At***ADF2iFCzxc","y":"9AylQ7HHI0vRT0C***PqWuf2yT8","crv":"P-256","d":"DCQ0jrmYw8***9i64igNKuP0","kid":"cmdos3lj50000sayo6pl45zly"}'
export BRON_WORKSPACE_ID='htotobpkg7xqjfxenjid3n1o'
```

The SDK generates an ES256 JWT per request from your private JWK and sends it in `Authorization: ApiKey <jwt>`. No token caching, no revocation flow.

## Quickstart

```typescript theme={"system"}
import BronClient from '@bronlabs/bron-sdk';
import { randomUUID } from 'node:crypto';

const client = new BronClient({
  apiKey: process.env.BRON_API_KEY, // Your private JWK
  workspaceId: process.env.BRON_WORKSPACE_ID
});

// Get workspace
const workspace = await client.workspaces.getWorkspaceById();
console.log('Workspace:', workspace.name);

// Get accounts
const { accounts } = await client.accounts.getAccounts();

// Get balances for first account
if (accounts.length > 0) {
  const account = accounts[0];
  const { balances } = await client.balances.getBalances({
    accountIds: [account.accountId]
  });

  balances.forEach(balance => {
    console.log(`Balance ${balance.assetId} (${balance.symbol}):`, balance.totalBalance)
  });

  // Create a USDC withdrawal on Ethereum to a saved address-book record.
  const tx = await client.transactions.createTransaction({
    accountId: account.accountId,
    externalId: randomUUID(),
    transactionType: 'withdrawal',
    params: {
      amount: '100',
      assetId: '5000',
      networkId: 'ETH',
      toAddressBookRecordId: '<recordId>'
    }
  });

  console.log(`Created transaction '${tx.transactionId}': send ${tx.params.amount}`);
}
```

## Subscriptions (WebSocket)

Live subscriptions are not yet exposed in the TypeScript SDK; they are available today in the [Golang SDK](/sdk/golang#subscriptions-websocket) and will land here in a subsequent release. The wire protocol is identical (a subscription is "GET extended" — same query, server replays the historical match then streams live updates of the same response shape).

## Errors

All API methods return promises. The SDK throws on non-2xx responses with a structured error object that mirrors the API error envelope (`code`, `trace`, `details`):

```typescript theme={"system"}
try {
  const accounts = await client.accounts.getAccounts();
  console.log('Accounts:', accounts);
} catch (error) {
  console.error('API error:', error);
}
```

Branch on `error.code` (stable identifier) — never on the human message. Quote `error.trace` in any user-facing report.

## Configuration

The `BronClient` constructor accepts:

* `apiKey` — private JWK as a JSON string (required).
* `workspaceId` — workspace ID (required).
* `baseUrl` — API base URL (defaults to `https://api.bron.org`).
* `proxy` — `http://[user:pass@]host:port` for outbound requests through a corporate proxy. Standard `HTTPS_PROXY` / `HTTP_PROXY` env vars are honored too.

## Where to next

<CardGroup cols={2}>
  <Card title="API reference" icon="book-open" href="/api-reference/getting-started">
    Endpoints, request/response shapes, OpenAPI spec.
  </Card>

  <Card title="CLI overview" icon="terminal" href="/sdk/cli">
    `bron` binary — same auth, same data path, no client code.
  </Card>

  <Card title="Errors & exit codes" icon="triangle-exclamation" href="/sdk/cli/errors">
    Error envelope shape, stable codes, retry strategy.
  </Card>

  <Card title="Authentication & profiles" icon="key" href="/sdk/cli/auth">
    Keypair lifecycle, env-var overrides, proxy setup, rotation.
  </Card>
</CardGroup>
