# API reference: Keys

> Endpoints of the Keys group of the Sendtide API with parameters, request body, responses and curl examples.

URL: https://sendtide.ch/en/docs/api/keys/

4 endpoints of the Keys group.
## List API keys

GET /v1/keys
Prefix, environment and scope; the key itself is shown once, when it is created.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| limit | query | integer | Page size. The default and the maximum depend on the endpoint (emails 50 up to 500, received mail 50 up to 200, audit up to 200, the others 100 up to 500 or 1000). Default: 100 |
| cursor | query | string | The next_cursor of the previous page. Opaque; pass it unchanged to the same endpoint with the same filters. |
### Example

```
curl "https://api.sendtide.ch/v1/keys" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Keys |
## Create an API key

POST /v1/keys
Needs scope full or admin (or a dashboard role of developer or higher). The new key gets the requested scope at most as high as the caller's own; the admin scope is only created by owners and admins in the dashboard (403 otherwise). Default scope: full. With expires_at (at most a year ahead) the key stops working at that time.
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| name | string | |
| env * | enum: live / test | |
| scope | enum: admin / full / send / read | Default: "full" |
| allowed_ips | array | |
| allowed_domains | array | |
| allowed_streams | array | |
| expires_at | string (date-time) | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/keys" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"name":"Server","env":"live","scope":"send","allowed_ips":["203.0.113.0/24"]}'
```
### Responses
| Status | Description |
| --- | --- |
| 201 | Created; the key is in the answer ApiKey |
| 403 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
## Revoke an API key

DELETE /v1/keys/{id}
Revoking an admin key needs an admin.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Example

```
curl -X DELETE "https://api.sendtide.ch/v1/keys/key_3f9a" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 204 | Revoked |
## Rotate an API key

POST /v1/keys/{id}/rotate
Creates a new key with the name, environment, scope, restrictions and API version of the old one; the new key is in the answer, only this once. The old key keeps working for the chosen time (expires_in, or expires_at at most 90 days ahead) and is refused afterwards; now revokes it at once. Rotating a key that already expires only ever moves its expiry earlier. The same rules as for creating and revoking keys apply: rotating an admin key needs an owner or admin in the dashboard. Owners and admins get a reminder 7 days and 1 day before a key expires.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| expires_in | enum: now / 1h / 24h / 7d / 30d | How long the old key keeps working |
| expires_at | string (date-time) | Instead of expires_in; at most 90 days ahead |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/keys/key_3f9a/rotate" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```
### Responses
| Status | Description |
| --- | --- |
| 201 | Rotated; the new key is in the answer, only this once |
| 403 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
| 404 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
| 422 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
