Create a thread.

POST /threads
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.

    • 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:
        Hide attribute Show attribute
        • type string Required

          The type of tool being defined: code_interpreter

          Value is code_interpreter.

    • 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, and querying for objects via API or the dashboard.

      Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

      Hide metadata attribute Show metadata attribute object | null
      • * string Additional properties
  • 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
    • code_interpreter object
      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, and querying for objects via API or the dashboard.

    Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

    Hide metadata attribute Show metadata attribute object | null
    • * string Additional properties

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
      • code_interpreter object
        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, and querying for objects via API or the dashboard.

      Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

      Hide metadata attribute Show metadata attribute object | null
      • * string Additional properties
POST /threads
curl \
 --request POST 'https://api.openai.com/v1/threads' \
 --header "Authorization: Bearer $ACCESS_TOKEN" \
 --header "Content-Type: application/json" \
 --data '{"messages":[{"role":"user","content":"string","attachments":[{"file_id":"string","tools":[{"type":"code_interpreter"}]}],"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}}],"tool_resources":{"code_interpreter":{"file_ids":[]},"file_search":{"vector_store_ids":["string"],"vector_stores":[{"file_ids":["string"],"chunking_strategy":{"type":"auto"},"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}}]}},"metadata":{"additionalProperty1":"string","additionalProperty2":"string"}}'
Request examples
{
  "messages": [
    {
      "role": "user",
      "content": "string",
      "attachments": [
        {
          "file_id": "string",
          "tools": [
            {
              "type": "code_interpreter"
            }
          ]
        }
      ],
      "metadata": {
        "additionalProperty1": "string",
        "additionalProperty2": "string"
      }
    }
  ],
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ],
      "vector_stores": [
        {
          "file_ids": [
            "string"
          ],
          "chunking_strategy": {
            "type": "auto"
          },
          "metadata": {
            "additionalProperty1": "string",
            "additionalProperty2": "string"
          }
        }
      ]
    }
  },
  "metadata": {
    "additionalProperty1": "string",
    "additionalProperty2": "string"
  }
}
Response examples (200)
{
  "id": "string",
  "object": "thread",
  "created_at": 42,
  "tool_resources": {
    "code_interpreter": {
      "file_ids": []
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ]
    }
  },
  "metadata": {
    "additionalProperty1": "string",
    "additionalProperty2": "string"
  }
}