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

# Authenticate with the Alphacast API

> Send your API key with HTTP Basic Auth, and keep it safe.

Authenticate your requests with your Alphacast API key.

## Get your API key

Open [your settings](https://www.alphacast.io/settings). Next to **API Key**, click **Show Key**.

> [!WARNING]
>
> Treat your API key like a password. Do not share it, commit it to version control, or put it in client-side code.

## Use HTTP Basic Auth

Send the key as the **username** and leave the **password** empty.

```bash curl theme={null}
curl https://api.alphacast.io/datasets \
  -u YOUR_API_KEY:
```

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

response = requests.get(
    "https://api.alphacast.io/datasets",
    auth=("YOUR_API_KEY", ""),
)
response.raise_for_status()
print(response.json())
```

```javascript Node.js theme={null}
const response = await fetch("https://api.alphacast.io/datasets", {
  headers: { Authorization: "Basic " + btoa("YOUR_API_KEY:") },
});
const datasets = await response.json();
```

## The apiKey query parameter

Most endpoints require Basic Auth. A few endpoints also accept `?apiKey=YOUR_API_KEY`, for tools that cannot send headers. The main one is [Download data](https://learn.alphacast.io/api/datasets/data.md):

```bash theme={null}
curl -L "https://api.alphacast.io/datasets/123/data?apiKey=YOUR_API_KEY"
```

Do not expect this parameter to work on other endpoints, such as listing or creating repositories and datasets. A URL that contains your key can end up in logs, history, and shared files. Use Basic Auth whenever you can.

## Authentication errors

A missing or invalid key returns `401`. The body is not always JSON, so check the status code before you parse the response.

Check that:

* The request includes the key.
* The key is the username, not the password.
* You are using your current key. In settings, **Reset** creates a new key. Scripts and Excel integrations that use the old key can stop working.

## Keep your key in an environment variable

```python theme={null}
import os
import requests

api_key = os.environ["ALPHACAST_API_KEY"]

response = requests.get(
    "https://api.alphacast.io/datasets",
    auth=(api_key, ""),
)
```

If your key is exposed, reset it in [your settings](https://www.alphacast.io/settings).


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