---
title: "Update an API key"
method: PATCH
path: "/api_key/{id}"
tags: ["API keys"]
---

# Update an API key

`PATCH /api_key/{id}`

Updates an API key by ID.

## Path parameters

- `id` integer, required

## Request body

- ApiKeyWrite
  - `name` string — A descriptive name for the API key.
  - `grants` union[] — Defines access grants for an API key.
    - union
      - object
        - `nrn` string, required — The NRN of the resource where the API key's role is assigned.
        - `role_slug` string, required — The slug of the role assigned to the API key for this NRN. > Note: See [Roles](/docs/authorization/roles) for more info. >
      - object
        - `nrn` string, required — The NRN of the resource where the API key's role is assigned.
        - `role_id` integer, required — The ID of the role assigned to the API key for this NRN. > Note: See [Roles](/docs/authorization/roles) for more info. >
  - `tags` object[] — Tags associated with your API key.
    - `key` string — Tag key associated with your API key.
    - `value` string — Tag value associated with your API key.

## Response `200`

The operation was successful.

- ApiKeyResponse
  - `id` integer, required — Unique ID for the API key.
  - `name` string, required — The descriptive name given to the API key.
  - `masked_api_key` string, nullable — Your masked API key.
  - `tags` object[], required — Array of tags associated with your API key. ℹ️ If no tags are found, we return an empty array.
    - `key` string, required — Tag key associated with your API key.
    - `value` string, required — Tag value associated with your API key.
  - `grants` object[], required — Defines access grants for an API key.
    - `nrn` string, required — The NRN of the resource where the API key's role is assigned.
    - `role_id` integer, required — The ID of the role assigned to the API key for this NRN.
    - `role_slug` string, required — The slug of the role assigned to the API key for this NRN.
  - `owner_id` integer — The unique ID of the user that creates the API key.
  - `last_used_at` string, date-time, nullable — The ISO-8601 UTC timestamp of when the API key was last used.
  - `created_at` string, date-time, required — The ISO-8601 UTC timestamp of when the API key was created.
  - `updated_at` string, date-time, nullable, required — The ISO-8601 UTC timestamp of when the API key was last updated.

## Other responses

- `4XX` — Client error responses due to invalid input or missing parameters.
- `5XX` — Server error responses indicating an issue on the API side.

---

[API](https://skmtc.dev/nullplatform/apis/nullplatform-api.md) · [All operations](https://skmtc.dev/nullplatform/apis/nullplatform-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/nullplatform/nullplatform-api/revisions/1c4ea154b159/schema)
