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

# Authentication

> How to authenticate requests to the KeyAPI API.

## API Key

Every request to the KeyAPI API must include your API key. You can find it in your [dashboard](https://keyapi.ai/app/dashboard).

<Warning>Keep your API key secret. Do not expose it in client-side code or public repositories.</Warning>

## Bearer Authentication

KeyAPI uses **Bearer authentication**. Pass your API key in the `Authorization` header.

<CodeGroup>
  ```bash cURL theme={null}
  curl -H "Authorization: Bearer YOUR_API_KEY" \
    "https://api.keyapi.ai/v1/tiktok/influencer/detail?unique_id=karladelatorre97"
  ```

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

  response = requests.get(
      "https://api.keyapi.ai/v1/tiktok/influencer/detail",
      params={"unique_id": "karladelatorre97"},
      headers={"Authorization": "Bearer YOUR_API_KEY"},
  )
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    "https://api.keyapi.ai/v1/tiktok/influencer/detail?unique_id=karladelatorre97",
    {
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
    },
    }
  );
  ```
</CodeGroup>

## Response Envelope

All endpoints return a consistent JSON envelope:

```json theme={null}
{
  "code": 0,
  "message": "success",
  "data": { ... }
}
```

| Field     | Type            | Description                                    |
| --------- | --------------- | ---------------------------------------------- |
| `code`    | integer         | `0` means success; non-zero indicates an error |
| `message` | string          | Human-readable status message                  |
| `data`    | object \| array | The response payload                           |

## Error Responses

| HTTP Status | Meaning                                       |
| ----------- | --------------------------------------------- |
| `400`       | Invalid request parameters                    |
| `401`       | Missing or invalid API key                    |
| `402`       | Insufficient credits or payment required      |
| `403`       | API key does not have access to this endpoint |
| `429`       | Too many requests                             |
| `500`       | Internal server error                         |
