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

# Authentication

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

## API Key Authentication

The Cleanview API uses API key authentication. All requests must include a valid API key in the `x-api-key` header.

### API Key Format

API keys follow this format:

```
cv_pub_[32 random characters base64url encoded]
```

**Example:** `cv_pub_KJ3x9mN2pQ8rS7tV5wY6zA1bC4dE0fG2`

### Making Authenticated Requests

Include your API key in the `x-api-key` header:

```bash theme={null}
x-api-key: cv_pub_your_api_key_here
```

## Request Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -H "x-api-key: cv_pub_your_api_key_here" \
    https://api.cleanview.co/api/v1/eia-860m
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.cleanview.co/api/v1/eia-860m', {
    headers: {
      'x-api-key': 'cv_pub_your_api_key_here'
    }
  });

  const data = await response.json();
  ```

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

  headers = {
      'x-api-key': 'cv_pub_your_api_key_here'
  }

  response = requests.get(
      'https://api.cleanview.co/api/v1/eia-860m',
      headers=headers
  )

  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $headers = [
      'x-api-key: cv_pub_your_api_key_here'
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://api.cleanview.co/api/v1/eia-860m');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  curl_close($ch);

  $data = json_decode($response, true);
  ?>
  ```
</CodeGroup>

## Authentication Errors

When authentication fails, the API will return a `401 Unauthorized` status code with an error response:

```json theme={null}
{
  "error": "INVALID_API_KEY",
  "message": "The provided API key is invalid or has been revoked"
}
```

### Common Error Codes

| Error Code        | Description                          |
| ----------------- | ------------------------------------ |
| `MISSING_API_KEY` | No API key provided in the request   |
| `INVALID_API_KEY` | API key doesn't exist or is inactive |

## Security Best Practices

<AccordionGroup>
  <Accordion title="Keep Your API Key Secure" icon="shield-check">
    * Never expose your API key in client-side code or public repositories
    * Store API keys as environment variables
    * Use different API keys for different environments (development, staging, production)
    * Regularly rotate your API keys
  </Accordion>

  <Accordion title="Server-Side Only" icon="server">
    API keys should only be used in server-side applications. Never include them in:

    * Frontend JavaScript code
    * Mobile applications
    * Public GitHub repositories
    * Configuration files committed to version control
  </Accordion>

  <Accordion title="Monitor Usage" icon="eye">
    * Regularly review your API usage patterns
    * Watch for unexpected spikes in requests
    * Contact support if you notice suspicious activity
  </Accordion>
</AccordionGroup>

## Getting Your API Key

<Steps>
  <Step title="Schedule a demo">
    During the beta phase, API keys are manually provisioned. Visit [our demo page](https://cleanview.co/demo) to request access.
  </Step>

  <Step title="Tell us how you plan to use the API">
    Let us know if you plan to use the data for internal business use only or want to integrate it into your product.
  </Step>

  <Step title="Receive your key">
    Our team will review your request and provide you with an API key along with any specific usage guidelines.
  </Step>
</Steps>

<Note>
  **Future Self-Service:** We're working on a self-service API key management portal that will be available in a future version of the API.
</Note>
