SpyBara
Go Premium

resources/beta/subresources/threads/methods/create/index.md 2026-10-29 23:59 UTC to 2026-10-30 23:59 UTC

This page contains 2 additions and 0 deletions.

2026
Fri 2 23:58 Tue 6 22:58 Wed 28 23:00 Thu 29 23:59 Fri 30 23:59

For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.

Create thread

post /threads

Create a thread.

Body Parameters

Content type: application/json

  • messages: optional array of object { content, role, attachments, metadata }

    A list of messages to start the thread with.

    • content: string or array of ImageFileContentBlock or ImageURLContentBlock or TextContentBlockParam

      The text contents of the message.

      • TextContent = string

        The text contents of the message.

      • ArrayOfContentParts = array of ImageFileContentBlock or ImageURLContentBlock or TextContentBlockParam

        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.

        minItems: 1

        • ImageFileContentBlock object { image_file, type }

          References an image File in the content of a message.

          • image_file: ImageFile

            • file_id: string

              The File ID of the image in the message content. Set purpose="vision" when uploading the File if you need to later display the file content.

            • detail: optional "auto" or "low" or "high" (default: "auto")

              Specifies the detail level of the image if specified by the user. low uses fewer tokens, you can opt in to high resolution using high.

              • "auto"

              • "low"

              • "high"

          • type: "image_file"

            Always image_file.

            • "image_file"
        • ImageURLContentBlock object { image_url, type }

          References an image URL in the content of a message.

          • image_url: ImageURL

            • url: string

              The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.

              format: uri

            • detail: optional "auto" or "low" or "high" (default: "auto")

              Specifies the detail level of the image. low uses fewer tokens, you can opt in to high resolution using high. Default value is auto

              • "auto"

              • "low"

              • "high"

          • type: "image_url"

            The type of the content part.

            • "image_url"
        • TextContentBlockParam object { text, type }

          The text content that is part of a message.

          • text: string

            Text content to be sent to the model

          • type: "text"

            Always text.

            • "text"
    • role: "user" or "assistant"

      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.

      • "user"

      • "assistant"

    • attachments: optional array of object { file_id, tools } or null

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

      • file_id: optional string

        The ID of the file to attach to the message.

      • tools: optional array of CodeInterpreterTool or FileSearchTool { type }

        The tools to add this file to.

        • CodeInterpreterTool object { type }

          • type: "code_interpreter"

            The type of tool being defined: code_interpreter

            • "code_interpreter"
        • FileSearchTool object { type }

          • type: "file_search"

            The type of tool being defined: file_search

            • "file_search"
    • metadata: optional Metadata or 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.

  • metadata: optional Metadata or 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.

  • tool_resources: optional object { code_interpreter, file_search } or 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.

    • code_interpreter: optional object { file_ids }

      • file_ids: optional array of string (default: [])

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

        maxItems: 20

    • file_search: optional object { vector_store_ids, vector_stores }

      • vector_store_ids: optional array of string

        The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.

        maxItems: 1

      • vector_stores: optional array of object { chunking_strategy, file_ids, metadata }

        A helper to create a vector store with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread.

        maxItems: 1

        • chunking_strategy: optional Auto { type } or Static { static, type }

          The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.

          • Auto object { type }

            The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400.

            • type: "auto"

              Always auto.

              • "auto"
          • Static object { static, type }

            • static: object { chunk_overlap_tokens, max_chunk_size_tokens }

              • chunk_overlap_tokens: integer

                The number of tokens that overlap between chunks. The default value is 400.

                Note that the overlap must not exceed half of max_chunk_size_tokens.

              • max_chunk_size_tokens: integer

                The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096.

                minimum: 100, maximum: 4096

            • type: "static"

              Always static.

              • "static"
        • file_ids: optional array of string

          A list of file IDs to add to the vector store. For vector stores created before Nov 2025, there can be a maximum of 10,000 files in a vector store. For vector stores created starting in Nov 2025, the limit is 100,000,000 files.

          maxItems: 100000000

        • metadata: optional Metadata or 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.

Returns

  • Thread object { id, created_at, metadata, 2 more }

    Represents a thread that contains messages.

    • id: string

      The identifier, which can be referenced in API endpoints.

    • created_at: integer

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

      format: unixtime

    • metadata: Metadata or 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.

    • object: "thread"

      The object type, which is always thread.

      • "thread"
    • tool_resources: object { code_interpreter, file_search } or 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.

      • code_interpreter: optional object { file_ids }

        • file_ids: optional array of string (default: [])

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

          maxItems: 20

      • file_search: optional object { vector_store_ids }

        • vector_store_ids: optional array of string

          The vector store attached to this thread. There can be a maximum of 1 vector store attached to the thread.

          maxItems: 1

Example

curl https://api.openai.com/v1/threads \
    -X POST \
    -H 'OpenAI-Beta: assistants=v2' \
    -H "Authorization: Bearer $OPENAI_API_KEY"

200 — Example

{
  "id": "id",
  "created_at": 0,
  "metadata": {
    "foo": "string"
  },
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "string"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ]
    }
  }
}

Empty

curl https://api.openai.com/v1/threads \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d ''

Response example

{
  "id": "thread_abc123",
  "object": "thread",
  "created_at": 1699012949,
  "metadata": {},
  "tool_resources": {}
}

Messages

curl https://api.openai.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d '{
    "messages": [{
      "role": "user",
      "content": "Hello, what is AI?"
    }, {
      "role": "user",
      "content": "How does AI work? Explain it in simple terms."
    }]
  }'

Response example

{
  "id": "thread_abc123",
  "object": "thread",
  "created_at": 1699014083,
  "metadata": {},
  "tool_resources": {}
}