Benchmark

Claude Code is 4.2x faster & 3.2x cheaper with CustomGPT.ai plugin. See the report →

CustomGPT.ai Blog

Update and Delete a Conversation Using CustomGPT RAG API – A Complete Guide

Author Image

Written by: Priyansh Khodiyar

Update and Delete a Conversation Using CustomGPT RAG API

Watch the video above for a live demo and walkthrough of this guide! (coming soon)

1. Introduction

Hi there! In this tutorial, we’ll walk through the process of updating and deleting a conversation using the CustomGPT RAG API in a Google Colab notebook. You’ll learn how to create an agent (often still called a “project” in the code), initiate a conversation, update the conversation’s name, and delete a conversation if needed. This complete guide explains every step in detail, so let’s dive right in!

Make sure you have read our Getting Started with CustomGPT.ai for New Developers blog to get an overview of the entire platform, including enterprise AI solutions, and how CustomGPT.ai works.

By the end, you’ll be able to programmatically inspect where your chatbot’s content comes from. For full API reference, see the CustomGPT API docs.

Get the cookbook here – https://github.com/Poll-The-People/customgpt-cookbook/blob/main/examples/Update_Delete_a_conversation.ipynb

2. Setting Up the Environment

Before we start, we need to get our workspace ready. In our Google Colab notebook, we set up the API endpoint, add our API token, and import the necessary libraries.

# setup API URL and API Token

api_endpoint = 'https://app.customgpt.ai/api/v1/'

api_token = 'ADD_YOUR_API_TOKEN_HERE'

headers = {

    'Content-type': 'application/json',

    'Authorization': 'Bearer ' + api_token

}

# imports

import requests

import json

What This Does:

  • API Endpoint & Token: Establishes the base URL for all API calls and ensures authenticated requests using your API token.
  • Headers: Configures the HTTP headers to indicate that JSON data will be sent along with the authentication token.
  • Imports: Brings in the requests library for making HTTP calls and json for encoding/decoding JSON data.

Get API keys

To get your API key, there are two ways:

Method 1 – Via Agent

  1. Agent > All Agents.
  2. Select your agent and go to deploy, click on the API key section and create an API. 

Method 2 – Via Profile section.

  1. Go to profile (top right corner of your screen)
  2. Click on My Profile
  3. You will see the screen something like this (below screenshot). Here you can click on “Create API key”, give it a name and copy the key.
Create API

Please save this secret key somewhere safe and accessible. For security reasons, You won’t be able to view it again through your CustomGPT.ai account. If you lose this secret key, you’ll need to generate a new one.

Now that our environment is set up, make sure you have met all prerequisites before continuing.

3. Prerequisites

Before you begin, please ensure you have:

  • CustomGPT.ai Account: Sign up and log in at CustomGPT.ai.
  • API Key: Generate your API token from your account dashboard.
  • Basic Python Knowledge: Familiarity with Python and REST APIs.
  • Google Colab: No local installation is required, as we’ll be running this in Google Colab.

With all prerequisites checked off, let’s create an agent (project) for your account, whether it’s a general project or a WordPress site management agent.

4. Creating an Agent (Project)

Even though the code still uses the term “project,” we refer to these as agents. In this section, you’ll create an agent using a sitemap as its content source.

**Create a project for the account**

# Give a name to your project

project_name = 'Example ChatBot using Sitemap'

sitemap_path = 'https://adorosario.github.io/small-sitemap.xml'

payload = json.dumps({

    "project_name": project_name,

    "sitemap_path": sitemap_path

})

url = api_endpoint + 'projects'

create_project = requests.request('POST', url, headers=headers, data=payload)

print(create_project.text)

What This Does:

  • Agent Details: Sets up the agent’s name and defines a sitemap URL as the source of content.
  • Payload Creation: Encodes these details into JSON format.
  • POST Request: Sends a request to create the agent.
  • Output: Prints a JSON response including the agent’s unique ID (e.g., “id”:532) and other details.

Great! With your agent created, it’s time to open a conversation within it so you can retrieve conversation messages.

5. Creating a Conversation

Now, we’ll initiate a conversation in your newly created agent. Conversations allow you to interact with and track the communication history of your agent, which is especially useful when updating and deleting conversations.

**Create Project Conversation**

data = json.loads(create_project.text)["data"]

project_id = data["id"]

# Get the project settings

name = 'Test Converasation'

payload = json.dumps({

    "name": project_name

})

url = api_endpoint + 'projects' + f"/{project_id}" + '/conversations'

create_conversation = requests.request('POST', url, headers=headers, data=payload)

print(create_conversation.text)

What This Does:

  • Extract Agent ID: Parses the JSON response from the agent creation step to obtain the agent’s unique ID.
  • Set Conversation Name: Defines the conversation’s name; note that the payload here uses the original project name.
  • POST Request: Sends a request to the specific conversation endpoint within the agent.
  • Output: Prints a JSON response containing conversation details, including a session_id (e.g., “session_id”:”8ff8078b-3e88-4ad1-8e3f-9a37324964af”).

Now that you’ve created a conversation, let’s move forward to update its name.

6. Updating the Conversation Name

After starting the conversation, you might want to update its name to better reflect its purpose. Here’s how you can do that using a PUT request.

**Update a conversation name**

# Create a message to the above conversation

conversation_data = json.loads(create_conversation.text)["data"]

# session_id is important to maintain chat history

session_id = conversation_data["session_id"]

# pass in your updated conversation name

name = "Who is Tom"

url = api_endpoint + 'projects/' + str(project_id) + '/conversations/' + str(session_id)

payload = json.dumps({

    "name": name

})

update_conversation_response = requests.put(url, headers=headers, data=payload)

print(update_conversation_response.text)

