> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/openai/openai-python/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing Threads

<Warning>
  The Assistants API is deprecated in favor of the Responses API.
</Warning>

Create a thread for conversations with an assistant.

## Create Thread

### Request Body

<ParamField body="messages" type="array">
  A list of messages to start the thread with.

  <Expandable title="Message object">
    <ParamField body="role" type="string" required>
      The role of the entity creating the message. Either `user` or `assistant`.
    </ParamField>

    <ParamField body="content" type="string" required>
      The text contents of the message.
    </ParamField>

    <ParamField body="attachments" type="array">
      A list of files attached to the message, and the tools they should be added to.
    </ParamField>

    <ParamField body="metadata" type="object">
      Set of 16 key-value pairs that can be attached to an object.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tool_resources" type="object">
  A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
</ParamField>

<ParamField body="metadata" type="object">
  Set of 16 key-value pairs that can be attached to an object.

  Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
</ParamField>

## Response

Returns a `Thread` object.

<ResponseField name="id" type="string">
  The thread identifier.
</ResponseField>

<ResponseField name="object" type="string">
  The object type, always `thread`.
</ResponseField>

<ResponseField name="created_at" type="integer">
  The Unix timestamp (in seconds) for when the thread was created.
</ResponseField>

<ResponseField name="metadata" type="object">
  Set of 16 key-value pairs attached to the object.
</ResponseField>

## Retrieve Thread

`GET https://api.openai.com/v1/threads/{thread_id}`

Retrieves a thread.

## Update Thread

`POST https://api.openai.com/v1/threads/{thread_id}`

Modifies a thread.

## Delete Thread

`DELETE https://api.openai.com/v1/threads/{thread_id}`

Delete a thread.

<RequestExample>
  ```python Python theme={null}
  from openai import OpenAI
  client = OpenAI()

  # Create a thread
  thread = client.beta.threads.create(
      messages=[
          {
              "role": "user",
              "content": "Explain quantum computing in simple terms."
          }
      ]
  )

  print(thread.id)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from "openai";
  const openai = new OpenAI();

  // Create a thread
  const thread = await openai.beta.threads.create({
    messages: [
      {
        role: "user",
        content: "Explain quantum computing in simple terms."
      }
    ]
  });

  console.log(thread.id);
  ```

  ```bash cURL theme={null}
  curl https://api.openai.com/v1/threads \\
    -H "Authorization: Bearer $OPENAI_API_KEY" \\
    -H "Content-Type: application/json" \\
    -H "OpenAI-Beta: assistants=v2" \\
    -d '{
      "messages": [
        {
          "role": "user",
          "content": "Explain quantum computing in simple terms."
        }
      ]
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "id": "thread_abc123",
    "object": "thread",
    "created_at": 1699012949,
    "metadata": {},
    "tool_resources": {}
  }
  ```
</ResponseExample>
