> 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/rest-api/authentication.md).

# Authentication

Every request to `/api/public/v1/*` requires a bearer token:

```
Authorization: Bearer bs_live_...
```

## Getting a key

**Dashboard → Developers → Create key**. Keys start with `bs_live_` on mainnet and `bs_test_` on devnet accounts. Copy the full string at creation time.

## Header format

```
Authorization: Bearer bs_live_abcd1234...
Content-Type: application/json
```

Missing or invalid keys return:

```http
HTTP/1.1 401 Unauthorized
{ "error": "Unauthorized" }
```

## Scope

A key has access to **every** wallet and transaction in the account that created it. There is no per-wallet scoping today — issue multiple accounts if you need isolation between products.

## Rotation

`POST /v1/keys/:id/rotate` *(or use the dashboard)*. The old key is revoked immediately. Stagger rollouts:

1. Create new key, deploy alongside the old one (two env vars).
2. Switch traffic to the new key.
3. Revoke the old key.

## Never expose in browser code

The bearer key grants full account access. Treat it like a database password:

* ❌ Don't put it in `VITE_*` / `NEXT_PUBLIC_*` / `REACT_APP_*`.
* ❌ Don't ship it to a mobile app.
* ✅ Keep it on your server / serverless function.
* ✅ For browser-initiated spends, build a thin server endpoint that authenticates the user, then calls Black Sheep server-to-server.


---

# 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/rest-api/authentication.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.
