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

# API key

## Available Fields

| Field          |
| -------------- |
| `id`           |
| `created_at`   |
| `is_of__actor` |
| `name`         |
| `description`  |

***

## Examples

### Get all API keys

```bash
GET "https://api.balena-cloud.com/v7/api_key" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Get all API keys of a device by UUID

```bash
GET "https://api.balena-cloud.com/v7/api_key?\$filter=is_of__actor/any(a:a/is_of__device/any(d:d/uuid%20eq%20'<DEVICE_UUID>'))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Get all API keys of an application by slug

```bash
GET "https://api.balena-cloud.com/v7/api_key?\$filter=is_of__actor/any(a:a/is_of__application/any(ioa:ioa/slug%20eq%20'<SLUG>'))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Get all user API keys for the authenticated user

```bash
GET "https://api.balena-cloud.com/v7/api_key?\$filter=is_of__actor/any(a:a/is_of__user%20eq%20<USER_ID>))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" 
```

### Update the expiry date for an API Key

Note: Select a date in the past to expire an API Key immediately.

```bash
PATCH "https://api.balena-cloud.com/v7/api_key(<ID>)" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "expiry_date": "<ISO_8601_DATE_TIME>"
}'
```

### Clear the expiry date of an API Key

```bash
PATCH "https://api.balena-cloud.com/v7/api_key(<ID>)" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "expiry_date": null
}'
```

### Create new API key

```bash
POST "https://api.balena-cloud.com/api-key/user/full" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTH_TOKEN>" \
--data '{
    "name": "<NAME>",
    "description": "<DESCRIPTION>"
}'
```


---

# 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.balena.io/reference/api/resources/api_key.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.
