Create an API key
Create an API key and receive its full secret.
The full secret is returned only on creation, in the key field — store it immediately. Subsequent reads return a redacted prefix.
POST /v3/keys
Body parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Required | Human-readable key name (max 255 chars) shown in the Console and audit log. |
scope | string | Optional | full_access, send_only or read_only. Default full_access. See Authentication → Scopes. |
env | string | Optional | live or test. Test keys simulate delivery without sending (see Test keys). Default live. |
verify_before_send | boolean or null | Optional | Per-key verify-before-send override: true/false force it on/off, null (default) inherits the domain/account setting. |
test_outcomes | object | Optional | Test keys only — simulated outcome weights, e.g. { "send": { "delivered": 90, "bounce": 10 } }. Silently ignored for live keys. See Test keys. |
Response (201)
json
{
"id": "key_01j9…",
"name": "Production API Key",
"prefix": "afn_live_pK7d",
"scope": "full_access",
"env": "live",
"key": "afn_live_pK7dXXXXXXXXXXXXXXXX",
"created_at": "2026-08-22T10:00:00Z"
}key is the full secret and appears only in this response. Every later read of the key returns only the display prefix.
Responses
| Status | Description |
|---|---|
201 | Created. The new key — the full secret key is shown only here, this once. |
400 | Validation error. |
401 | Missing or invalid API key. |
403 | Your plan's API-key allowance is used up — upgrade for unlimited keys. |
Code examples
cURL
curl -X POST https://api.wemail.io/v3/keys \
-H "Authorization: Bearer afn_live_…" \
-H "Content-Type: application/json" \
-d '{ "name": "Production API Key", "scope": "full_access", "env": "live" }'Node.js
const res = await fetch("https://api.wemail.io/v3/keys", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WEMAIL_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ "name": "Production API Key", "scope": "full_access", "env": "live" }),
});
const data = await res.json();Python
import os, requests
r = requests.post(
"https://api.wemail.io/v3/keys",
headers={"Authorization": f"Bearer {os.environ['WEMAIL_API_KEY']}"},
json={ "name": "Production API Key", "scope": "full_access", "env": "live" },
)
data = r.json()