> For the complete documentation index, see [llms.txt](https://black-sheep-finance.gitbook.io/black-sheep-finance-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://black-sheep-finance.gitbook.io/black-sheep-finance-docs/sdk/typescript.md).

# TypeScript SDK

`@blacksheep/sdk` — typed REST client. Works in Node 18+, Bun, Deno, Cloudflare Workers, Vercel Edge.

## Construct

```ts
import { BlackSheep } from "@blacksheep/sdk";

const bs = new BlackSheep({
  apiKey: process.env.BS_API_KEY!,
  baseUrl: "https://blacksheepfinance.money", // optional
  fetch: globalThis.fetch,                     // optional override
});
```

## `bs.agents`

```ts
bs.agents.list(): Promise<Agent[]>
bs.agents.create({ label, policy? }): Promise<Agent>
bs.agents.get(id): Promise<Agent>
bs.agents.send(id, { to, amount, memo? }): Promise<SendResult>
```

### Agent

```ts
type Agent = {
  id: string;
  label: string;
  kind: "agent";
  pubkey: string;
  created_at: string;
  policy?: AgentPolicy;
};
```

### SendResult

```ts
type SendResult =
  | { status: "sent"; signature: string }
  | { status: "pending_approval"; approval_id: string };
```

## `bs.transactions`

```ts
bs.transactions.list(): Promise<Transaction[]>
```

## Errors

Every call throws `BlackSheepError` on non-2xx:

```ts
import { BlackSheepError } from "@blacksheep/sdk";

try {
  await bs.agents.send(id, { to, amount: 1000 });
} catch (e) {
  if (e instanceof BlackSheepError) {
    console.error(e.status, e.message); // e.g. 403 "Blocked by policy"
  }
}
```

See [Error handling](/black-sheep-finance-docs/sdk/errors.md) for the full list.

## Runtime notes

* **Edge / Workers** — pass `fetch: globalThis.fetch` if your runtime requires it. No Node built-ins are imported.
* **Bun** — works out of the box.
* **React Native** — works; pass `fetch` explicitly if you patch global fetch.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://black-sheep-finance.gitbook.io/black-sheep-finance-docs/sdk/typescript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
