Update API key
/v1/api-keys/{id}Changes anything about a key and keeps its secret, so nothing has to be redeployed: name and expiresAt on any key; a workspace key's permissions and sender domains (replace them with domains, or addDomains and removeDomains); a key for addresses or an inbox's access: its addresses (addressIds, addAddressIds, removeAddressIds), its mail (create included), its inbox (inboxId), or access.type to make an inbox key a key for addresses or back. A workspace key stays a workspace key. Takes effect from the next request: requests already waiting lose what was removed, and mail the key queued is sent only within its new access. Each change is recorded with who made it, before and after (lastChange, listApiKeyChanges, Activity). Needs the access createApiKey needs, checked again as the change is written, and no key changes itself. An agent signed in over MCP as a person changes any key that person could change in the dashboard; a key an MCP approval created changes only keys that approval created; temporary agent tokens change none. Revoked keys and keys whose inbox ended can't be changed; an expired key can be given a later expiry.
Needs Configuration: write on the whole workspace. A person needs to be an owner or admin. Not a temporary agent token.
Example
import { createClient } from '@nightmail/sdk/client';
import { updateApiKey } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await updateApiKey({
client,
path: {
"id": "resource_123"
},
body: {},
throwOnError: true,
});
console.log(result.data);curl --request PATCH \
--url 'https://nightmail.dev/v1/api-keys/resource_123' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
--header 'Content-Type: application/json' \
--data '{}'Parameters
idrequiredpath · stringIdempotency-Keyheader · stringOptional. Makes retries safe. Repeating a request with the same key and the same body returns the original result without performing the write again. While the first request with a key is still running, a duplicate returns 409 IDEMPOTENCY_IN_PROGRESS with Retry-After: retry with the same key, never a new one. Reusing a key with a different body returns 409 IDEMPOTENCY_CONFLICT. Keys are scoped to the API key and request path. This route's keys do not expire: a repeat with the same key replays the original result at any later time. Without a key, every request is processed, so a retried send can deliver twice.
Request body
UpdateApiKeynamestringAny text, 1 to 100 characters once trimmed. Need not be unique.
permissionsstring[]Workspace keys: replaces its permissions.
domainsstring[]Workspace keys: replaces the sender domains it is limited to. [] for all domains.
addDomainsstring[]Workspace keys: adds these sender domains and keeps the others. A key for all domains already has them.
removeDomainsstring[]Workspace keys: removes these sender domains. Removing the last one is refused, since [] means all domains: set domains instead.
expiresAtstring or nullAny key: sets when it stops working, or null so it never expires (an inbox key then ends with its inbox). An expired key can be given a later expiry: it works again with the same secret. Over MCP, an agent moves an expiry later only up to its own approval's end, and never removes one; a key an approval created is exempt, as it ends with that approval anyway.
accessobjectA key limited to addresses or an inbox: what it reaches. A workspace key stays a workspace key, and a key for addresses or an inbox stays one of those two.
access.typestringA key for addresses or an inbox: makes it the other one, on the same secret. inbox takes inboxId; addresses keeps the inbox as its address unless addressIds says otherwise.
access.inboxIdstringAn inbox key: the active agent inbox it belongs to now. It ends with that inbox, and its expiry is at most that inbox's end.
access.addressIdsarray or nullA key for addresses: replaces its addresses. null for every address, including ones added later.
access.addAddressIdsstring[]A key for addresses: adds these and keeps the others. An address it already has is left as it is, so a retry changes nothing.
access.removeAddressIdsstring[]A key for addresses: removes these. Requests with the key lose them at once, and replies it queued from them are not sent. An inbox the key created stays reachable while it has create, so removing one is refused (409 CREATED_INBOX_REACHABLE) unless mail drops create too.
access.mailstring[]A key for addresses or an inbox: replaces what it may do with that mail: read, send, modify, and create (agent inboxes, which it then reaches as well).
Responses
200Success
ApiKeyidrequiredstringnamerequiredstringpermissionsrequiredstring[]Workspace permissions. Empty for a key limited to addresses or an inbox: see access.
domainsrequiredstring[]prefixrequiredstringcreatedAtrequiredstringlastUsedAtrequiredstring or nullrevokedAtrequiredstring or nullaccessrequiredobjectaccess.typerequiredstringworkspace: the whole workspace, with permissions and domains. addresses: only mail at receiving addresses. inbox: only one agent inbox; the key stops working when the inbox is deleted.
access.addressIdsrequiredarray or nulladdresses: the receiving addresses it may use, or null for every address including ones added later. inbox: the inbox. Null for workspace keys.
access.inboxIdrequiredstring or nullinbox: the agent inbox the key belongs to.
access.mailrequiredstring[]addresses and inbox: read (mail, events, attachments), send (reply and start conversations from those addresses only), modify (mark read, archive, star, label, delete an inbox), create (create agent inboxes and use the ones it created). Empty for workspace keys.
access.createdInboxIdsrequiredstring[]With create: the live agent inboxes the key created, which it reaches as well as addressIds (up to 1,000, by ID). Empty otherwise.
expiresAtrequiredstring or nullWhen the key stops working: the expiry set on it, or for an inbox key its inbox's end if that is sooner. Null: it never expires. updateApiKey changes it on the same secret.
approvalrequiredobject or nullSet when this is tied to MCP approvals: created, or for a webhook set up or changed, over MCP with a person’s sign-in or with a key that is tied. It works only while every one of them is active. Null: it lasts, not tied to any approval.
approval.activerequiredbooleanEvery approval that owns it is active, so a key is accepted and a webhook is delivered to. False: a key is refused and a webhook is not delivered to until all of them are active again.
approval.endsAtrequiredstringThe earliest end among its owners: when it stops working unless their agents connect again before then.
approval.ownersrequiredobject[]Each approval that owns it, by ID. A key has one; a webhook has one for each approval that set it up or changed it.
lastChangerequiredobject or nullThe newest entry in its history (listApiKeyChanges): when it was created, changed or revoked, and by whom. Null when none is kept (after a year).
lastChange.atrequiredstringWhen it happened (ISO 8601, UTC).
lastChange.actionrequiredstringWhat happened, as <area>.<verb>: api_key.create, member.role_change, domain.delete, support.view.
lastChange.actorrequiredobjectagentrequiredobject or nullA key an agent got through agent setup (exchangeAgentSetupToken or the device flow): the agent it was made for. Null for every other key.
agent.clientrequiredstring or nullWhat the agent said it is (client_name), its claim, never verified. Null when it didn't say.
400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiErrorerrorrequiredobjecterror.coderequiredstringerror.messagerequiredstringerror.requestIdrequiredstringerror.fieldstringerror.retryablerequiredbooleanerror.resetAtstringNext capacity change for a Hosted rolling send limit.
error.detailsobject[]Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).
error.requiredobjectOn a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.