---
title: "Generate a new API key for the specified user. The API key returned in the result must be saved by the caller, as it cannot be retrieved subsequently from the Octopus server."
method: POST
path: "/users/{userId}/apikeys"
tags: ["ApiKeys"]
---

# Generate a new API key for the specified user. The API key returned in the result must be saved by the caller, as it cannot be retrieved subsequently from the Octopus server.

`POST /users/{userId}/apikeys`

## Path parameters

- `userId` string, required

## Request body

- CreateUserApiKeyCommand
  - `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'
  - `ApiKey` string
  - `Created` string, date-time
  - `Expires` string, date-time
  - `Id` string — Gets or sets a unique identifier for this resource.
  - `IsLastUsedTimestampKnown` boolean
  - `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

## 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.net/octopus/apis/octopus-server-api.md) · [All operations](https://skmtc.net/octopus/apis/octopus-server-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/octopus/octopus-server-api/revisions/b296c3a60aa5/schema)
