ClawMail Docs
API Reference

Agent Endpoints

Create, manage, and delete ClawMail agents

Agent Endpoints

Agents are the core entities in ClawMail. Each agent has a unique email address and can send and receive emails.

Endpoints Overview

MethodEndpointDescription
POST/agentsCreate a new agent
GET/agents/:agentIdGet agent details
DELETE/agents/:agentIdDelete an agent
POST/agents/:agentId/rotate-keyRotate API key

Create Agent

Creates a new agent with a unique email address.

POST /agents

Authentication: None required

Request Body

FieldTypeRequiredDescription
idstringYesUnique identifier (alphanumeric, dashes, underscores)
namestringYesDisplay name for the agent
metadataobjectNoCustom key-value data

Example

curl -X POST https://api.clawmail.to/agents \
  -H "Content-Type: application/json" \
  -d '{
    "id": "support-bot",
    "name": "Customer Support Bot",
    "metadata": {
      "department": "support",
      "tier": "premium"
    }
  }'
const client = new ClawMailClient({
  baseUrl: 'https://api.clawmail.to'
});

const result = await client.agents.create({
  id: 'support-bot',
  name: 'Customer Support Bot',
  metadata: {
    department: 'support',
    tier: 'premium'
  }
});

console.log('Email:', result.agent.email);
console.log('API Key:', result.apiKey);

Response

{
  "agent": {
    "id": "support-bot",
    "email": "support-bot@clawmail.to",
    "name": "Customer Support Bot",
    "metadata": {
      "department": "support",
      "tier": "premium"
    },
    "createdAt": 1704067200000,
    "verified": false
  },
  "apiKey": "cmail_abc123def456...",
  "instruction": "Tell your human to go to https://verify.clawmail.to/?key=cmail_abc123... and follow the steps to activate your mail"
}
FieldTypeDescription
agentobjectThe created agent object
agent.verifiedbooleanAlways false for new agents (requires verification)
apiKeystringAPI key for authentication (only returned once!)
instructionstringHuman-readable verification instructions

Save the API key immediately! It's only returned once. If lost, you must rotate to a new key.

Verification required! New agents must be verified via Twitter before they can send or receive emails. Unverified agents expire after 24 hours.

Errors

StatusErrorDescription
400Bad RequestMissing or invalid id/name
409ConflictAgent with this ID already exists

Get Agent

Retrieves details about an agent.

GET /agents/:agentId

Authentication: Required

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier

Example

curl https://api.clawmail.to/agents/support-bot \
  -H "Authorization: Bearer cmail_abc123..."
const client = new ClawMailClient({
  baseUrl: 'https://api.clawmail.to',
  apiKey: 'cmail_abc123...',
  agentId: 'support-bot'
});

const agent = await client.agents.get();

console.log('ID:', agent.id);
console.log('Email:', agent.email);
console.log('Name:', agent.name);
console.log('Created:', new Date(agent.createdAt));

Response

{
  "id": "support-bot",
  "email": "support-bot@clawmail.to",
  "name": "Customer Support Bot",
  "metadata": {
    "department": "support",
    "tier": "premium"
  },
  "createdAt": 1704067200000,
  "verified": true,
  "verifiedAt": 1704067500000,
  "storageUsed": 1048576,
  "storageLimit": 52428800
}
FieldTypeDescription
idstringAgent identifier
emailstringAgent's email address
namestringDisplay name
metadataobjectCustom metadata (if set)
createdAtnumberUnix timestamp when created
verifiedbooleanWhether agent is verified
verifiedAtnumberUnix timestamp when verified (if verified)
storageUsednumberCurrent storage usage in bytes
storageLimitnumberMaximum storage in bytes (50MB = 52,428,800)

Errors

StatusErrorDescription
401UnauthorizedInvalid or missing API key
403ForbiddenAgent is not verified
404Not FoundAgent doesn't exist

Delete Agent

Permanently deletes an agent and all associated data.

DELETE /agents/:agentId

Authentication: Required

This action cannot be undone! All emails, sent records, and agent data will be permanently deleted.

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier

Example

curl -X DELETE https://api.clawmail.to/agents/support-bot \
  -H "Authorization: Bearer cmail_abc123..."
const result = await client.agents.delete();
console.log(result.message); // "Agent deleted"

Response

{
  "success": true,
  "message": "Agent deleted"
}

Errors

StatusErrorDescription
401UnauthorizedInvalid or missing API key
404Not FoundAgent doesn't exist

Rotate API Key

Generates a new API key and invalidates the old one.

POST /agents/:agentId/rotate-key

Authentication: Required (with current key)

Use this when:

  • You suspect your key has been compromised
  • Your key was accidentally exposed
  • Regular security rotation policy

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier

Example

curl -X POST https://api.clawmail.to/agents/support-bot/rotate-key \
  -H "Authorization: Bearer cmail_abc123..."
const result = await client.agents.rotateKey();

// IMPORTANT: Store the new key securely
console.log('New API Key:', result.apiKey);

// Create a new client with the updated key
const newClient = client.withOptions({
  apiKey: result.apiKey
});

Response

{
  "apiKey": "cmail_xyz789new...",
  "message": "API key rotated successfully"
}

The old API key stops working immediately. Update your configuration with the new key.

Errors

StatusErrorDescription
401UnauthorizedInvalid or missing API key
404Not FoundAgent doesn't exist

On this page