---
title: "Create an API key"
---

> Documentation Index
> Fetch the complete documentation index at: https://simplcron.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an API key

Path: Simplcron API › API keys

`POST /v1/keys`

Create a key fixed to the current project and environment. Store the full API key immediately.

## Authentication

Requires one of the following:

- `browserSession`, apiKey, in cookie
- `localBrowserSession`, apiKey, in cookie

## Header parameters

- `X-Simplcron-Environment` (`createApiKey.header.X-Simplcron-Environment`; string, optional) — Environment for a browser session. Bearer keys always use their fixed environment.
  - one of `"production"`, `"development"` · default: `"production"`

## Request body

_Required._

- `name` (`createApiKey.name`; string, required)
  - maxLength: `80` · minLength: `1`
- `permissions` (`createApiKey.permissions`; array of string, optional)
  - one of `"tasks:read"`, `"tasks:write"`, `"runs:read"`, `"runs:write"`, `"schedules:read"`, `"schedules:write"`, `"webhooks:read"`, `"webhooks:write"`

## Example request

```json
{
  "name": "string",
  "permissions": [
    "tasks:read"
  ]
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url '<base-url>/v1/keys' \
  --header 'Content-Type: application/json' \
  --cookie '__Host-simplcron_session=<__Host-simplcron_session>' \
  --data '
{
  "name": "string",
  "permissions": [
    "tasks:read"
  ]
}
'
```

### TypeScript

```typescript
const url = '<base-url>/v1/keys';
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    cookie: '__Host-simplcron_session=<__Host-simplcron_session>'
  },
  body: JSON.stringify({name: 'string', permissions: ['tasks:read']})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "<base-url>/v1/keys"

payload = {
    "name": "string",
    "permissions": ["tasks:read"]
}
headers = {
    "cookie": "__Host-simplcron_session=<__Host-simplcron_session>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 201

Key created

#### Example

```json
{
  "key": {
    "id": "string",
    "name": "string",
    "prefix": "string",
    "permissions": [
      "tasks:read"
    ],
    "createdAt": "2019-08-24T14:15:22Z",
    "revokedAt": "2019-08-24T14:15:22Z"
  },
  "secret": "string"
}
```

- `key` (`createApiKey.response.201.key`; object, required)
  - `id` (`createApiKey.response.201.key.id`; string, required)
  - `name` (`createApiKey.response.201.key.name`; string, required)
    - maxLength: `80` · minLength: `1`
  - `prefix` (`createApiKey.response.201.key.prefix`; string, required)
  - `createdAt` (`createApiKey.response.201.key.createdAt`; string, required)
    - format: `date-time`
  - `permissions` (`createApiKey.response.201.key.permissions`; array of string, optional)
    - one of `"tasks:read"`, `"tasks:write"`, `"runs:read"`, `"runs:write"`, `"schedules:read"`, `"schedules:write"`, `"webhooks:read"`, `"webhooks:write"`
  - `revokedAt` (`createApiKey.response.201.key.revokedAt`; any of, optional)
    - any of the following: `string`, `null`
- `secret` (`createApiKey.response.201.secret`; string, required) — One-time bearer API key.

### 400

Invalid input

#### Example

```json
{
  "error": "string"
}
```

- `error` (`createApiKey.response.400.error`; string, required)

### 401

Authentication is required

#### Example

```json
{
  "error": "string"
}
```

- `error` (`createApiKey.response.401.error`; string, required)

### 403

The credential lacks permission

#### Example

```json
{
  "error": "string"
}
```

- `error` (`createApiKey.response.403.error`; string, required)


Source: https://simplcron.dev/docs/api/create-api-key/index.md
