Questions about programming with the OpenAI Assistant API and how to invoke an existing assistant ID

Hello everyone, I have a question about using the OpenAI assistant API with Python.

I am currently trying to split a long text into shorter segments, each containing 30 lines, to ensure they do not exceed the 4096 token limit for prompts.

Initially, I defined a system_prompt that contains guidelines on how to summarize the following input segment text.

I then plan to continuously upload these segmented texts and extract summaries based on the criteria in my system_prompt.

Here’s my current code setup, which successfully creates an assistant visible on the OpenAI website:

  1. However, I’m unsure how to keep feeding the segmented texts to the assistant in a manner that keeps all interactions under the same thread, similar to how it works in the assistant playground:

  2. Additionally, every time I run a test program, my account at creates a new assistant. I’ve accumulated hundreds of them by now, almost all with identical content. I was wondering how I could just call an existing assistant ID, as it would be more convenient to directly modify the content of that assistant in the system.

Can anyone guide me on how to proceed with uploading the segmented texts to continue in the same thread, maintaining context as if it was a continuous conversation? Additionally reuse existing assistant created on OpenAI platform?

Thank you.

Here is the code I have written so far:

lines_per_segment = 30
system_prompt =  f""guideline prompt"
#API connect
with open('key.txt', 'r') as f:
    OPENAI_API_KEY = f.readline()

client = OpenAI(api_key=OPENAI_API_KEY)

#step : Create assistant
assistant = client.beta.assistants.create(
    name="Session Summary Analysis",
    instructions="You are a professioinal assistant tasked with summarizing the interview data",
# step 3: Create thread
thread = client.beta.threads.create()
# step 4: Add user query
    content= system_prompt

token_count_system = len(encoding.encode(system_prompt))
print(f"The content contains {token_count_system} tokens.")

# step 5: Run assistant
run = client.beta.threads.runs.create(,

print("Assistant ID:",
print("Thread ID:",

# step 6: Check run results
while True:
    run = client.beta.threads.runs.retrieve(,
    if run.status == "completed":
    if run.status == "failed":
        print("failed error:", run.last_error)

print("step 6 completed")