Skip to main content

Delete Agent

Deletes an agent from Ultravox and removes the corresponding local agent_mappings record. Before deletion, it unassigns any phone numbers linked to the agent and checks for active call batches. Supports a keep_ultravox option to remove only the local mapping while preserving the agent in Ultravox.

Endpoint

PropertyValue
Function Nameagents-delete
HTTP MethodDELETE
AuthenticationSupabase JWT (Bearer token)
Required Roleagency_owner

Request

Headers

Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json

Query Parameters

FieldTypeRequiredDescription
agent_idstringYesThe Ultravox agent ID to delete.
keep_ultravoxstringNoSet to "true" to only delete the local mapping and keep the agent in Ultravox. Defaults to false.

Response

Success (200)

{
"success": true,
"agent_id": "uv-agent-abc123",
"agent_name": "My_Agent",
"ultravox_deleted": true,
"local_mapping_deleted": true,
"was_managed_by_virsyn": true
}
FieldDescription
agent_idThe Ultravox agent ID that was deleted.
agent_nameThe agent's name from the local mapping, or null if no mapping existed.
ultravox_deletedWhether the agent was deleted from Ultravox. false if keep_ultravox=true was set.
local_mapping_deletedWhether the local mapping was deleted. false if no mapping existed or deletion failed.
was_managed_by_virsynWhether this agent was originally created through Virsyn.

Error Responses

StatusCondition
400agent_id query parameter is missing
400Agent has active call batches (status: pending, scheduled, or processing)
400Ultravox API key is not configured for the agency
401Missing or invalid authorization header
403User is not associated with an agency
403User role is not agency_owner
405HTTP method is not DELETE
500Failed to retrieve API credentials
500Unexpected server error
502Ultravox API returned an error during deletion (non-404)

Behavior

  • Authenticates the user via Supabase JWT and verifies they belong to an agency with the agency_owner role. Unlike other agent management functions, only agency owners can delete agents.
  • Validates the required agent_id query parameter and parses the optional keep_ultravox flag.
  • Looks up the local agent_mappings record for the agent (scoped to the user's agency) to determine ownership and get the mapping ID.
  • If a local mapping exists, checks for active phone numbers assigned to the agent mapping in agency_phone_numbers. If any are found, unassigns them by setting agent_mapping_id to null.
  • Checks the call_batches table for any batches in pending, scheduled, or processing status linked to the agent mapping. If active batches exist, the deletion is blocked and a 400 error is returned with the count of active batches.
  • Unless keep_ultravox=true is set:
    • Retrieves the agency's Ultravox API key.
    • Sends a DELETE request to https://api.ultravox.ai/api/agents/{agent_id}.
    • Treats a 404 response from Ultravox as successful (agent already gone).
  • Deletes the local agent_mappings record (if one exists).
  • Returns a summary of what was deleted.

Database Tables

TableOperationDescription
usersReadFetches user profile to determine agency_id and role
agent_mappingsReadFetches the local mapping to check ownership and get the mapping ID
agency_phone_numbersReadChecks for active phone numbers assigned to the agent
agency_phone_numbersUpdateUnassigns phone numbers by setting agent_mapping_id to null
call_batchesReadChecks for active batches linked to the agent mapping
agent_mappingsDeleteRemoves the local mapping record

External APIs

APIMethodEndpointDescription
UltravoxDELETE/api/agents/{agent_id}Deletes the agent from Ultravox (unless keep_ultravox=true)