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

# Authentication

> Learn how to authenticate with the Trakkr API using API keys

The Trakkr API uses API key authentication to secure your requests. All API requests must include your API key in the Authorization header.

## Getting Your API Key

1. Visit [trakkr.ai/api-keys](https://trakkr.ai/api-keys)
2. Sign in to your account
3. Generate a new API key
4. Copy the key and keep it secure

<Warning>
  **Keep your API key secure!** Never share your API key publicly or commit it to version control.
</Warning>

## Using Your API Key

Include your API key in the `Authorization` header of all requests using the Bearer token format:

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

### Example Request

<CodeGroup>
  ```bash theme={null}
  curl -X POST https://api.trakkr.ai/get-scores \
    -H "Authorization: Bearer sk_live_1234567890abcdef" \
    -H "Content-Type: application/json" \
    -d '{
      "brand": "0000000000000x000000000000000000",
      "breakdown": ["model"]
    }'
  ```

  ```javascript theme={null}
  const response = await fetch('https://api.trakkr.ai/get-scores', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk_live_1234567890abcdef',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      brand: '0000000000000x000000000000000000',
      breakdown: ['model']
    })
  });
  ```

  ```python theme={null}
  import requests

  response = requests.post(
      'https://api.trakkr.ai/get-scores',
      headers={
          'Authorization': 'Bearer sk_live_1234567890abcdef',
          'Content-Type': 'application/json'
      },
      json={
          'brand': '0000000000000x000000000000000000',
          'breakdown': ['model']
      }
  )
  ```
</CodeGroup>

## API Key Format

Your API key should be in the following format:

```
sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

## Error Responses

If authentication fails, you'll receive one of these error responses:

### Missing API Key

```json theme={null}
{
  "error": "Missing API key",
  "errors": ["API key must be provided in the Authorization header as 'Bearer <api_key>'"]
}
```

**Status Code:** `401 Unauthorized`

### Invalid API Key

```json theme={null}
{
  "error": "Invalid API key",
  "errors": ["No accounts found for this API key"]
}
```

**Status Code:** `403 Forbidden`

### Authentication Error

```json theme={null}
{
  "error": "Authentication error",
  "errors": ["Could not validate API key against database"]
}
```

**Status Code:** `500 Internal Server Error`

## Security Best Practices

1. **Use HTTPS**: Always make requests over HTTPS
2. **Keep keys secure**: Store API keys in environment variables or secure key management systems

## Environment Variables

Store your API key in environment variables:

```bash theme={null}
# .env file
TRAKKR_API_KEY=sk_live_1234567890abcdef
```

```javascript theme={null}
// JavaScript
const apiKey = process.env.TRAKKR_API_KEY;
```

```python theme={null}
# Python
import os
api_key = os.environ.get('TRAKKR_API_KEY')
```

<Note>
  **Need to regenerate your key?** Visit your [API settings](https://trakkr.ai/api) to create a new key and invalidate the old one.
</Note>
