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

# Authentication

> Learn how to authenticate with the DeepDive API

All API endpoints require authentication using an API key.

## Using Your API Key

Include your API key in the `X-API-Key` header with every request:

```bash theme={null}
curl -X POST "https://data-api.deepdiveplatform.com/api/v1/tiktok/posts" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"username": "charlidamelio", "limit": 10}'
```

## Code Examples

<CodeGroup>
  ```python Python theme={null}
  import requests

  headers = {
      "X-API-Key": "your-api-key",
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://data-api.deepdiveplatform.com/api/v1/tiktok/posts",
      headers=headers,
      json={"username": "charlidamelio", "limit": 10}
  )

  data = response.json()
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://data-api.deepdiveplatform.com/api/v1/tiktok/posts", {
    method: "POST",
    headers: {
      "X-API-Key": "your-api-key",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      username: "charlidamelio",
      limit: 10
    })
  });

  const data = await response.json();
  ```
</CodeGroup>

## Error Responses

### Missing API Key

```json theme={null}
{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "API key is required"
  }
}
```

### Invalid API Key

```json theme={null}
{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Invalid API key"
  }
}
```

### Insufficient Credits

```json theme={null}
{
  "success": false,
  "error": {
    "code": "PAYMENT_REQUIRED",
    "message": "Insufficient credits"
  }
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Never expose your API key">
    Don't include your API key in client-side code or public repositories
  </Accordion>

  <Accordion title="Use environment variables">
    Store your API key in environment variables, not in code
  </Accordion>

  <Accordion title="Rotate keys periodically">
    If you suspect unauthorized access, rotate your keys immediately
  </Accordion>

  <Accordion title="Monitor usage">
    Check your dashboard regularly to detect anomalies
  </Accordion>
</AccordionGroup>
