> For the complete documentation index, see [llms.txt](https://docs.kiloiot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kiloiot.io/api/authentication-and-api-keys.md).

# Authentication & API Keys

Authenticate Kilo IoT API requests with scoped keys — X-API-Key and X-Organization-Id headers, per-integration keys.

An **API key** is the credential an external integration sends to authenticate its requests to Kilo IoT Server. Its **scopes** are the allowed operations, such as reading devices or writing a supported resource. The key is bound to one organization, the shared workspace whose data the integration uses.

Create a key with the required scopes in [Settings → API Keys](/settings/api-keys.md). For REST or gRPC requests authenticated through the public API gateway, supply both the key and its matching organization identifier. The gateway validates the credential, checks the required scopes, and checks the organization match.

## How requests authenticate

* **`X-API-Key`** — your API key (format `kilo_<key>`). Send it on every request.
* **`X-Organization-Id`** — the organization the request acts in. It must match the organization the key was created in. This header is required by the authentication gateway. If an operation also uses an `organizationId` query parameter, it does not replace the header.

All requests are over TLS.

## Scopes

Keys are scoped. Most areas have separate **Read** and **Write** scopes; some — such as telemetry and subscription data — are read-only. A key grants only what you select when you create it, so grant only the scopes the integration needs. Each endpoint in the [API reference](https://api.kiloiot.io/) lists the scope it requires.

The **Create API Key** dialog asks for a name, an optional expiry date, and the scopes themselves — every scope starts unchecked, so a key grants nothing until you say so.

<figure><img src="https://2057878315-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtNQh1wBSHSaknslMdOXm%2Fuploads%2Fgit-blob-e2e31de97adacb0b0d949199c29378c195801c26%2Fapi-key-create-scopes.jpg?alt=media" alt="The Create API Key dialog with the name and expiry fields above the list of read and write scopes"><figcaption></figcaption></figure>

## Handling keys safely

* The full key value is shown **once** at creation; only a short prefix is visible afterward. Store it immediately in a secrets manager or vault.
* Use a **separate key per integration** so one can be revoked without disrupting the others.
* **Rotate or revoke** a key immediately if it may be exposed; rotation is the only recovery path for a lost key.
* Never embed a key in client-side code or commit it to source control.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kiloiot.io/api/authentication-and-api-keys.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
