This is a destructive operation that cannot be undone. Deleting an agent permanently removes all associated data including usage statistics, configuration, and history.
Overview
Permanently delete an agent and all its associated data. Kakiyo-managed agents must have status ended; externally provisioned profiles can be removed when their source lifecycle requires cleanup. The operation removes the agent, its campaigns, and its usage statistics from your account. Kakiyo-managed agents also have their provider resources cleaned up, while externally provisioned profiles keep their externally owned provider resources untouched.
Prerequisites
You must have access to the agent (same team)
Agent must exist in your account
Kakiyo-managed agents must have status ended
No campaign import can be active for the agent
Use Cases
Account Cleanup: Remove agents that are no longer needed
Data Management: Clean up ended agents to reduce clutter
Resource Management: Free up agent slots in your account
Compliance: Permanently remove agent data for privacy requirements
Path Parameters
string
required
The unique identifier of the agent to delete
Response Examples
Success Response
{ "message": "Agent deleted successfully"}
Error Responses
// Agent not found{ "error": "not_found", "message": "Agent not found"}// No access to agent{ "error": "forbidden", "message": "You do not have access to this agent"}// Campaign import in progress{ "error": "campaign_busy", "message": "Wait for active prospect imports to finish before deleting this profile"}// Kakiyo-managed agent is not ended{ "error": "invalid_status", "message": "Agent can only be deleted when status is ended", "currentStatus": "running"}// Internal server error{ "error": "internal_error", "message": "An internal error occurred"}
# Pythonimport requestsdef delete_agent(agent_id): """Permanently delete an agent""" response = requests.delete( f'https://api.kakiyo.com/v1/agents/{agent_id}', headers={ 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' } ) if response.status_code == 200: return response.json() else: error_data = response.json() raise Exception(f"Failed to delete agent: {error_data['message']}")# Usage with error handlingtry: result = delete_agent('agent_123') print(f"Agent deleted: {result['message']}")except Exception as e: print(f"Delete failed: {e}")
Error Handling
Status Code Reference
Status Code
Error Code
Description
Action
200
-
Success
Agent deleted successfully
400
invalid_status
Kakiyo-managed agent is not ended
End the agent, then retry
403
forbidden
No access to agent
Verify agent belongs to your team
404
not_found
Agent doesn’t exist
Check agent ID is correct
409
campaign_busy
A campaign import is active
Wait for the import to finish, then retry
429
rate_limit_exceeded
Too many requests
Retry after the indicated delay
500
internal_error
Server error
Retry request or contact support
Comprehensive Error Handling
const safeDeleteAgent = async (agentId) => { try { const response = await fetch(`https://api.kakiyo.com/v1/agents/${agentId}`, { method: 'DELETE', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' } }); const data = await response.json(); if (!response.ok) { switch (data.error) { case 'not_found': throw new Error('Agent not found. Please check the agent ID.'); case 'forbidden': throw new Error('You do not have permission to delete this agent.'); case 'campaign_busy': throw new Error('Agent cannot be deleted while a campaign import is active. Retry shortly.'); case 'invalid_status': throw new Error(`Agent cannot be deleted. Current status: ${data.currentStatus}.`); case 'internal_error': throw new Error('Server error occurred. Please try again later.'); default: throw new Error(`Unexpected error: ${data.message}`); } } return data; } catch (error) { console.error('Delete agent error:', error.message); throw error; }};
Integration Examples
Safe Deletion Workflow
const safeAgentDeletion = async (agentId) => { try { // Confirm deletion (in a real app, this would be user confirmation) const confirmed = true; // Replace with actual confirmation logic if (!confirmed) { return { success: false, reason: 'User cancelled' }; } // Proceed with deletion const result = await deleteAgent(agentId); return { success: true, message: result.message }; } catch (error) { return { success: false, error: error.message }; }};