Difference between Creating a Run and Creating a Thread and Run

Hello everyone!

I’m currently working on a chatbot assistant that helps users answer questions based on an uploaded file. The idea is that users can ask questions today and return multiple times in the future.

I’m trying to figure out the best approach for creating a “run” in this scenario. Which method would work best for my use case?

  1. Using client.beta.threads.runs.create
    or
  2. Using client.beta.threads.create_and_run

I’d love to hear your thoughts on which method is more efficient or better suited for managing recurring user interactions with the uploaded file.

Thanks in advance!

  1. Do you have a thread prepared with messages, and just want to start a run?
  2. Do you want to create a new thread, optionally including initial messages?

Do you want a user to rejoin an existing chat, and you are recording the chats of a user? Has the user started a new chat? Choose appropriately.

“Uploaded file” can mean several things.

Yes, i want user to comeback to the chat multiple times and record the conversation thread. Also, I want chatgpt to remember all past interactions with the user. Basically developing a customer support chatbot. As you know users might have different requests in different days.

One more question:

client.beta.threads.create_and_run

Piece of code above returns an object that includes thread id?

Create a thread and run it in one request.

  • Returns a run object:

{
“id”: “run_abc123”,
“object”: “thread.run”,
“created_at”: 1698107661,
“assistant_id”: “asst_abc123”,
“thread_id”: “thread_abc123”,
“status”: “completed”,
“started_at”: 1699073476,
“expires_at”: null,
“cancelled_at”: null,
“failed_at”: null,
“completed_at”: 1699073498,
“last_error”: null,
“model”: “gpt-4o”,
“instructions”: null,
“tools”: [{“type”: “file_search”}, {“type”: “code_interpreter”}],
“metadata”: {},
“incomplete_details”: null,
“usage”: {
“prompt_tokens”: 123,
“completion_tokens”: 456,
“total_tokens”: 579
},
“temperature”: 1.0,
“top_p”: 1.0,
“max_prompt_tokens”: 1000,
“max_completion_tokens”: 1000,
“truncation_strategy”: {
“type”: “auto”,
“last_messages”: null
},
“response_format”: “auto”,
“tool_choice”: “auto”,
“parallel_tool_calls”: true
}

It will have your new thread ID. You can now monitor status to see when a response is ready.


For further interactions with the same thread, you would:

  • Know the thread ID being referenced and the assistant you now want to run it against.
  1. add a new user input to the thread, with “create messages”
  2. start another run, with “create run”.
2 Likes

alright, let me try. Thank you for your guidance.