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

# API Keys API

Create, list, and revoke API keys belonging to service accounts.

Create, list, and revoke API keys belonging to service accounts.

## Authentication

Admin permissions are required for all operations on this page. Set `GC_API_KEY` to an API key with the required permissions and `GC_BACKEND_ID` to the backend ID. Every example sends both headers. For self-hosted deployments, replace `https://api.groundcover.com` with your API URL.

These keys authenticate API requests. For telemetry ingestion credentials, use the separate [Ingestion Keys API](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/list-ingestion-keys.md).

## Create

**POST** `/api/rbac/apikey/create`

| Field              | Required | Description                                                                                                                             |
| ------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `name`             | Yes      | Key name.                                                                                                                               |
| `serviceAccountId` | Yes      | ID from the [Service Accounts API](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/service-accounts-api.md). |
| `description`      | No       | Purpose of the key.                                                                                                                     |
| `expirationDate`   | No       | RFC3339 expiration timestamp; omit or use `null` for no expiration.                                                                     |

```bash
curl --request POST \
  --url "https://api.groundcover.com/api/rbac/apikey/create" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID" \
  --header "Content-Type: application/json" \
  --data '{
  "name": "automation-key",
  "serviceAccountId": "<SERVICE_ACCOUNT_ID>",
  "description": "Read-only automation"
}'
```

HTTP `200` returns `{"apiKey":"<GENERATED_SECRET>","id":"<API_KEY_ID>"}`. Store `apiKey` securely: the list endpoint does not return its secret. The key inherits the service account's policies. An unknown service account returns `400`; a duplicate key name returns `409`.

## List

**GET** `/api/rbac/apikeys/list`

Optional boolean query parameters `withRevoked` and `withExpired` include inactive keys. Both default to `false`.

```bash
curl --request GET \
  --url "https://api.groundcover.com/api/rbac/apikeys/list?withRevoked=true&withExpired=true" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID"
```

HTTP `200` returns an array of key metadata, including `id`, `name`, `serviceAccountId`, `serviceAccountName`, `policies`, `description`, `creationDate`, `createdBy`, `lastActive`, `revokedAt`, and `expiredAt`.

## Revoke

**DELETE** `/api/rbac/apikey/{id}`

Use the resource `id`, not the secret token. Revocation removes the key's ability to authenticate.

```bash
curl --request DELETE \
  --url "https://api.groundcover.com/api/rbac/apikey/<API_KEY_ID>" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID"
```

Success returns HTTP `202` with no response body; an unknown ID returns `404`.


---

# 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.groundcover.com/reference/remote-access-and-apis/api-examples/api-keys-api.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.