What This Does:

  • Retrieve Session ID:
    Extracts the session_id from the conversation creation response to identify which conversation to update.
  • Define New Conversation Name:
    Sets the new name (in this case, “Who is Tom”) within the payload.
  • PUT Request:
    Sends a PUT request to update the conversation’s name. The URL is built using the agent’s ID and the conversation’s session ID.
  • Output:
    Prints a JSON response showing the updated conversation details, confirming that the name has been successfully updated.

With the conversation name updated, you’re now ready to see how deletion works. Let’s move on to the final step.

7. Deleting a Conversation

If you need to delete a conversation—maybe for cleanup or testing purposes—you can do this with a DELETE request.

**Delete a conversation**

url = api_endpoint + 'projects/' + str(project_id) + '/conversations/' + str(session_id)

payload = json.dumps({

    "name": name

})

delete_conversation_response = requests.delete(url, headers=headers)

print(delete_conversation_response.text)

What This Does:

  • Build Deletion URL:
    Constructs the URL for the DELETE endpoint using the agent’s ID and the session ID.
  • DELETE Request:
    Sends a DELETE request to remove the conversation.
  • Output:
    Prints a JSON response indicating whether the deletion was successful (e.g., “deleted”:true).

With this final step, you have successfully updated and then deleted a conversation within your agent.

8. Troubleshooting Common Issues

Here are some common issues you might encounter along with possible solutions:

  • Invalid API Token: Ensure you replace ‘ADD_YOUR_API_TOKEN_HERE’ with your valid API token.
  • JSON Formatting Errors: Verify that your JSON payloads are correctly formatted, especially when updating data.
  • Connection Problems: Check your internet connection and make sure the API endpoint is correct.
  • Unexpected API Responses: If the API responses are not as expected, print the raw responses for debugging and refer to the official CustomGPT API documentation for clarification.

If you still face issues, consider consulting the community forum or the official documentation for further support.

9. Conclusion

Congratulations! In this guide, you learned how to:

  • Set up your Google Colab environment with the necessary API configurations.
  • Create an agent (project) and start a conversation.
  • Update the name of an ongoing conversation.
  • Delete a conversation if necessary.

These steps provide a complete workflow for managing conversations using the CustomGPT API. Whether you’re updating conversation titles for clarity or cleaning up old conversations, these methods give you full control over your interactions with the API.

If you have any questions or need further assistance, feel free to check out the CustomGPT documentation or join our community for support.

Happy coding, and enjoy building and maintaining your chatbot solutions with CustomGPT!

Related Resources

If you’re working further with the CustomGPT.ai API, these pages expand on the next steps and adjacent setup options.

  • Creating Agents and Messages — Learn how to create an agent and send messages through the CustomGPT.ai API to start new conversations programmatically.
  • Create Agent From File — This guide shows how to build a custom agent from a file using the Python SDK, which is useful when setting up data-backed workflows in CustomGPT.ai.
  • Platform Integrations — Explore the integration options available in CustomGPT.ai to connect your agents with other tools and platforms.

Frequently Asked Questions

Can I rename a conversation after it has been created?

GEMA’s AI assistant handles 248,000 inquiries a year at an 88% success rate, so clear conversation labels can matter at scale. Yes. Updating a conversation lets you change the conversation name after creation. Use it when you want a clearer label while keeping the same chat thread instead of starting a new one.

How do I delete test or temporary conversations programmatically?

u0022We love CustomGPT.ai. It’s a fantastic Chat GPT tool kit that has allowed us to create a ‘lab’ for testing AI models. The results? High accuracy and efficiency leave people asking, ‘How did you do it?’ We’ve tested over 30 models with hundreds of iterations using CustomGPT.ai.u0022 — Brendan McSheffrey, Managing Partner u0026 Founder, The Kendall Project. To delete temporary conversations programmatically, store the conversation ID and send an authenticated delete request for that conversation. This is the cleanest pattern for demos, QA runs, and short-lived test chats.

Can conversations expire automatically, or do I need to delete them myself?

Automatic conversation expiration is not documented. If you need a retention policy, set the schedule in your own application and call the delete action explicitly. That approach also fits privacy-sensitive workflows, since the platform is GDPR compliant and states that customer data is not used for model training.

Does deleting a conversation remove the knowledge base or just the chat thread?

u0022CustomGPT.ai isn’t just a support tool. It’s become a knowledge infrastructure for our organization. It allows us to serve members, customers, and employees better, faster, and smarter.u0022 — Jonas Walther, Manager Data u0026 AI, GEMA. Deleting a conversation is a thread-level action. It removes the targeted chat conversation, not the broader knowledge setup behind the agent. Use it for chat cleanup, not for removing source content.

When should I rename a conversation instead of starting a new one?

Rename a conversation when the work is still the same case, customer, or workflow and you only need a better label. Start a new conversation when you want a fresh context with separate history. Updating the name is best for organization; creating a new conversation is best for context separation.

Why am I getting 401 or 404 when updating or deleting a conversation?

The platform is SOC 2 Type 2 certified, so authenticated actions are intentionally explicit. A 401 usually points to a missing or invalid API key or Authorization header. A 404 usually means the URL or conversation identifier does not match an existing resource. Check the base API URL, confirm the Bearer token format, and verify the conversation ID before retrying.

Can I update or delete conversations from PHP, WhatsApp, or another external app?

u0022They’ve officially cracked the sub-second barrier, a breakthrough that fundamentally changes the user experience from merely ‘interactive’ to ‘instantaneous’.u0022 — Bill French, Technology Strategist. Yes. You can update or delete conversations from PHP or any other backend that can send authenticated HTTPS requests, and PHP is listed among the supported SDK languages. For chat channels such as WhatsApp, your backend can call the API after receiving the message event, so conversation management stays server-side.

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.