> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://docs.agentmail.to/llms.txt. For full content including API reference and SDK examples, see https://docs.agentmail.to/llms-full.txt.

# Create API Key

POST https://api.agentmail.to/v0/inboxes/{inbox_id}/api-keys
Content-Type: application/json

**CLI:**

```bash
agentmail inboxes api-keys create --inbox-id <inbox_id> --name "My Key"
```

Reference: https://docs.agentmail.to/api-reference/inboxes/api-keys/create

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.agentmail.to` (prod, default)
- `https://x402.api.agentmail.to` (prod-x402)
- `https://mpp.api.agentmail.to` (prod-mpp)
- `https://api.agentmail.eu` (eu-prod)

## Request

### Path parameters

- `inbox_id` (string, required) — The ID of the inbox.

### Body (application/json)

This endpoint expects an object or object.

- `object or object`
  - Create Bearer API Key Request
    - `name` (string, optional) — Name of api key.
    - `permissions` (object, optional) — Granular permissions for the API key. When ommitted all permissions are granted. Otherwise, only permissions set to true are granted.
      - `inbox_read` (boolean, optional) — Read inbox details.
      - `inbox_create` (boolean, optional) — Create new inboxes.
      - `inbox_update` (boolean, optional) — Update inbox settings.
      - `inbox_delete` (boolean, optional) — Delete inboxes.
      - `message_read` (boolean, optional) — Read messages. Also required to read threads.
      - `message_send` (boolean, optional) — Send messages.
      - `message_update` (boolean, optional) — Update message labels. Also required to update threads.
      - `message_delete` (boolean, optional) — Delete messages. Also required to delete threads.
      - `label_spam_read` (boolean, optional) — Access messages labeled spam.
      - `label_blocked_read` (boolean, optional) — Access messages labeled blocked.
      - `label_unauthenticated_read` (boolean, optional) — Access messages labeled unauthenticated.
      - `label_trash_read` (boolean, optional) — Access messages labeled trash.
      - `draft_read` (boolean, optional) — Read drafts.
      - `draft_create` (boolean, optional) — Create drafts.
      - `draft_update` (boolean, optional) — Update drafts.
      - `draft_delete` (boolean, optional) — Delete drafts.
      - `draft_send` (boolean, optional) — Send drafts.
      - `webhook_read` (boolean, optional) — Read webhook configurations.
      - `webhook_create` (boolean, optional) — Create webhooks.
      - `webhook_update` (boolean, optional) — Update webhooks.
      - `webhook_delete` (boolean, optional) — Delete webhooks.
      - `domain_read` (boolean, optional) — Read domain details.
      - `domain_create` (boolean, optional) — Create domains.
      - `domain_update` (boolean, optional) — Update domains.
      - `domain_delete` (boolean, optional) — Delete domains.
      - `list_entry_read` (boolean, optional) — Read list entries.
      - `list_entry_create` (boolean, optional) — Create list entries.
      - `list_entry_delete` (boolean, optional) — Delete list entries.
      - `metrics_read` (boolean, optional) — Read metrics.
      - `api_key_read` (boolean, optional) — Read API keys.
      - `api_key_create` (boolean, optional) — Create API keys.
      - `api_key_update` (boolean, optional) — Update API keys.
      - `api_key_delete` (boolean, optional) — Delete API keys.
      - `provider_connect` (boolean, optional) — Sign in to providers as an inbox: connect a provider, authorize an inbox, and mint the sign-in keys. Omitted on a new bearer key means false, whatever else the key holds.
      - `provider_share_owner` (boolean, optional) — Share the organization owner's name and email with providers at sign-in. One permission for both values.
      - `account_update` (boolean, optional) — Update accounts: disable or re-enable an inbox's sign-in at a provider. Reading accounts needs only `inbox_read`.
      - `pod_read` (boolean, optional) — Read pods.
      - `pod_create` (boolean, optional) — Create pods.
      - `pod_delete` (boolean, optional) — Delete pods.
  - Create Public Key Request
    - `public_key` (object, required) — A public P-256 JWK. The object accepts exactly `kty`, `crv`, `x`, and `y`. Private key material such as `d`, embedded key IDs, and all other members are rejected. The server also rejects coordinates that are not a point on P-256.
      - `kty` ("EC", required)
      - `crv` ("P-256", required)
      - `x` (string, required) — A 32-byte P-256 coordinate encoded as unpadded base64url.
      - `y` (string, required) — A 32-byte P-256 coordinate encoded as unpadded base64url.
    - `client_id` (string, optional) — Caller-chosen alias for a public key, unique within the organization and reusable after deletion. Accepted in place of `api_key_id` on get, update, and delete. Registration is idempotent on it: the same alias returns the existing key, a conflicting one returns `409`. URL-safe; no slash or `@`.
    - `name` (string, optional) — Name of api key.
    - `permissions` (object, optional) — Granular permissions for the API key. When ommitted all permissions are granted. Otherwise, only permissions set to true are granted.
      - `inbox_read` (boolean, optional) — Read inbox details.
      - `inbox_create` (boolean, optional) — Create new inboxes.
      - `inbox_update` (boolean, optional) — Update inbox settings.
      - `inbox_delete` (boolean, optional) — Delete inboxes.
      - `message_read` (boolean, optional) — Read messages. Also required to read threads.
      - `message_send` (boolean, optional) — Send messages.
      - `message_update` (boolean, optional) — Update message labels. Also required to update threads.
      - `message_delete` (boolean, optional) — Delete messages. Also required to delete threads.
      - `label_spam_read` (boolean, optional) — Access messages labeled spam.
      - `label_blocked_read` (boolean, optional) — Access messages labeled blocked.
      - `label_unauthenticated_read` (boolean, optional) — Access messages labeled unauthenticated.
      - `label_trash_read` (boolean, optional) — Access messages labeled trash.
      - `draft_read` (boolean, optional) — Read drafts.
      - `draft_create` (boolean, optional) — Create drafts.
      - `draft_update` (boolean, optional) — Update drafts.
      - `draft_delete` (boolean, optional) — Delete drafts.
      - `draft_send` (boolean, optional) — Send drafts.
      - `webhook_read` (boolean, optional) — Read webhook configurations.
      - `webhook_create` (boolean, optional) — Create webhooks.
      - `webhook_update` (boolean, optional) — Update webhooks.
      - `webhook_delete` (boolean, optional) — Delete webhooks.
      - `domain_read` (boolean, optional) — Read domain details.
      - `domain_create` (boolean, optional) — Create domains.
      - `domain_update` (boolean, optional) — Update domains.
      - `domain_delete` (boolean, optional) — Delete domains.
      - `list_entry_read` (boolean, optional) — Read list entries.
      - `list_entry_create` (boolean, optional) — Create list entries.
      - `list_entry_delete` (boolean, optional) — Delete list entries.
      - `metrics_read` (boolean, optional) — Read metrics.
      - `api_key_read` (boolean, optional) — Read API keys.
      - `api_key_create` (boolean, optional) — Create API keys.
      - `api_key_update` (boolean, optional) — Update API keys.
      - `api_key_delete` (boolean, optional) — Delete API keys.
      - `provider_connect` (boolean, optional) — Sign in to providers as an inbox: connect a provider, authorize an inbox, and mint the sign-in keys. Omitted on a new bearer key means false, whatever else the key holds.
      - `provider_share_owner` (boolean, optional) — Share the organization owner's name and email with providers at sign-in. One permission for both values.
      - `account_update` (boolean, optional) — Update accounts: disable or re-enable an inbox's sign-in at a provider. Reading accounts needs only `inbox_read`.
      - `pod_read` (boolean, optional) — Read pods.
      - `pod_create` (boolean, optional) — Create pods.
      - `pod_delete` (boolean, optional) — Delete pods.
    - `expires_at` (datetime, optional) — Time at which api key expires. Omitted when it does not expire.

