# API Keys

API keys authenticate software that calls the LaserData Cloud API. Use them for CI/CD, CLI tools, Terraform providers, and other integrations. They follow the same [permission model](/organization/roles-permissions) as interactive sessions.

## How It Works

```mermaid
graph LR
  Client[Client / CI / CLI] -->|ld-api-key header| API[LaserData API]
  API -->|check permissions| Response[Response]
```

A key follows this sequence:

1. You create it with a role and optional IP restrictions.
2. The platform shows its generated secret once.
3. You send the secret in the `ld-api-key` header on each request.
4. The platform evaluates the key, rate limit, IP allowlist, and role permissions.

Save the secret when you create the key. The platform cannot display it again.

A key never carries more authority than its creator. You can create a key only with a role, or inline permissions, that you hold yourself in the same scope: organization, workspace, or environment. Manage includes read. A key that creates keys is bound the same way. Otherwise the request answers `403` with `insufficient_permissions`.

A key belongs to the member who created it. Removing that member from the organization, the member leaving it, or deleting the user deletes the keys they created there. Deactivating the member suspends the keys they created in the organization until the member is active again. Locking the user suspends their keys in every organization until the user is unlocked. A suspended key answers `401`, stays in the key list, and carries `suspended: true` there. A key limited to one workspace is deleted when that workspace is deleted. For automation that must outlive a person, create the key from an account that stays.

## Creating an API Key

### From the Console

1. Open the tenant's API Keys page.
2. Click Create API Key.
3. Enter a key name.
4. Select an existing role, or enter permissions to create a dedicated role for the key.
5. Set an expiration date no more than 365 days away.
6. Click Create.
7. Copy the secret before you leave the page.

### With Inline Permissions

Inline permissions define the tenant, workspace, and environment grants within the request. The platform creates a dedicated role and ties it to the key.

```json
{
  "name": "monitoring-key",
  "expiry_at": "2026-06-01T00:00:00Z",
  "permissions": {
    "tenant": ["info:read", "member:read"],
    "workspace": ["environment:read"],
    "environment": ["deployment:read", "deployment:telemetry:read"]
  }
}
```

`permissions.environment` applies to every environment in every workspace. Use `permissions.workspaces[id].environment` for a workspace's defaults. Use `permissions.workspaces[id].environments[env_id]` for an environment override. [Roles & Permissions](/organization/roles-permissions#how-scoping-works) explains precedence.

## Security

| Property | Description |
| --- | --- |
| High entropy | Long random secret - infeasible to brute-force |
| One-way storage | Only the hash is stored - the secret cannot be recovered |
| Required expiry | Maximum 365 days, enforced at creation |
| Rate limiting | Per-key rate limiter prevents abuse |
| IP allowlisting | Optional - restrict the key to specific IP addresses |
| Instant revocation | Deleting the key blocks access immediately |
| Bound to its creator | Keys are deleted with the member who created them and suspended while that member is deactivated or that user is locked |
| Bound to its workspace | A key limited to one workspace is deleted with that workspace |

## IP Allowlisting

An allowlist restricts a key to selected source IPs. Other addresses receive `403`. You can change an existing key's IP restrictions without recreating it.

The account plan limits allowed IPs per key:

| Plan | Allowed IPs per key |
| --- | --- |
| Standard | 5 |
| Performance | 20 |
| Enterprise | 100 |

## Managing API Keys

Use the API Keys page for these actions:

* Read each key's name, role, expiry, and creation date.
* Change its IP allowlist.
* Delete it to revoke access immediately.

Creation, updates, and deletion require `api_key:manage`. Listing requires `api_key:read`. The [audit log](/observability/audit-compliance) records all API key operations.

## API Reference

### Create an API Key with a Role

```bash
curl -X POST https://api.laserdata.cloud/tenants/{tenant_id}/api_keys \
  -H "ld-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ci-deploy-key",
    "role_id": 67890,
    "workspace_id": 123,
    "expiry_at": "2026-06-01T00:00:00Z",
    "validate_ip": false
  }'
```

Supply `role_id` for an existing role or `permissions` for a dedicated role. Do not supply both. The optional `workspace_id` limits the key to one workspace.

### Create an API Key with Inline Permissions

```bash
curl -X POST https://api.laserdata.cloud/tenants/{tenant_id}/api_keys \
  -H "ld-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "monitoring-key",
    "expiry_at": "2026-06-01T00:00:00Z",
    "validate_ip": true,
    "allowed_ips": ["10.0.0.1"],
    "permissions": {
      "tenant": ["info:read", "member:read"],
      "workspace": ["environment:read"]
    }
  }'
```

### List API Keys

```bash
curl https://api.laserdata.cloud/tenants/{tenant_id}/api_keys \
  -H "ld-api-key: YOUR_API_KEY"
```

```json
{
  "items": [
    {
      "id": 1,
      "workspace_id": 123,
      "workspace_name": "production",
      "user_id": 1,
      "role_id": 67890,
      "role_name": "deployer",
      "name": "ci-deploy-key",
      "validate_ip": false,
      "allowed_ips": [],
      "expiry_at": "2026-06-01T00:00:00Z",
      "created_at": "2025-01-15T10:30:00Z",
      "suspended": false
    }
  ],
  "page": 1,
  "total_results": 1,
  "total_pages": 1
}
```

### Update Security Settings

```bash
curl -X PUT https://api.laserdata.cloud/tenants/{tenant_id}/api_keys/{api_key_id}/security \
  -H "ld-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "validate_ip": true,
    "allowed_ips": ["10.0.0.1", "192.168.1.0"]
  }'
```

### Delete an API Key

```bash
curl -X DELETE https://api.laserdata.cloud/tenants/{tenant_id}/api_keys/{api_key_id} \
  -H "ld-api-key: YOUR_API_KEY"
```

- [Roles & Permissions](/organization/roles-permissions)
- [Authentication](/security/authentication)
- [Organization](/organization)

Source: https://docs.laserdata.com/security/api-keys
