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

# Authentication

> Learn how to authenticate your requests to the Cometly API

## Overview

The Cometly API uses API keys to authenticate requests. You can view and manage your API keys in the Cometly Dashboard.

## API Key Authentication

All API requests must include your API key in the request headers. Your API keys carry many privileges, so be sure to keep them secure. Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, etc.

### Authentication Header

Include your API key in the `Authorization` header using the Bearer authentication scheme:

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

### Required Headers

All API requests must include the following headers:

* **Authorization**: Your API key using Bearer authentication scheme
* **Accept**: `application/json` - Indicates that you expect JSON responses
* **Content-Type**: `application/json` - Specifies that you're sending JSON data

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
Accept: application/json
Content-Type: application/json
```

## Example Request

Here's an example of an authenticated request:

<CodeGroup>
  ```bash cURL theme={null}
  curl https://app.cometly.com/public-api/v1/events \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json"
  ```

  ```javascript JavaScript theme={null}
  fetch('https://app.cometly.com/public-api/v1/events', {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    }
  });
  ```

  ```php PHP theme={null}
  <?php
  $url = 'https://app.cometly.com/public-api/v1/events';
  $headers = [
      'Authorization: Bearer YOUR_API_KEY',
      'Accept: application/json',
      'Content-Type: application/json'
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  curl_close($ch);
  ?>
  ```

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

  headers = {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Accept': 'application/json',
      'Content-Type': 'application/json'
  }

  response = requests.get('https://app.cometly.com/public-api/v1/events', headers=headers)
  ```
</CodeGroup>

## Getting Your API Key

<Steps>
  <Step title="Log in to your Cometly account">
    Navigate to [app.cometly.com](https://app.cometly.com) and log in.
  </Step>

  <Step title="Go to Integrations">
    Navigate to the Integrations page at [app.cometly.com/integrations](https://app.cometly.com/integrations).
  </Step>

  <Step title="Search for Cometly API">
    Use the search bar to find "cometly api" and click on the Cometly API integration page.
  </Step>

  <Step title="Generate a new API key">
    Click the button to generate a new API key. Make sure to copy and save it immediately, as you won't be able to view it again.
  </Step>
</Steps>

## Error Responses

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

| Status Code | Error           | Description                                                                                 |
| ----------- | --------------- | ------------------------------------------------------------------------------------------- |
| 401         | Unauthenticated | Missing or invalid API key                                                                  |
| 403         | Forbidden       | API key doesn't have permission for this resource, or your Cometly subscription is inactive |