## Response

### 200

- `object or object`
  - Create API Key Response
    - `api_key_id` (string, required) — ID of api key.
    - `api_key` (string, required) — API key.
    - `prefix` (string, required) — Prefix of api key.
    - `name` (string, required) — Name of api key.
    - `created_at` (datetime, required) — Time at which api key was created.
    - `pod_id` (string, optional) — Pod ID the api key is scoped to. If set, the key can only access resources within this pod.
    - `inbox_id` (string, optional) — Inbox ID the api key is scoped to. If set, the key can only access resources within this inbox.
    - `permissions` (object, optional) — Granular permissions for the API key. When ommitted all permissions are granted. Otherwise, only permissions set to true are granted.
      - `inbox_read` (boolean, optional) — Read inbox details.
      - `inbox_create` (boolean, optional) — Create new inboxes.
      - `inbox_update` (boolean, optional) — Update inbox settings.
      - `inbox_delete` (boolean, optional) — Delete inboxes.
      - `message_read` (boolean, optional) — Read messages. Also required to read threads.
      - `message_send` (boolean, optional) — Send messages.
      - `message_update` (boolean, optional) — Update message labels. Also required to update threads.
      - `message_delete` (boolean, optional) — Delete messages. Also required to delete threads.
      - `label_spam_read` (boolean, optional) — Access messages labeled spam.
      - `label_blocked_read` (boolean, optional) — Access messages labeled blocked.
      - `label_unauthenticated_read` (boolean, optional) — Access messages labeled unauthenticated.
      - `label_trash_read` (boolean, optional) — Access messages labeled trash.
      - `draft_read` (boolean, optional) — Read drafts.
      - `draft_create` (boolean, optional) — Create drafts.
      - `draft_update` (boolean, optional) — Update drafts.
      - `draft_delete` (boolean, optional) — Delete drafts.
      - `draft_send` (boolean, optional) — Send drafts.
      - `webhook_read` (boolean, optional) — Read webhook configurations.
      - `webhook_create` (boolean, optional) — Create webhooks.
      - `webhook_update` (boolean, optional) — Update webhooks.
      - `webhook_delete` (boolean, optional) — Delete webhooks.
      - `domain_read` (boolean, optional) — Read domain details.
      - `domain_create` (boolean, optional) — Create domains.
      - `domain_update` (boolean, optional) — Update domains.
      - `domain_delete` (boolean, optional) — Delete domains.
      - `list_entry_read` (boolean, optional) — Read list entries.
      - `list_entry_create` (boolean, optional) — Create list entries.
      - `list_entry_delete` (boolean, optional) — Delete list entries.
      - `metrics_read` (boolean, optional) — Read metrics.
      - `api_key_read` (boolean, optional) — Read API keys.
      - `api_key_create` (boolean, optional) — Create API keys.
      - `api_key_update` (boolean, optional) — Update API keys.
      - `api_key_delete` (boolean, optional) — Delete API keys.
      - `provider_connect` (boolean, optional) — Sign in to providers as an inbox: connect a provider, authorize an inbox, and mint the sign-in keys. Omitted on a new bearer key means false, whatever else the key holds.
      - `provider_share_owner` (boolean, optional) — Share the organization owner's name and email with providers at sign-in. One permission for both values.
      - `account_update` (boolean, optional) — Update accounts: disable or re-enable an inbox's sign-in at a provider. Reading accounts needs only `inbox_read`.
      - `pod_read` (boolean, optional) — Read pods.
      - `pod_create` (boolean, optional) — Create pods.
      - `pod_delete` (boolean, optional) — Delete pods.
  - Public Key Credential
    - `type` ("public_key", required)
    - `api_key_id` (string, required) — ID of api key.
    - `name` (string, required) — Name of api key.
    - `permissions` (object, required) — Granular permissions for the API key. When ommitted all permissions are granted. Otherwise, only permissions set to true are granted.
      - `inbox_read` (boolean, optional) — Read inbox details.
      - `inbox_create` (boolean, optional) — Create new inboxes.
      - `inbox_update` (boolean, optional) — Update inbox settings.
      - `inbox_delete` (boolean, optional) — Delete inboxes.
      - `message_read` (boolean, optional) — Read messages. Also required to read threads.
      - `message_send` (boolean, optional) — Send messages.
      - `message_update` (boolean, optional) — Update message labels. Also required to update threads.
      - `message_delete` (boolean, optional) — Delete messages. Also required to delete threads.
      - `label_spam_read` (boolean, optional) — Access messages labeled spam.
      - `label_blocked_read` (boolean, optional) — Access messages labeled blocked.
      - `label_unauthenticated_read` (boolean, optional) — Access messages labeled unauthenticated.
      - `label_trash_read` (boolean, optional) — Access messages labeled trash.
      - `draft_read` (boolean, optional) — Read drafts.
      - `draft_create` (boolean, optional) — Create drafts.
      - `draft_update` (boolean, optional) — Update drafts.
      - `draft_delete` (boolean, optional) — Delete drafts.
      - `draft_send` (boolean, optional) — Send drafts.
      - `webhook_read` (boolean, optional) — Read webhook configurations.
      - `webhook_create` (boolean, optional) — Create webhooks.
      - `webhook_update` (boolean, optional) — Update webhooks.
      - `webhook_delete` (boolean, optional) — Delete webhooks.
      - `domain_read` (boolean, optional) — Read domain details.
      - `domain_create` (boolean, optional) — Create domains.
      - `domain_update` (boolean, optional) — Update domains.
      - `domain_delete` (boolean, optional) — Delete domains.
      - `list_entry_read` (boolean, optional) — Read list entries.
      - `list_entry_create` (boolean, optional) — Create list entries.
      - `list_entry_delete` (boolean, optional) — Delete list entries.
      - `metrics_read` (boolean, optional) — Read metrics.
      - `api_key_read` (boolean, optional) — Read API keys.
      - `api_key_create` (boolean, optional) — Create API keys.
      - `api_key_update` (boolean, optional) — Update API keys.
      - `api_key_delete` (boolean, optional) — Delete API keys.
      - `provider_connect` (boolean, optional) — Sign in to providers as an inbox: connect a provider, authorize an inbox, and mint the sign-in keys. Omitted on a new bearer key means false, whatever else the key holds.
      - `provider_share_owner` (boolean, optional) — Share the organization owner's name and email with providers at sign-in. One permission for both values.
      - `account_update` (boolean, optional) — Update accounts: disable or re-enable an inbox's sign-in at a provider. Reading accounts needs only `inbox_read`.
      - `pod_read` (boolean, optional) — Read pods.
      - `pod_create` (boolean, optional) — Create pods.
      - `pod_delete` (boolean, optional) — Delete pods.
    - `created_by` (object, required) — The bearer API key that created the credential. Provenance only; the credential outlives it.
      - `api_key_id` (string, required) — ID of api key.
    - `created_at` (datetime, required) — Time at which api key was created.
    - `updated_at` (datetime, required) — Time at which api key was last updated.
    - `client_id` (string, optional) — Caller-chosen alias for a public key, unique within the organization and reusable after deletion. Accepted in place of `api_key_id` on get, update, and delete. Registration is idempotent on it: the same alias returns the existing key, a conflicting one returns `409`. URL-safe; no slash or `@`.
    - `public_key` (object, optional) — Registered public key material and its server-computed RFC 7638 thumbprint.
      - `jwk` (object, required) — A public P-256 JWK. The object accepts exactly `kty`, `crv`, `x`, and `y`. Private key material such as `d`, embedded key IDs, and all other members are rejected. The server also rejects coordinates that are not a point on P-256.
        - `kty` ("EC", required)
        - `crv` ("P-256", required)
        - `x` (string, required) — A 32-byte P-256 coordinate encoded as unpadded base64url.
        - `y` (string, required) — A 32-byte P-256 coordinate encoded as unpadded base64url.
      - `fingerprint` (string, required) — RFC 7638 SHA-256 JWK thumbprint encoded as unpadded base64url.
    - `pod_id` (string, optional) — Pod ID the api key is scoped to. If set, the key can only access resources within this pod.
    - `inbox_id` (string, optional) — Inbox ID the api key is scoped to. If set, the key can only access resources within this inbox.
    - `status` (enum, optional) — Lifecycle of a sign-in key: `pending` until the client finishes creating it on the AgentID page, `active` once it can sign in as the inbox. Absent on a registered key.
      - Allowed values: `pending`, `active`
    - `used_at` (datetime, optional) — Time at which api key was last used.
    - `expires_at` (datetime, optional) — Time at which api key expires. Omitted when it does not expire.

