# Generate a Key

API keys are generated by making a `POST` request to the API key endpoint. Authentication via a bearer token is required to access this endpoint.

{% hint style="warning" %}
After generation a key cannot be retrieved in full, please ensure you make a copy of the key.
{% endhint %}

## Create a new API Key

<mark style="color:orange;">`POST`</mark> `https://api.olisystems.com/user/api-key`

**Headers**

| Name                                            | Value              |
| ----------------------------------------------- | ------------------ |
| Content-Type                                    | `application/json` |
| Authorization<mark style="color:red;">\*</mark> | `Bearer <token>`   |

**Body (Optional)**

<table><thead><tr><th width="119">Name</th><th width="101" data-type="checkbox">Optional</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>true</td><td>string</td><td>A custom name for the API key (max 50 characters).</td></tr><tr><td><code>expiry</code></td><td>true</td><td>number</td><td>The expiration date of the API key, specified as an epoch timestamp in milliseconds.</td></tr></tbody></table>

**Example Request**

```json
{
  "name": "My API Key",
  "expiry": 1735689600000
}
```

**Example Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "code": 200,
  "data": {
    "apiKey": "gAAAAABnP7fAh9VNmiIkHlpLRMmDNduOCDls4rgdngQpqA0GDNQXipd2ljo4YmNec9K56kvPP5u6zfsEIVrQXD9C_ZInRmH7XZ9BpguHJgd2W2xJVqdZL_Rp6xHR6nb-T",
    "apiKeyId": "d0e13388-c3b8-4bd4-8361-4b699828cde6"
  },
  "message": "User API KEY. PLEASE make a copy. This key can not be retrieved again.",
  "status": "success"
}
```

{% endtab %}

{% tab title="400 - Invalid Date" %}

```json
{
  "status": "ERROR",
  "message": "Invalid expiry date. Expiry date is provided in milliseconds"
}
```

{% endtab %}

{% tab title="400 - Epoch Formatting" %}

```json
{
  "status": "ERROR",
  "message": "Invalid expiry date milliseconds",
}
```

{% endtab %}

{% tab title="400 - Too Many Keys" %}

```json
{
  "status": "ERROR",
  "message": "User api key exceeds allowed limit",
}
```

{% endtab %}
{% endtabs %}

####


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devdocs.olisystems.com/authentication/api-keys/generate-a-key.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
