Delete Thread
curl --request DELETE \
--url https://api.mycura.org/api/cura/threads/{id} \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://api.mycura.org/api/cura/threads/{id}"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://api.mycura.org/api/cura/threads/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mycura.org/api/cura/threads/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mycura.org/api/cura/threads/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://api.mycura.org/api/cura/threads/{id}")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mycura.org/api/cura/threads/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"error": "Thread not found"
}
{
"error": "Unauthorized - Invalid API key"
}
{
"error": "Failed to delete thread"
}
Conversation Threads
Delete Thread
Manually end and delete a conversation thread
DELETE
/
api
/
cura
/
threads
/
{id}
Delete Thread
curl --request DELETE \
--url https://api.mycura.org/api/cura/threads/{id} \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://api.mycura.org/api/cura/threads/{id}"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://api.mycura.org/api/cura/threads/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mycura.org/api/cura/threads/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mycura.org/api/cura/threads/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://api.mycura.org/api/cura/threads/{id}")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mycura.org/api/cura/threads/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"error": "Thread not found"
}
{
"error": "Unauthorized - Invalid API key"
}
{
"error": "Failed to delete thread"
}
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
string
required
Your Cura API key
Path Parameters
string
required
The 5-digit thread ID to delete (e.g.,
82451)Request Example
curl -X DELETE "https://api.mycura.org/api/cura/threads/82451" \
-H "X-API-Key: YOUR_API_KEY"
const axios = require('axios');
const response = await axios.delete(
'https://api.mycura.org/api/cura/threads/82451',
{
headers: {
'X-API-Key': 'YOUR_API_KEY'
}
}
);
console.log(response.data.message);
// "Thread deleted successfully"
import requests
response = requests.delete(
'https://api.mycura.org/api/cura/threads/82451',
headers={
'X-API-Key': 'YOUR_API_KEY'
}
)
print(response.json()['message'])
# "Thread deleted successfully"
<?php
$ch = curl_init('https://api.mycura.org/api/cura/threads/82451');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: YOUR_API_KEY'
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
echo $data['message'];
?>
Response
boolean
Whether the deletion was successful
string
Confirmation message
Success Response (200)
{
"success": true,
"message": "Thread deleted successfully"
}
Error Responses
{
"error": "Thread not found"
}
{
"error": "Unauthorized - Invalid API key"
}
{
"error": "Failed to delete thread"
}
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://api.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://api.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://api.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
Always clean up on logout
Always clean up on logout
Delete threads when users log out or close sessions to protect privacy:
auth.onLogout(async () => {
if (currentThreadId) {
await deleteThread(currentThreadId);
}
});
Handle deletion failures gracefully
Handle deletion failures gracefully
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();
Use sendBeacon for browser close
Use sendBeacon for browser close
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 })
);
}
});
Track deletion in analytics
Track deletion in analytics
Monitor how users are ending conversations:
async function deleteThread(threadId) {
await axios.delete(
`https://api.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.
- 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
Related Endpoints
Create Thread
Start a new conversation
Get Thread
Check thread status
Chat
Send messages to a thread
Next Steps
Conversation Threads Guide
Learn about thread lifecycle and management
Best Practices
Tips for production applications
Was this page helpful?

