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

# Authentication

> Authenticate with the MathFi.ai API. Obtain a Bearer token, handle 1-hour expiry, and secure your requests.

### Getting your credentials

The credentials for the API are the same as the UI/Dashboard,

1. Fill the form at [Get access](/get-access/)
2. After a few minutes an email will be sent with your credentials: the `email` provided, a `password`, the `url` to access the dashboard and a `baseUrl` for the API

These credentials can be used to log into the Dashboard or the API.

### Using your credentials with the API

The API is authenticated via a `Bearer` token with `1h` expiration. As of this initial release, there's no refresh mechanism so another token must be requested each 1h period to keep requests authenticated.

There are 2 separated API paths:

* The endpoint to login is `https://{baseUrl}/api/login`
* The rest of endpoints, that use the `Bearer` token are of the form `https://{baseUrl}/api/v1/<endpoint>`

To login and obtain the `Bearer` token via API run:

```bash theme={null}
curl -i -XPOST 'https://{baseUrl}/api/login' \
--header 'Content-Type: application/json' \
--data '{ "username": "<email>", "password": "<password>"}'
```

```json theme={null}
{"access_token":"eyJhbGciOiJIUzI1NiJ9.eyJpc3Mi...","token_type":"Bearer","expires_in":3600,"username":"<email>"}
```

Ensure the obtained `Bearer` token in all requests:

```bash theme={null}
curl -X GET https://{baseUrl}/api/v1/datasets \
  -H "Authorization: Bearer $TOKEN"
```
