How would I delete thread ID content of assistant using Python code?

Hello everyone, I have seen the input and output results executed by the assistant I designed in the OpenAI thread list.

The official cookbook code provided is quite special

https://platform.openai.com/…/messages/deleteMessage

curl https://api.openai.com/v1/threads/thread_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -X DELETE
  1. If my code below can respond to a list of questions through the assistant sequentially, how should I delete the thread after all the questions have been answered?

  2. Additionally, you mentioned that OpenAI retains API data for up to 30 days for safety and moderation concerns. However, I see that my personal account’s assistant thread records still have data from almost six months ago.
    How can I ensure that I delete these messages uploaded through the assistant?

Thank you.

Here is the my Python code related to managing threads:

segments = [Q1, Q2, Q3, ...] 
# Load or create a conversation thread
try:
    with open('thread_id_test.txt', 'r') as f:
        thread_id = f.readline().strip()
    print("Using existing thread ID:", thread_id)
except FileNotFoundError:
    thread = client.beta.threads.create()
    thread_id = thread.id
    with open('thread_id_test.txt', 'w') as f:
        f.write(thread_id)
    print("Created new thread ID:", thread_id)

# Initially send a system prompt to the conversation thread
client.beta.threads.messages.create(
    thread_id=thread_id,
    role="user",
    content=system_prompt
)

# Loop through each text segment
countm = 0
for segment in segments:
    countm += 1
    # Send messages to the conversation thread
    client.beta.threads.messages.create(
        thread_id=thread_id,
        role="user",
        content=segment  # Send current question
    )

    # Execute the assistant for the current segment
    run = client.beta.threads.runs.create(
        thread_id=thread_id,
        assistant_id=assistant_id
    )

    # Check the execution results
    while True:
        run = client.beta.threads.runs.retrieve(
            thread_id=thread_id,
            run_id=run.id
        )
        if run.status == "completed":
            print(f"Run completed. Segment {countm}")
            break
        elif run.status == "failed":
            print("Run failed with error:", run.last_error)
            break
        time.sleep(2)

    messages = client.beta.threads.messages.list(
        thread_id=thread_id
    )
    message = messages.data[0].content[0].text.value
    print(message)