# API Keys

Use API keys for CI/CD, CLI tools, Terraform providers, and other software integrations. These endpoints use `https://api.laserdata.cloud`.

Listing keys requires `api_key:read`. Creation, updates, and deletion require `api_key:manage`.

## Create an API Key

### With an Existing Role

`POST /tenants/{tenant_id}/api_keys`

Create a new API key assigned to an existing 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
}'
```

### With Inline Permissions

`POST /tenants/{tenant_id}/api_keys`

Create a new API key with inline permissions (a dedicated role is created automatically).

```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"],
    "environment": ["deployment:read"]
  }
}'
```

| Field | Required | Description |
| --- | --- | --- |
| `name` | Yes | Human-readable name |
| `expiry_at` | Yes | Expiration timestamp (ISO 8601, max 365 days) |
| `role_id` | No\* | Existing role to assign |
| `permissions` | No\* | Inline permissions object (creates a dedicated role) |
| `workspace_id` | No | Scope key to a specific workspace |
| `validate_ip` | No | Enable IP allowlisting (default `false`) |
| `allowed_ips` | No | IP addresses or CIDRs to allowlist (requires `validate_ip: true`) |

\*Supply `role_id` or `permissions`, but not both.

Copy the returned secret immediately. It cannot be retrieved again.

```json
{
  "id": 1,
  "name": "ci-deploy-key",
  "secret": "ld_api_key_abcdef...",
  "role_id": 67890,
  "expiry_at": "2026-06-01T00:00:00Z",
  "created_at": "2025-01-15T10:30:00Z"
}
```

***

## List API Keys

`GET /tenants/{tenant_id}/api_keys`

List all API keys in the tenant. Secrets are never returned in list responses.

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

```json
{
  "items": [
    {
      "id": 1,
      "name": "ci-deploy-key",
      "role_id": 67890,
      "role_name": "deployer",
      "workspace_id": 123,
      "workspace_name": "production",
      "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
}
```

`suspended` is `true` while the member who created the key is deactivated in the organization or the user is locked. A suspended key answers `401` until the member is active again.

***

## Get API Key

`GET /tenants/{tenant_id}/api_keys/{api_key_id}`

Get a single API key with its full role and resolved permission set.

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

```json
{
  "id": 1,
  "workspace_id": null,
  "workspace_name": null,
  "user_id": 608123456789012345,
  "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,
  "permissions": {
    "tenant": ["info:read"],
    "workspace": ["environment:read"],
    "environment": ["deployment:read"],
    "workspaces": {
      "1101": {
        "name": "main",
        "permissions": ["info:read"],
        "environment": [],
        "environments": {
          "1201": {
            "name": "production",
            "permissions": ["deployment:read", "deployment:credentials:read"]
          }
        }
      }
    }
  }
}
```

The response uses the `ApiKeyDetails` structure from [Self-Introspection](#self-introspection) for the selected tenant key. It requires tenant-level `api_key:read`.

***

## Self-Introspection

`GET /tenants/{tenant_id}/api_keys/context`

Return the calling key's role, workspace scope, IP-allowlist state, expiry, and resolved permission set. Requires no specific permission - the key authenticating the request is sufficient.

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

```json
{
  "id": 1,
  "workspace_id": null,
  "workspace_name": null,
  "user_id": 608123456789012345,
  "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,
  "permissions": {
    "tenant": ["info:read"],
    "workspace": ["environment:read"],
    "environment": ["deployment:read"],
    "workspaces": {
      "1101": {
        "name": "main",
        "permissions": ["info:read"],
        "environment": [],
        "environments": {
          "1201": {
            "name": "production",
            "permissions": ["deployment:read", "deployment:credentials:read"]
          }
        }
      }
    }
  }
}
```

`permissions.tenant` lists the organization permissions. `permissions.workspace` and `permissions.environment` list the permissions the role grants in every workspace and in every environment of the organization. `permissions.workspaces` is keyed by workspace ID, and each entry holds the workspace `name`, its own `permissions`, an `environment` list the role grants in every environment of that workspace, and `environments`, keyed by environment ID, with each environment's `name` and `permissions`. IDs are 64-bit integers written as JSON object keys, so they arrive as text.

Use this endpoint to authenticate a key and read its scope. To find the deployments a key can read, [List Organization Deployments](/api/deployments#list-organization-deployments) answers in one call. It accepts API-key sessions only and does not return `403` for permission failures. A `403` from another endpoint cannot distinguish an invalid key from insufficient permission.

***

## Update Security Settings

`PUT /tenants/{tenant_id}/api_keys/{api_key_id}/security`

Update IP allowlist settings on an existing key without recreating it.

```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/24"]
}'
```

***

## Delete an API Key

`DELETE /tenants/{tenant_id}/api_keys/{api_key_id}`

Revoke and delete an API key. Access is blocked immediately, no grace period.

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

- [API Keys Guide](/security/api-keys): Console walkthrough and security model
- [Authentication](/api/authentication): How keys are validated on every request
- [Roles & Permissions](/api/members): Role and permission management

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