Skip to main content
DELETE
https://app.mycura.org
/
api
/
cura
/
threads
/
{id}
Delete Thread
curl --request DELETE \
  --url https://app.mycura.org/api/cura/threads/{id} \
  --header 'X-API-Key: <x-api-key>'
{
  "error": "Thread not found"
}

Overview

Manually deletes a conversation thread before its automatic 30-minute expiration. Use this to:
  • End conversations when users log out
  • Clean up threads when a session ends
  • Protect privacy by removing conversation history
  • Free up server resources
Permanent Deletion: This action cannot be undone. All messages in the thread will be permanently deleted.

Authentication

X-API-Key
string
required
Your Cura API key

Path Parameters

id
string
required
The 5-digit thread ID to delete (e.g., 82451)

Request Example

curl -X DELETE "https://app.mycura.org/api/cura/threads/82451" \
  -H "X-API-Key: YOUR_API_KEY"

Response

success
boolean
Whether the deletion was successful
message
string
Confirmation message

Success Response (200)

{
  "success": true,
  "message": "Thread deleted successfully"
}

Error Responses

{
  "error": "Thread not found"
}

When to Delete Threads

User Logs Out

Delete threads when users end their session for privacy

Conversation Complete

Clean up when the conversation naturally concludes

Starting Fresh

Delete old thread before creating a new one for the same user

Error Recovery

Remove problematic threads to start clean

Common Use Cases

1. Delete on Logout

// Clean up thread when user logs out
async function handleLogout() {
  const threadId = sessionStorage.getItem('threadId');
  
  if (threadId) {
    try {
      await axios.delete(
        `https://app.mycura.org/api/cura/threads/${threadId}`,
        {
          headers: { 'X-API-Key': 'YOUR_API_KEY' }
        }
      );
      console.log('Thread deleted successfully');
    } catch (error) {
      console.error('Failed to delete thread:', error);
    } finally {
      sessionStorage.removeItem('threadId');
    }
  }
  
  // Proceed with logout
  await logout();
}

2. Delete on Browser Close

// Clean up thread when user closes the browser/tab
window.addEventListener('beforeunload', async (event) => {
  const threadId = sessionStorage.getItem('threadId');
  
  if (threadId) {
    // Use sendBeacon for guaranteed delivery
    const blob = new Blob(
      [JSON.stringify({ threadId })],
      { type: 'application/json' }
    );
    
    navigator.sendBeacon(
      'https://yourapp.com/api/cleanup-thread',
      blob
    );
    
    // Your backend should call DELETE /api/cura/threads/{id}
  }
});

3. Auto-Delete After Success

// Delete thread after successful task completion
async function completeRefillRequest(threadId) {
  // Process refill through conversation
  await chat({ 
    threadId, 
    message: "I'd like to refill my medication" 
  });
  
  // ... more conversation ...
  
  // Once refill is confirmed, clean up
  await axios.delete(
    `https://app.mycura.org/api/cura/threads/${threadId}`,
    {
      headers: { 'X-API-Key': 'YOUR_API_KEY' }
    }
  );
  
  console.log('Refill complete, thread deleted');
}

4. Replace Expired Thread

// Check if thread expired, delete and create new one
async function ensureActiveThread(oldThreadId) {
  try {
    // Try to get thread info
    await axios.get(
      `https://app.mycura.org/api/cura/threads/${oldThreadId}`,
      {
        headers: { 'X-API-Key': 'YOUR_API_KEY' }
      }
    );
    
    // Thread still exists, return it
    return oldThreadId;
    
  } catch (error) {
    if (error.response?.status === 404) {
      // Thread expired/deleted - create new one
      const newThread = await createThread();
      return newThread.threadId;
    }
    throw error;
  }
}

Best Practices

Delete threads when users log out or close sessions to protect privacy:
auth.onLogout(async () => {
  if (currentThreadId) {
    await deleteThread(currentThreadId);
  }
});
Don’t block user actions if thread deletion fails:
try {
  await deleteThread(threadId);
} catch (error) {
  // Log error but don't prevent logout
  console.error('Thread cleanup failed:', error);
}
// Continue with user action regardless
proceedWithLogout();
For reliable cleanup on page unload, use navigator.sendBeacon():
window.addEventListener('beforeunload', () => {
  if (threadId) {
    // This is guaranteed to send even if page is closing
    navigator.sendBeacon(
      '/api/cleanup',
      JSON.stringify({ threadId })
    );
  }
});
Monitor how users are ending conversations:
async function deleteThread(threadId) {
  await axios.delete(
    `https://app.mycura.org/api/cura/threads/${threadId}`,
    {
      headers: { 'X-API-Key': 'YOUR_API_KEY' }
    }
  );
  
  // Track the deletion
  analytics.track('thread_deleted', {
    threadId,
    trigger: 'user_action',
    timestamp: new Date().toISOString()
  });
}

Automatic Deletion

Reminder: Threads automatically delete after 30 minutes of inactivity. You don’t need to manually delete every thread - this endpoint is for when you want to end a conversation early.
The auto-deletion system:
  • Runs every 10 minutes on the server
  • Deletes threads inactive for 30+ minutes
  • Resets the timer every time a message is sent
  • Permanently removes all conversation data

Next Steps