---
title: "Create an API key"
method: POST
path: "/api_key"
tags: ["API keys"]
---

# Create an API key

`POST /api_key`

Creates a new API key.

## Request body

- ApiKeyNew
  - `name` string, required — A descriptive name for the API key.
  - `grants` union[], required — Defines access grants for an API key. > **Note**: Specify either `role_id` or `role_slug`, but not both. >
    - 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 `201`

The operation was successful.

- ApiKeyPostResponse
  - `id` integer, required — Unique ID for the API key.
  - `name` string, required — The descriptive name given to the API key.
  - `api_key` string, required — Your newly created API key. > > ⚠️ **Save your API key securely.** > >The API key value will be displayed only once. Make sure to store it in a secure location as it cannot be retrieved later.
  - `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, 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)
