# Authentication & API keys

> Create an API key, send it either of two ways, and understand what it can reach.

Source: https://docs.cleartalk.ai/docs/developers/authentication

Every public API request authenticates with an organization-scoped API key.

<Summary
  items={[
  "Create keys under Integrations → API access; they belong to the organization, not you.",
  "Send as a bearer token, or in an X-API-Key header — either works. Headers only, never in a URL.",
  "A key reaches every endpoint in the API reference, with full access to its own organization's data — and nothing else's.",
  "Rotate by creating the replacement first, then revoking the old one.",
]}
/>

<Key>
  The full key is shown **exactly once**, in the dialog where it's created. Copy it into a password manager or your secret store before closing that dialog — a lost key can't be recovered, only revoked and replaced.
</Key>

## Creating a key

In your dashboard: **Integrations → API access → Generate key**. Name it after the system that will use it (e.g. "HighLevel", "Zapier", "Production").

The full key — it starts with `ct_` — is shown **exactly once**, in the dialog where it's created. Copy it into a password manager or your system's secret store before clicking Done; afterwards the dashboard only ever shows a masked prefix. A lost key can't be recovered — revoke it and generate a new one.

Keys belong to the organization, not the person who created them, so they keep working if that person leaves the team.

## Sending the key

Either header works — same key, pick whichever fits your caller:

```bash
# Standard bearer token:
curl -H "Authorization: Bearer ct_your_key" ...

# Or, if your platform reserves the Authorization header for its own auth:
curl -H "X-API-Key: ct_your_key" ...
```

<Callout type="warn" title="Headers only">
  Never put the key in a URL (`?key=...`) or a request body. URLs end up in server logs, proxy logs, and browser history; headers don't. If a key has ever traveled in a URL, treat it as exposed — rotate it.
</Callout>

## Scope

A key reaches every endpoint in the [API reference](/api-reference) — not just triggering conversations, but contacts, campaigns, results, scheduling, and configuration too — with **full access** to its organization. Treat it like an owner's password: keep it server-side, never in a browser or a mobile app.

The one exception is troubleshooting — the beta diagnostics endpoints that explain a call, step through its Pathway, list what happened to the data sent to your system, and check texting delivery. A key reaches them only if it was created with **Allow troubleshooting** ticked; without it they answer `403`. You see that option if your role includes troubleshooting (owners and admins do), and keys that have it carry a **Troubleshooting** badge in the list. If your organization has HIPAA encryption turned on, a key gets the structure of what happened only — no error text, step names or destination names.

The boundary is the organization. There is no organization ID in any URL — the key *is* the tenant context — and a resource ID from another organization returns the same 404 as one that doesn't exist.

## Agency keys

An agency creates its key in the agency portal under **API access**. That key acts in the agency's own organization by default, and in any customer account the agency manages when the request names it:

```text
X-Organization-Id: org_customer_id
```

The request then behaves exactly as if the customer's own key had sent it — same data, same limits, same owner-level access. Get the ids from [`GET /api/account/customers`](/api-reference). Naming an organization that isn't one of the agency's customers answers `403`, whether or not it exists. The 10,000-requests-a-day limit is per key, so it is shared across every customer the key works in.

## Revoking

**Integrations → API access → Revoke** next to the key. Revocation is immediate: any system using that key loses access on its next request. Rotate keys by generating the replacement first, updating your systems, then revoking the old one.

## Errors

| Status | Meaning                                                                                                                                                                                                       |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401`  | Missing, malformed, or revoked key.                                                                                                                                                                           |
| `403`  | The key lacks a permission the endpoint needs — for troubleshooting, a key created without **Allow troubleshooting** — or `X-Organization-Id` names an organization that isn't one of the agency's customers. |
| `404`  | The resource doesn't exist — or belongs to a different organization.                                                                                                                                          |
