# API Keys

## Generate new API Key

<mark style="color:green;">`POST`</mark> `https://api.smtpd.dev/api/v1/account/api_key`

**IMPORTANT**: The generated secret will be visible only once. After the key has been created, you will only be able to see the name of the key.

{% hint style="warning" %}
API Keys are automatically revoked after 90 days of inactivity.
{% endhint %}

#### Path Parameters

| Name                                             | Type   | Description             |
| ------------------------------------------------ | ------ | ----------------------- |
| Authentication<mark style="color:red;">\*</mark> | string | `Bearer {access_token}` |

#### Request Body

| Name                                   | Type   | Description                                                                                                                                                               |
| -------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| role<mark style="color:red;">\*</mark> | string | <p>The permission role for the API key. Supports the following roles;</p><p><code>iac</code>, <code>standard</code>, <code>read\_only</code>, <code>send\_only</code></p> |
| name<mark style="color:red;">\*</mark> | string | Name for API key                                                                                                                                                          |

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

```
{
  "ID": "ad75ae9c-f133-11eb-ab65-0a58a9feaca0",
  "Name": "PROD - Datadog",
  "Key": "ty5davhlalixzn7+2+4l9yemuxdprs8m2ue45vtxsot/zjngii1ptlrzxleceojvxos423om1zsu0apx6wmira==/1w2fsrgv7mayczileqw5svnduj3",
  "Secret": "lloIT4+/3636UvGI2dTm20DH/V9cdFpzHNcET142I32sKVmZV95xnYkVD7CZT7XhoHnQmYS7n/EE7DQmZMv7eoa+k+E/HVXXbjqmB3OFMccSJxboO17wiokvZGgr7Hsdw3LAwrWeYtdAHwzpFB/73JCg7mJ5Ln5ntzfKB1v10dY=/1w2FsQmMFMtP4h1x8lMjhoEwYv8"
}
```

{% endtab %}
{% endtabs %}

## Get all API Keys

<mark style="color:blue;">`GET`</mark> `https://api.smtpd.dev/api/v1/account/api_key`

#### Path Parameters

| Name                                             | Type   | Description             |
| ------------------------------------------------ | ------ | ----------------------- |
| Authentication<mark style="color:red;">\*</mark> | string | `Bearer {access_token}` |

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

```
[
  {
    "id": "055e24ae-f132-11eb-a5ac-0a58a9feac2b",
    "account_id": "35132685-7dcf-4b2a-8c88-88ccf4848925",
    "name": "Staging - AWS",
    "key": "oqzedt51ibrwg5u2tgoanah1eulilowfj3+hcjlydywquze647c8jvyrqvx5ykeivttzo3ulxaa2a3/gecc08w==/1w2eqx3nkawstmkzct7zk7c5uyw",
    "is_active": true,
    "last_accessed_at_utc": 1827618270,
    "created_at_utc": 1627618270,
    "modified_at_utc": 1627618270
  },
  {
    "id": "ad75aea0-f133-11eb-ab65-0a58a9feaca0",
    "account_id": "35132685-7dcf-4b2a-8c88-88ccf4848925",
    "name": "PROD - Datadog",
    "key": "ty5davhlalixzn7+2+4l9yemuxdprs8m2ue45vtxsot/zjngii1ptlrzxleceojvxos423om1zsu0apx6wmira==/1w2fsrgv7mayczileqw5svnduj3",
    "is_active": true,
    "last_accessed_at_utc": 1827618270,
    "created_at_utc": 1627642982,
    "modified_at_utc": 1627642982
  }
]
```

{% endtab %}
{% endtabs %}

## Get an API Key by ID

<mark style="color:blue;">`GET`</mark> `https://api.smtpd.dev/api/v1/account/api_key/:id`

#### Headers

| Name                                             | Type   | Description             |
| ------------------------------------------------ | ------ | ----------------------- |
| Authentication<mark style="color:red;">\*</mark> | String | `Bearer {access_token}` |

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

```javascript
{
    "id": "055e24ae-f132-11eb-a5ac-0a58a9feec2b",
    "account_id": "35132685-7dcf-4b2a-8c88-88ccf4848925",
    "name": "Staging - AWS",
    "key": "oqzedt51ibrwg5u2tgoanah1eulilowfj3+hcjlydywquze647c8jvyrqvx5ykeivttzo3ulxaa2a3/gecc08w==/1w2eqx3nkawstmkzct7zk7c5uyw",
    "is_active": true,
    "last_accessed_at_utc": 1827618270,
    "created_at_utc": 1627618270,
    "modified_at_utc": 1627618270
  }
```

{% endtab %}
{% endtabs %}

## Get API Key sessions by ID

<mark style="color:blue;">`GET`</mark> `https://api.smtpd.dev/api/v1/account/api_key/:id/sessions`

#### Headers

| Name                                             | Type   | Description             |
| ------------------------------------------------ | ------ | ----------------------- |
| Authentication<mark style="color:red;">\*</mark> | String | `Bearer {access_token}` |

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

```javascript
[
	{
		"id": "3430b8f0-b04b-48c9-824e-dae631f3ecd8",
		"account_id": "34132685-7dcf-4b2a-8c88-48ccff847925",
		"ip_address": "22.2.3.28",
		"raw_user_agent": "",
		"user_agent_family": "",
		"user_agent_version": "",
		"user_agent_major_version": "",
		"os_family": "",
		"os_version": "",
		"device_family": "Other",
		"device_brand": "",
		"device_type": "Unknown",
		"country": "United States",
		"country_iso_code": "US",
		"is_active": true,
		"created_at_utc": 1657870731,
		"modified_at_utc": 1657870731
	}
]
```

{% endtab %}
{% endtabs %}

## Revoke an API key

<mark style="color:orange;">`PUT`</mark> `https://api.smtpd.dev/api/v1/account/api_key/:id/revoke`

#### Path Parameters

| Name                                             | Type   | Description             |
| ------------------------------------------------ | ------ | ----------------------- |
| Authentication<mark style="color:red;">\*</mark> | string | `Bearer {access_token}` |
| id<mark style="color:red;">\*</mark>             | string | API Key ID              |

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

```
```

{% 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://docs.smtpd.dev/api/account/api-keys.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.
