---
title: "Generates 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"]
---

# Generates 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'
  - `Expires` string, date-time
  - `Purpose` string
  - `UserId` string, required

## 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
  - `IsLastUsedTimestampKnown` boolean
  - `LastModifiedBy` string
  - `LastModifiedOn` string, date-time
  - `LastUsedTimeStamp` string, date-time
  - `Links` object
  - `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/versions/bc9158facfc7/schema)
