Skip to main content
POST
/
v1
/
sessions
/
{session_id}
/
cancel
Cancel Session
curl --request POST \
  --url https://api.example.com/v1/sessions/{session_id}/cancel \
  --header 'Authorization: <authorization>'
{
  "success": true,
  "message": "Session cancelled successfully"
}

Overview

Cancel the current task execution. The session remains active and can receive new messages to start a different task. Use this when you want to abandon the current task but keep the session.

Request

session_id
string
required
The UUID of the session
Authorization
string
required
Bearer token for authentication

Response

success
boolean
Whether the operation completed successfully
message
string
Result message
{
  "success": true,
  "message": "Session cancelled successfully"
}

Example

curl -X POST https://api.agi.tech/v1/sessions/<session_id>/cancel \
  -H "Authorization: Bearer $AGI_API_KEY"

Use Cases

Emergency Stop

# User clicks "stop" button
def emergency_stop(session_id):
    try:
        result = cancel_session(session_id)
        print("Task cancelled")
    except Exception as e:
        # Fallback: delete entire session
        delete_session(session_id)

User Rejection

# Pause for user approval, cancel if rejected
pause_session(session_id)
print("Agent wants to make a purchase. Approve? (y/n)")
approval = input()

if approval.lower() == 'y':
    resume_session(session_id)
else:
    cancel_session(session_id)

Task Abandonment

# Cancel current task and start a new one
cancel_session(session_id)

# Send new task
send_message(session_id, "Find flights to Paris instead")

Cancel vs Delete

OperationEffectUse When
CancelStop task, session stays activeWant to abandon current task
DeleteDestroy entire sessionCompletely done with session

Best Practices

Use cancel when you want to stop the current task but keep the session active for a new task.
After cancelling, the session remains active. Send a new message to start a different task, or delete the session to clean up.
Cancelled sessions can still receive new messages to start fresh tasks. Deleted sessions are permanently removed.