> For the complete documentation index, see [llms.txt](https://docs.countercyclical.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.countercyclical.io/developers/authentication.md).

# Authentication

Learn how to authenticate with Countercyclical's API.

## Overview

See also [Endpoints Catalog](https://docs.countercyclical.io/developers/endpoints-catalog) and [OAuth 2.0 Applications](https://docs.countercyclical.io/developers/oauth-2.0-applications).

All calls to the Countercyclical API require authorization, most notably through Bearer Auth or via the `X-API-Key` header.

{% code collapsedlinecount="10" %}

```
https://api.countercyclical.io/v1/investments...
```

{% endcode %}

### Generating an API Key

Users can find their API tokens by going to [Settings › Workspace › Developers › API Keys](https://dashboard.countercyclical.io/settings/workspace/developers/api).

Each key you generate should look something like the following:

{% code collapsedlinecount="10" %}

```
ck_prod_dxjgVIbY...
```

{% endcode %}

{% hint style="warning" %}
**Save Your API Key**

Copy the API key before closing the dialog. The full key is shown once. Store it in your secrets manager so you can retrieve it securely.
{% endhint %}

### Best Practice: Rolling your API Keys

It's a good practice to roll your API keys once in a while for security purposes.

While we do not currently support "rerolling" the same API key, we recommend users generate a new API key with the same permissions they might otherwise have.&#x20;

To make this easier, you can select from the dropdown menu on the right-hand side of any one of your API keys and select the "Roll as New Key" option.

## Example

Here's an example of what a call to get a member's Investments might look like:

{% tabs %}
{% tab title="Express.js (API)" %}
{% code collapsedlinecount="10" %}

```typescript
import axios, { AxiosResponse } from 'axios';
import { NextFunction, Request, Response, Router } from 'express';

const router = Router();

const apiKey: string = process.env.COUNTERCYCLICAL_API_KEY;

const countercyclicalAxiosInstance = axios.create({
    baseURL: 'https://api.countercyclical.io',
    headers: {
        'X-API-Key': apiKey,
    },
});

router.get('/v1/investments', async (req: Request, res: Response, next: NextFunction) => {
    try {
        await countercyclicalAxiosInstance
            .get('/v1/investments', { params: { limit: 6 } })
            .then((apiResponse: AxiosResponse) => {
                if (apiResponse.status === 200) {
                    return res.send(apiResponse.data);
                }
            });
    } catch (error) {
        console.error(error);
    }
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Related Pages

{% content-ref url="/pages/yDU7MBg2twpMc9Bg51Vg" %}
[OAuth 2.0 Applications](https://docs.countercyclical.io/developers/oauth-2.0-applications.md)
{% endcontent-ref %}

{% content-ref url="/pages/REVYMYw7ghhF39hxYNq9" %}
[Endpoints Catalog](https://docs.countercyclical.io/developers/endpoints-catalog.md)
{% endcontent-ref %}

{% content-ref url="/pages/mw3PAMlSCrUy2Rne4WCx" %}
[Rate Limiting](https://docs.countercyclical.io/developers/rate-limiting.md)
{% endcontent-ref %}
