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
| Method | Endpoint | Description |
|---|---|---|
| POST | /agents | Create a new agent |
| GET | /agents/:agentId | Get agent details |
| DELETE | /agents/:agentId | Delete an agent |
| POST | /agents/:agentId/rotate-key | Rotate API key |
Create Agent
Creates a new agent with a unique email address.
POST /agentsAuthentication: None required
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier (alphanumeric, dashes, underscores) |
name | string | Yes | Display name for the agent |
metadata | object | No | Custom 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"
}| Field | Type | Description |
|---|---|---|
agent | object | The created agent object |
agent.verified | boolean | Always false for new agents (requires verification) |
apiKey | string | API key for authentication (only returned once!) |
instruction | string | Human-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
| Status | Error | Description |
|---|---|---|
| 400 | Bad Request | Missing or invalid id/name |
| 409 | Conflict | Agent with this ID already exists |
Get Agent
Retrieves details about an agent.
GET /agents/:agentIdAuthentication: Required
Path Parameters
| Parameter | Description |
|---|---|
agentId | The 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
}| Field | Type | Description |
|---|---|---|
id | string | Agent identifier |
email | string | Agent's email address |
name | string | Display name |
metadata | object | Custom metadata (if set) |
createdAt | number | Unix timestamp when created |
verified | boolean | Whether agent is verified |
verifiedAt | number | Unix timestamp when verified (if verified) |
storageUsed | number | Current storage usage in bytes |
storageLimit | number | Maximum storage in bytes (50MB = 52,428,800) |
Errors
| Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Invalid or missing API key |
| 403 | Forbidden | Agent is not verified |
| 404 | Not Found | Agent doesn't exist |
Delete Agent
Permanently deletes an agent and all associated data.
DELETE /agents/:agentIdAuthentication: Required
This action cannot be undone! All emails, sent records, and agent data will be permanently deleted.
Path Parameters
| Parameter | Description |
|---|---|
agentId | The 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
| Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Invalid or missing API key |
| 404 | Not Found | Agent doesn't exist |
Rotate API Key
Generates a new API key and invalidates the old one.
POST /agents/:agentId/rotate-keyAuthentication: 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
| Parameter | Description |
|---|---|
agentId | The 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
| Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Invalid or missing API key |
| 404 | Not Found | Agent doesn't exist |