# API Keys

Operations related to API keys (generate and revoke your Enterprise `X-Api-Key`).

## List Enterprise API Keys

`GET /v1/api-keys`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": [],
    "BearerAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key
- BearerAuth: http (bearer)

Responses:

- 200: List of API keys

Content type: application/json

Type: array

Items:
  Reference: [ApiKey](https://api.prompteasy.eu/docs/api/models/apikey/index.md); Type: object

- 403: Forbidden

## Examples

### cURL

```bash
curl -X GET 'https://api.prompteasy.eu/v1/api-keys' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://api.prompteasy.eu/v1/api-keys', {
  method: 'GET',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get(
    'https://api.prompteasy.eu/v1/api-keys',
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Create a new Enterprise API Key

`POST /v1/api-keys`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": [],
    "BearerAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key
- BearerAuth: http (bearer)

Request body: application/json (required)

Type: object

- `service` (required)
  Type: string
  
  Example:
  
  ```json
  "my-production-backend"
  ```

- `urls` (optional)
  Type: string; nullable
  
  Comma-separated list of allowed origin URLs where the API key can be used via browser
  
  Example:
  
  ```json
  "https://tenant.com,https://app.tenant.com"
  ```

Responses:

- 201: API key created successfully

Content type: application/json

Type: object

Schema: [ApiKeyWithToken](https://api.prompteasy.eu/docs/api/models/apikeywithtoken/index.md)

- `id` (optional)
  Type: integer
  
  Example:
  
  ```json
  1
  ```

- `service` (optional)
  Type: string
  
  Example:
  
  ```json
  "my-production-backend"
  ```

- `urls` (optional)
  Type: string; nullable
  
  Example:
  
  ```json
  "https://tenant.com,https://app.tenant.com"
  ```

- `token` (optional)
  Type: string
  
  Example:
  
  ```json
  "pe_abcdef1234567890abcdef1234567890abcdef12"
  ```

- `created_at` (optional)
  Type: string, date-time

- `updated_at` (optional)
  Type: string, date-time

- 403: Forbidden

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/api-keys' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "service": "my-production-backend",
  "urls": "https://tenant.com,https://app.tenant.com"
}'
```

### JavaScript

```javascript
const body = `{
  "service": "my-production-backend",
  "urls": "https://tenant.com,https://app.tenant.com"
}`;

const response = await fetch('https://api.prompteasy.eu/v1/api-keys', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "service": "my-production-backend",
  "urls": "https://tenant.com,https://app.tenant.com"
}'''

response = requests.post(
    'https://api.prompteasy.eu/v1/api-keys',
    data=body.encode('utf-8'),
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Revoke an Enterprise API Key

`DELETE /v1/api-keys/{apiKey}`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": [],
    "BearerAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key
- BearerAuth: http (bearer)

Parameters:

- `apiKey` (path, integer, required)
  Type: integer

Responses:

- 200: API key revoked successfully

Content type: application/json

Type: object

- `message` (optional)
  Type: string
  
  Example:
  
  ```json
  "API key revoked."
  ```

- 403: Forbidden

## Examples

### cURL

```bash
curl -X DELETE 'https://api.prompteasy.eu/v1/api-keys/0' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://api.prompteasy.eu/v1/api-keys/0', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.delete(
    'https://api.prompteasy.eu/v1/api-keys/0',
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
