Update and Delete a Conversation Using CustomGPT.ai RAG API’s Python SDK – A Complete Developer Guide

Update and Delete a Conversation Using CustomGPT.ai RAG API’s Python SDK

Chat projects accumulate test sessions, support threads, or demo conversations that you may want to rename for clarity—or remove entirely. This tutorial walks you through how to update and delete a conversation in code, using the CustomGPTs RAG APIs Python SDK implementation.

We’ll cover:

  1. Installing and authenticating the SDK
  2. Listing conversations to find the right session_id
  3. Renaming a conversation (updating its metadata)
  4. Deleting a conversation permanently
  5. Verifying the operations and handling errors

If you’re new to CustomGPT, first sign up and read Getting Started with CustomGPT.ai. For deeper reference, see the API docs and the companion notebook in the GitHub Cookbook.

Prerequisites

  • API key with conversation‑management permissions
  • Python 3 environment (Colab, Jupyter, or local)
  • customgpt‑client installed:
pip install customgpt-client
  • The project ID that owns the conversation(s) you want to modify
  • If you already know the session ID, great—otherwise we’ll fetch it

1 – Setup & Authentication

First, import the SDK and set your API key so future calls are authenticated automatically.

from customgpt_client import CustomGPT   # Main SDK interface

CustomGPT.api_key = "YOUR_API_TOKEN"     # ← Replace with your real token

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.

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.

Once the token is assigned, every SDK call will include the proper bearer header—no manual work needed.

2 – List Conversations to Identify a Session

If you don’t yet know which session_id to rename or delete, list recent conversations for your project.

conv_list = CustomGPT.Conversation.list(

    project_id="YOUR_PROJECT_ID"          # ← Replace with your project ID

)

# Display ID and current name for each conversation

for conv in conv_list.parsed.data.data:

    print(f"ID: {conv.id}   |  Name: {conv.name}")

What’s happening here?
Conversation.list calls GET /projects/{id}/conversations.

We access parsed.data.data, which holds a list of conversation objects, then print their IDs and names so you can pick the correct session.

Now that you have a session_id, let’s rename the conversation.

3 – Update (Rename) a Conversation

Renaming gives context—think “Q2 2025 Demo” or “Customer XYZ Onboarding.”

update_resp = CustomGPT.Conversation.update(

    project_id="YOUR_PROJECT_ID",            # ← Your project ID

    session_id="YOUR_SESSION_ID",            # ← Session you want to rename

    name="June 2025 Support Session",        # ← New name

    description="Support chat covering June issues"  # Optional description

)

print("Rename Status:", update_resp.status)   # Should print "success"

Line‑by‑line explanation

  • Conversation.update sends a PATCH/PUT to /projects/{id}/conversations/{session_id}.
  • The name field updates the visible label; description adds extra context.
  • A “success” status means the server saved your changes.

Name updated—let’s see how to update and delete a conversation when you’re done with it.

4 – Delete a Conversation

Use deletion when a conversation is no longer relevant—or if policy requires purging old data.

delete_resp = CustomGPT.Conversation.delete(

    project_id="YOUR_PROJECT_ID",        # ← Same project ID

    session_id="YOUR_SESSION_ID"         # ← Session to remove

)

print("Delete Status:", delete_resp.status)   # Expect "success"

Heads‑up
This is irreversible. All messages inside that session are permanently removed.

To be extra sure, we’ll try to fetch the conversation and handle the expected error.

5 – Verify Deletion (Optional Safety Check)

Attempting to fetch a deleted conversation should error out—catch it to confirm.

try:

    CustomGPT.Conversation.get(

        project_id="YOUR_PROJECT_ID",

        session_id="YOUR_SESSION_ID"

    )

except Exception as e:

    print("Expected error (session deleted):", e)

If the SDK throws an exception (e.g., “Conversation not found”), you know the delete call succeeded.

Troubleshooting Tips

  • Invalid token errors – Re‑check CustomGPT.api_key; regenerate if expired.
  • Permission denied – Ensure your API key includes conversation‑management scopes.
  • List returns empty – Verify the correct project_id and that conversations actually exist.
  • Delete says “success” but still lists – Wait a few seconds and refresh; caching or pagination can briefly show stale data.

FAQs

Can I recover a deleted conversation?

No—deletion is permanent.

Does deleting free up credits?

Credits are spent at message time, not storage time, so deletion doesn’t refund usage.

Which fields are updatable on a conversation?

Only name and description.

Does renaming affect chat history?

No—messages remain intact under the new name.

How do I batch delete many sessions?

Loop through IDs from Conversation.list and call delete on each.

Related Reading

    Need more detail? Dive into the CustomGPT API docs or open the GitHub Cookbook notebook for a runnable example.

    Conclusion

    You’ve just learned to:

    1. Authenticate the CustomGPT Python SDK
    2. List conversations to grab a session_id
    3. Rename a session to keep things organized
    4. Permanently delete a conversation when it’s no longer needed
    5. Verify your actions and handle errors gracefully

    Use these techniques to keep your CustomGPT workspace tidy and compliant with your data‑retention policies. Happy coding—and may your chat history stay clean and manageable!

    Make Money With AI

    Join our Partner Programs!

    Boost your reputation, drive revenue and grow your business with CustomGPT.ai.

    Build a Custom GPT for your business, in minutes.

    Deliver exceptional customer experiences and maximize employee efficiency with custom AI agents.

    Trusted by thousands of organizations worldwide

    Related posts

    Leave a reply

    Your email address will not be published. Required fields are marked *

    *

    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.