---
title: "Generate a new API key for a User"
method: POST
path: "/users/{userId}/apikeys"
tags: ["ApiKeys"]
---

# Generate a new API key for a User

`POST /users/{userId}/apikeys`

The API Key returned in the result must be saved by the caller, as it cannot be retrieved subsequently from the Octopus server

## Path parameters

- `userId` string, required

## Request body

- CreateUserApiKeyCommand — The API Key returned in the result must be saved by the caller, as it cannot be retrieved subsequently from the Octopus server
  - `ActorType` 'User' | 'AiAgent' — The kind of actor that will hold this API key. Defaults to User when omitted.
  - `Expires` string, date-time — The date after which the API key ceases to be usable. Provide a null value to create an API key with the maximum allowable expiry. If unspecified, will use the system default which is 180 days unless otherwise configured.
  - `Purpose` string — Informational text specifying the intended usage of the api key.
  - `UserId` string, required — ID of the user

## Response `200`

The created API Key, containing the unencrypted value of the key which must be saved by the caller, as it cannot be retrieved subsequently from the Octopus server.

- ApiKeyCreatedResource
  - `ActorType` 'User' | 'AiAgent', required
  - `ApiKey` string, required
  - `Created` string, date-time, required
  - `Expires` string, date-time
  - `Id` string — Gets or sets a unique identifier for this resource.
  - `IsLastUsedTimestampKnown` boolean, required
  - `LastModifiedBy` string — Gets or sets the username of the user who last modified this resource.
  - `LastModifiedOn` string, date-time — Gets or sets the date/time that this resource was last modified.
  - `LastUsedTimeStamp` string, date-time
  - `Links` object — Gets or sets a dictionary of links to other related resources. These links can be used to navigate the resources on the server.
  - `Purpose` string
  - `UserId` string, required

## Other responses

- `400` — Bad request. Either the payload was not structurally valid or business rules did not permit the operation.
- `404` — Not found. One or more of the entities involved in the operation was not found.

---

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