## Errors

### 404 Not Found Error

- `name` (string, required) — Name of error.
- `message` (string, required) — Error message.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

### 400 Validation Error

- `name` (string, required) — Name of error.
- `errors` (any, required) — Validation errors. Each entry has a path and a message identifying the invalid field.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `message` (string, optional) — Error message.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "api_key_id": "api_key_id",
  "api_key": "api_key",
  "prefix": "prefix",
  "name": "name",
  "pod_id": "pod_id",
  "inbox_id": "inbox_id",
  "permissions": {
    "inbox_read": true,
    "inbox_create": true,
    "inbox_update": true,
    "inbox_delete": true,
    "message_read": true,
    "message_send": true,
    "message_update": true,
    "message_delete": true,
    "label_spam_read": true,
    "label_blocked_read": true,
    "label_unauthenticated_read": true,
    "label_trash_read": true,
    "draft_read": true,
    "draft_create": true,
    "draft_update": true,
    "draft_delete": true,
    "draft_send": true,
    "webhook_read": true,
    "webhook_create": true,
    "webhook_update": true,
    "webhook_delete": true,
    "domain_read": true,
    "domain_create": true,
    "domain_update": true,
    "domain_delete": true,
    "list_entry_read": true,
    "list_entry_create": true,
    "list_entry_delete": true,
    "metrics_read": true,
    "api_key_read": true,
    "api_key_create": true,
    "api_key_update": true,
    "api_key_delete": true,
    "provider_connect": true,
    "provider_share_owner": true,
    "account_update": true,
    "pod_read": true,
    "pod_create": true,
    "pod_delete": true
  },
  "created_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.agentmail.to/v0/inboxes/inbox_id/api-keys"

payload = {}
headers = {
    "Authorization": "Bearer <api_key>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.agentmail.to/v0/inboxes/inbox_id/api-keys';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <api_key>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.agentmail.to/v0/inboxes/inbox_id/api-keys"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <api_key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.agentmail.to/v0/inboxes/inbox_id/api-keys")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <api_key>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.agentmail.to/v0/inboxes/inbox_id/api-keys")
  .header("Authorization", "Bearer <api_key>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.agentmail.to/v0/inboxes/inbox_id/api-keys', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <api_key>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.agentmail.to/v0/inboxes/inbox_id/api-keys");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <api_key>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <api_key>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.agentmail.to/v0/inboxes/inbox_id/api-keys")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```