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

# API Keys

Generate and use API keys for programmatic access.

API keys provide machine-to-machine access to the Antidote platform.

Each API key is one base64-encoded string. It contains the OAuth2 client ID and secret. Exchange the key for a short-lived Bearer token, then use the token against the GraphQL API.

### Limits and scope

* Each key is scoped to one organisation.
* Each user can have up to **10 API keys**.
* Keys do not expire unless you set an expiry during creation.
* Organisation admins create, view and revoke keys in the dashboard, and can also rotate them over the API.
* By default a key inherits the roles of the user who created it. Over the API, `generateApiKey(input: { name, roles: ["org-member"], expiresInDays })` creates a key with fewer roles. You can only assign roles you hold.
* Listing, creating, rotating and revoking keys are organisation admin operations. A member cannot see the key list.

### Generate a key

1. Open **Settings → API keys** in the dashboard.
2. Select **+ Generate key**.
3. Enter a name like `GitHub Actions` or `CI Pipeline`.
4. To make the key expire, tick **Set expiration** and enter **Days until expiration**, a whole number from 1 to 3650.
5. Select **Generate key**.
6. Copy the API key, then select **I've saved it**. Select **Show separate client ID and secret** if your tool wants the two values apart.

Over the API, `generateApiKey` returns `clientId` and `clientSecret` as separate fields, plus the `roles` the key carries. The single base64 string shown in the dashboard is `clientId:clientSecret` base64-encoded for convenience. The dashboard also shows the two values under **Show separate client ID and secret**. The secret is returned once and cannot be retrieved again.

{% hint style="warning" %}
The API key is shown once. Store it in your secret manager immediately.
{% endhint %}

### Exchange the key for an access token

Base64-decode the key, then split its value on the first colon.

```bash
DECODED_KEY=$(printf '%s' '<your_api_key>' | base64 --decode)
CLIENT_ID=${DECODED_KEY%%:*}
CLIENT_SECRET=${DECODED_KEY#*:}

curl -X POST https://auth.duku.ai/realms/duku/protocol/openid-connect/token \
  -d "grant_type=client_credentials" \
  -d "client_id=$CLIENT_ID" \
  -d "client_secret=$CLIENT_SECRET"
```

Example response:

```json
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer"
}
```

Access tokens are short-lived, typically about five minutes. Fetch a fresh token rather than caching one for a long-running job.

### Use the access token

```bash
curl -X POST https://platform.duku.ai/graphql \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ subjects { id name } }"}'
```

### Rotate a key

Rotate a key over the API with `rotateApiKey(id: "key_...") { clientId clientSecret }`, using the key's `id` from the `apiKeys` query. The client ID stays the same and the new secret is shown once. Switch your integration to the new secret straight away: the new secret replaces the old one for every new token, and tokens already issued keep working until they expire, about five minutes later. If you use the single API key string, build it again from the client ID and the new secret. An expired key cannot be rotated; generate a new one. In the dashboard, retire a key with **Revoke** and generate a replacement.

### Revoke a key

1. Open **Settings → API keys**.
2. Select **Revoke** on the key.
3. Confirm with **Revoke key**.

The key is deleted permanently and stops issuing tokens. Tokens it already issued keep working until they expire, within about five minutes. An expired key shows **Expired** and cannot issue tokens. **Remove** clears it from the list.

#### Auditing keys

The `apiKeys` query returns each key's `id`, `name`, `clientId`, `createdAt`, `expiresAt` and `lastUsedAt`, so you can find keys that have stopped being used before revoking them.

### See also

Use Triggering explorations from any CI for a complete Platform API walkthrough.
