Create thread

POST /threads

Create a thread.

application/json

Body

  • messages array[object]

    A list of messages to start the thread with.

    Hide messages attributes Show messages attributes object
    • role string Required

      The role of the entity that is creating the message. Allowed values include:

      • user: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.
      • assistant: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation.

      Values are user or assistant.

    • content string | array[object] Required

      One of:

      The text contents of the message.

      An array of content parts with a defined type, each can be of type text or images can be passed with image_url or image_file. Image types are only supported on Vision-compatible models.

      At least 1 element.

      One of:
    • attachments array[object] | null

      A list of files attached to the message, and the tools they should be added to.

      Hide attachments attributes Show attachments attributes object
      • file_id string

        The ID of the file to attach to the message.

      • tools array[object]

        The tools to add this file to.

        One of:
    • metadata object | null

      Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

  • tool_resources object | null

    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.

    Hide tool_resources attributes Show tool_resources attributes object | null
    • Hide code_interpreter attribute Show code_interpreter attribute object
      • file_ids array[string]

        A list of file IDs made available to the code_interpreter tool. There can be a maximum of 20 files associated with the tool.

        Not more than 20 elements. Default value is [] (empty).

  • metadata object | null

    Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

Responses

  • 200 application/json

    OK

    Hide response attributes Show response attributes object
    • id string Required

      The identifier, which can be referenced in API endpoints.

    • object string Required

      The object type, which is always thread.

      Value is thread.

    • created_at integer Required

      The Unix timestamp (in seconds) for when the thread was created.

    • tool_resources object | null Required

      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.

      Hide tool_resources attributes Show tool_resources attributes object | null
      • Hide code_interpreter attribute Show code_interpreter attribute object
        • file_ids array[string]

          A list of file IDs made available to the code_interpreter tool. There can be a maximum of 20 files associated with the tool.

          Not more than 20 elements. Default value is [] (empty).

    • metadata object | null Required

      Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

POST /threads
curl \
 -X POST https://api.openai.com/v1/threads \
 -H "Authorization: Bearer $ACCESS_TOKEN" \
 -H "Content-Type: application/json" \
 -d '{"messages":[{"role":"user","content":"string","attachments":[{"file_id":"string","tools":[{"type":"code_interpreter"}]}],"metadata":{}}],"tool_resources":{"code_interpreter":{"file_ids":[]},"file_search":{"vector_store_ids":["string"],"vector_stores":[{"file_ids":["string"],"chunking_strategy":{"type":"auto"},"metadata":{}}]}},"metadata":{}}'
Request example
{
  "messages": [
    {
      "role": "user",
      "content": "string",
      "attachments": [
        {
          "file_id": "string",
          "tools": [
            {
              "type": "code_interpreter"
            }
          ]
        }
      ],
      "metadata": {}
    }
  ],
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ],
      "vector_stores": [
        {
          "file_ids": [
            "string"
          ],
          "chunking_strategy": {
            "type": "auto"
          },
          "metadata": {}
        }
      ]
    }
  },
  "metadata": {}
}
Response examples (200)
{
  "id": "string",
  "object": "thread",
  "created_at": 42,
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ]
    }
  },
  "metadata": {}
}