---
title: "Create a key; the full key is returned once"
method: POST
path: "/keys"
tags: ["keys"]
---

# Create a key; the full key is returned once

`POST /keys`

## Request

- Base URL: `https://api.tradingpal.io/api/v1`
- URL: `https://api.tradingpal.io/api/v1/keys`
- Auth: API key in cookie `tp_sessionid`

Creates an API key for the signed-in site user and returns it once, in key; only its hash is stored, so it cannot be shown again. name is optional and defaults to "default". Session cookie auth, not an API key.

## Request body

- object: An optional label for the key.
  - `name` string: A label for the key, for example the agent or script that will use it, at most 64 characters. Defaults to "default".

## Response `201`

Created; key holds the full secret

- Key: One API key as the developers page lists it. The full secret appears only in the POST /keys response.
  - `id` integer: Numeric id of the key; the key_id of DELETE /keys/{key_id}.
  - `prefix` string: The first 16 characters of the key (tp_live_ plus eight), enough to tell keys apart. The rest is never shown again.
  - `name` string: The label given at creation (default "default"), at most 64 characters.
  - `created_at` string, date-time: When the key was created, ISO 8601 date-time.
  - `last_used_at` string, date-time, nullable: When the key last authenticated a request, refreshed at most every five minutes. Null until first use.
  - `key` string: The full secret key, present only in the POST /keys response. Store it: only its hash is kept, so it cannot be shown again.

## Other responses

- `403`: not signed in to the site

---

[API](https://skmtc.dev/tradingpal/apis/tradingpal-pattern-api.md) · [All operations](https://skmtc.dev/tradingpal/apis/tradingpal-pattern-api/llms.txt) · [OpenAPI document](https://skmtc.dev/tradingpal/apis/tradingpal-pattern-api/revisions/e96e1f20c1ce?raw)
