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

# Authentication

Flare's API is available at `https://api.flare.io`.
Requests are authenticated with **API tokens** which can be obtained using an **API key**.

## Authentication Objects and Purpose

<CardGroup cols={1}>
  <Card title="API Key" icon="key">
    Used to generate API tokens. Can be given an expiration date.
  </Card>

  <Card title="API Token" icon="file-shield">
    Used to access API endpoints. Expires after 1 hour.
  </Card>
</CardGroup>

## Authentication Steps

<CardGroup cols={3}>
  <Card title="Obtain an API Key" icon="square-1" href="#1-obtaining-an-api-key">
    From the profile page.
  </Card>

  <Card title="Generate a temporary API Token" icon="square-2" href="#2-obtaining-an-api-token">
    Using the API key.
  </Card>

  <Card title="Access API endpoints" icon="square-3" href="#3-access-an-api-endpoint">
    Using the API token.
  </Card>
</CardGroup>

### 1 - Obtaining an API key

Users can generate API keys from the [Profile page](https://app.flare.io/#/profile), in the **API keys** section, by clicking **Generate key**.

When creating a key, you choose:

* **Name**: a description that helps you recognize the key.
* **Permissions**:
  * **Default**: the key inherits your current role permissions. If you can access a tenant, the key can access that tenant. If you are an organization administrator, the key has organization administrator access. If your role changes, the key's access changes with it.
  * **Restricted**: the key only has the permissions you select. You can only select permissions that your role allows.
* **Expiration date** (optional): the key stops working at 00:00 (your local time) on that date. Setting an expiration date is recommended. Without one, the key never expires.

Each endpoint in the API reference lists the API key permission it requires.

<Warning>
  The key's secret is only shown once, when the key is created. Save it somewhere secure, such as a password manager or secret store.
</Warning>

### 2 - Obtaining an API Token

API tokens are obtained using Flare API keys. They can be generated using the
[tokens/generate <Icon icon="code" size={16} />](/api-reference/tokens/endpoints/generate)
endpoint.

<CodeGroup>
  ```bash cURL example theme={null}
  curl --request POST \
    --url https://api.flare.io/tokens/generate \
    --header 'Authorization: <api-key>'
  ```
</CodeGroup>

### 3 - Access an API endpoint

API tokens may then be used by specifying the `Authorization: Bearer <api-token>` header.

API tokens can be tested using the
[tokens/test <Icon icon="code" size={16} />](/api-reference/tokens/endpoints/test)
endpoint.

<CodeGroup>
  ```bash cURL example theme={null}
  curl --request GET \
    --url https://api.flare.io/tokens/test \
    --header 'Authorization: Bearer <api-token>'
  ```
</CodeGroup>

## Finding tenant IDs

Users can find the IDs of the tenants they have access to by visiting the
[Profile page](https://app.flare.io/#/profile) under the "Tenants" section.

<Frame caption="Sidebar -> Configure -> Profile -> Tenants" className="flex justify-center">
  <img src="https://mintcdn.com/flare/GCvM3XI1BM5GxhP-/images/introduction/authentication/profile-tenants.png?fit=max&auto=format&n=GCvM3XI1BM5GxhP-&q=85&s=35cc79c038e6ec5672e8942bf2c32708" width="1286" height="198" data-path="images/introduction/authentication/profile-tenants.png" />
</Frame>

## End-to-End Examples

These are end-to-end examples in various programming languages.

<AccordionGroup>
  <Accordion title="Python Example">
    ```python theme={null}
    import os
    import requests


    api_key = os.environ.get("FLARE_API_KEY")
    if not api_key:
        raise Exception("Please provide an API key")

    # Generate the API token.
    token: str = requests.post(
        "https://api.flare.io/tokens/generate",
        headers={
            "Authorization": api_key,
        },
    ).json()["token"]

    # Now we can use our token to access the testing endpoint.
    resp = requests.get(
        "https://api.flare.io/tokens/test",
        headers={
            "Authorization": f"Bearer {token}",
        },
    )
    print(resp.json())
    ```
  </Accordion>

  <Accordion title="Python SDK Example">
    ```python Python SDK theme={null}
    import os

    from flareio import FlareApiClient


    api_key = os.environ.get("FLARE_API_KEY")
    if not api_key:
        raise Exception("Please provide an API key")

    client = FlareApiClient(api_key=api_key)

    # Generate the API token.
    token: str = client.generate_token()

    # Now we can use our token to access the testing endpoint.
    resp = client.get("/tokens/test")
    print(resp.json())
    ```
  </Accordion>
</AccordionGroup>


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