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

# Authentication

> Generate your access token and authenticate API requests.

Authentication is a **two-step** process: exchange your account credentials for an **access token (API key)** once, then send that token with every subsequent request.

## Step 1 — Generate your access token

Send a `POST` request to `/api/user` with your account **username and password** encoded as **HTTP Basic Auth** (`base64(username:password)`). See the full endpoint in [Generate Access Token](https://docs.bilalsadasub.com/reference/generate-token.md).

```bash cURL theme={null}
curl -X POST "https://bilalsadasub.com/api/user" \
  -H "Authorization: Basic $(echo -n 'username:password' | base64)" \
  -H "Content-Type: application/json"
```

```js Node.js theme={null}
const res = await fetch("https://bilalsadasub.com/api/user", {
  method: "POST",
  headers: {
    Authorization: "Basic " + Buffer.from("username:password").toString("base64"),
    "Content-Type": "application/json",
  },
});
const { AccessToken } = await res.json();
```

```python Python theme={null}
import base64, requests

cred = base64.b64encode(b"username:password").decode()
res = requests.post(
    "https://bilalsadasub.com/api/user",
    headers={"Authorization": f"Basic {cred}", "Content-Type": "application/json"},
)
access_token = res.json()["AccessToken"]
```

### Response

```json theme={null}
{
  "status": "success",
  "AccessToken": "your_api_key",
  "balance": "110,225.50",
  "username": "johndoe"
}
```

> [!TIP]
>
> Your `AccessToken` is your API key. Store it securely (e.g. an environment variable) and never expose it in client-side code.

## Step 2 — Authenticate your requests

Send your API key in the **`Authorization`** header on every other API call. The `Token` scheme is recommended; `Bearer` and the raw key are also accepted:

```bash theme={null}
-H "Authorization: Token your_api_key"
```

**Authorization** `string` *required*

`Token <your_api_key>` — your API key from Step 1. (`Bearer <your_api_key>` also works.)

> [!WARNING]
>
> Requests without a valid key return **401/403 Unauthorized**. A common mistake is sending the wrong value — make sure it's your **API key**, not your password. Keep the key secret; anyone with it can spend your wallet balance.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.