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

# Authentication

> Learn how to authenticate your API requests

## Overview

The Drime Cloud API uses **Bearer Token** authentication. Every API request must include your access token in the `Authorization` header.

```bash theme={null}
Authorization: Bearer YOUR_ACCESS_TOKEN
```

## Obtaining an Access Token

### Method 1: Dashboard (Recommended)

The easiest way to get a token is from the Drime Cloud dashboard:

1. Log in to [Drime Cloud](https://app.drime.cloud)
2. Go to [Account Settings → Developers](https://app.drime.cloud/account-settings#developers)
3. Click **Create a token**
4. Name your token and click **Create**
5. Copy your token and store it securely

<Tip>
  Direct link: [https://app.drime.cloud/account-settings#developers](https://app.drime.cloud/account-settings#developers)
</Tip>

<Warning>
  Your API token grants full access to your account. Never share it or commit it to version control.
</Warning>

### Method 2: Login Endpoint

You can also obtain a token programmatically using the login endpoint:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://app.drime.cloud/api/v1/auth/login \
    -H "Content-Type: application/json" \
    -d '{
      "email": "your@email.com",
      "password": "your_password",
      "device_name": "My Application"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://app.drime.cloud/api/v1/auth/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: 'your@email.com',
      password: 'your_password',
      device_name: 'My Application'
    })
  });

  const { user } = await response.json();
  console.log(user.access_token);
  ```

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

  response = requests.post(
      'https://app.drime.cloud/api/v1/auth/login',
      json={
          'email': 'your@email.com',
          'password': 'your_password',
          'device_name': 'My Application'
      }
  )

  data = response.json()
  access_token = data['user']['access_token']
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "status": "success",
  "user": {
    "id": 15843,
    "email": "your@email.com",
    "display_name": "John Doe",
    "first_name": "John",
    "last_name": "Doe",
    "access_token": "123|abcdef1234567890abcdef1234567890",
    "created_at": "2024-01-01T00:00:00.000000Z",
    "updated_at": "2024-01-15T10:30:00.000000Z"
  }
}
```

## Using the Token

Include the token in every API request:

```bash theme={null}
curl https://app.drime.cloud/api/v1/cli/loggedUser \
  -H "Authorization: Bearer 123|abcdef1234567890abcdef1234567890"
```

## Error Responses

### 401 Unauthorized

If the token is missing or invalid:

```json theme={null}
{
  "message": "Unauthenticated."
}
```

### 403 Forbidden

If you don't have permission to access a resource:

```json theme={null}
{
  "message": "This action is unauthorized."
}
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Environment Variables" icon="leaf">
    Store your token in environment variables, not in code
  </Card>

  <Card title="Rotate Tokens" icon="rotate">
    Regularly rotate your API tokens for security
  </Card>

  <Card title="Minimal Scope" icon="shield">
    Use separate tokens for different applications
  </Card>

  <Card title="HTTPS Only" icon="lock">
    Always use HTTPS for API requests
  </Card>
</CardGroup>

## Example: Setting Up Environment Variables

<Tabs>
  <Tab title="Linux/macOS">
    ```bash theme={null}
    export DRIME_API_TOKEN="your_token_here"
    ```
  </Tab>

  <Tab title="Windows (PowerShell)">
    ```powershell theme={null}
    $env:DRIME_API_TOKEN = "your_token_here"
    ```
  </Tab>

  <Tab title=".env File">
    ```
    DRIME_API_TOKEN=your_token_here
    ```
  </Tab>
</Tabs>

Then use it in your code:

```javascript theme={null}
const token = process.env.DRIME_API_TOKEN;

fetch('https://app.drime.cloud/api/v1/cli/loggedUser', {
  headers: {
    'Authorization': `Bearer ${token}`
  }
});
```
