# Tokens

Operations related to user's personal access tokens, and service accounts API tokens. Information about rate limits can be found from [Rate Limits documentation](https://prompteasy.eu/docs/rate-limits).

## Get personal access tokens

`GET /v1/tokens`

Authentication (security requirement alternatives):

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

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

Responses:

- 200: List of tokens

Content type: application/json

Type: array

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

- 403: Forbidden

## Examples

### cURL

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

### JavaScript

```javascript
const response = await fetch('https://api.prompteasy.eu/v1/tokens', {
  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/tokens',
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Issue a access token for a bot user

`POST /v1/tokens/bot/{user}`

Authentication (security requirement alternatives):

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

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

Parameters:

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

Responses:

- 200: Token response

Content type: application/json

Type: object

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

- `token` (optional)
  Type: string
  
  Example:
  
  ```json
  "1|..."
  ```

- 400: Target user is not a bot

- 403: Forbidden

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Issue a personal access token

`POST /v1/tokens/personal`

Authentication (security requirement alternatives):

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

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

Responses:

- 200: Token response

Content type: application/json

Type: object

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

- `token` (optional)
  Type: string
  
  Example:
  
  ```json
  "1|..."
  ```

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Revoke a access token

`DELETE /v1/tokens/{tokenId}`

Authentication (security requirement alternatives):

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

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

Parameters:

- `tokenId` (path, string, required)
  Type: string

Responses:

- 200: Token revoked successfully

Content type: application/json

Type: object

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

- 404: Token not found or unauthorized

## Examples

### cURL

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

### JavaScript

```javascript
const response = await fetch('https://api.prompteasy.eu/v1/tokens/string', {
  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/tokens/string',
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
