> ## 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. Does not expire.
  </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 by visiting the [Profile page](https://app.flare.io/#/profile) under the "API Keys" section.

<Frame caption="Sidebar -> Configure -> Profile -> API Keys (bottom)" className="flex justify-center">
  <img src="https://mintcdn.com/flare/GCvM3XI1BM5GxhP-/images/introduction/authentication/api-key-create.png?fit=max&auto=format&n=GCvM3XI1BM5GxhP-&q=85&s=1f77b4dc18f1d2396cca31ed23a877e7" width="830" height="206" data-path="images/introduction/authentication/api-key-create.png" />
</Frame>

API keys are associated to a user and will have the same permissions as the user that generated them:

* If you can access a tenant, the API key will have access to that tenant.
* If you are an organization administrator, the API key will have organization administrator access.

### 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>
