Skip to content
Primary navigation

Create thread

Deprecated
Thread beta().threads().create(ThreadCreateParamsparams = ThreadCreateParams.none(), RequestOptionsrequestOptions = RequestOptions.none())
POST/threads

Create a thread.

ParametersExpand Collapse
ThreadCreateParams params
Optional<List<Message>> messages

A list of messages to start the thread with.

Content content

The text contents of the message.

One of the following:
String
One of the following:
class ImageFileContentBlock:

References an image File in the content of a message.

ImageFile imageFile
String fileId

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.

Optional<Detail> detail

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.

One of the following:
AUTO("auto")
LOW("low")
HIGH("high")
JsonValue; type "image_file"constant"image_file"constant

Always image_file.

class ImageUrlContentBlock:

References an image URL in the content of a message.

ImageUrl imageUrl
String url

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

formaturi
Optional<Detail> detail

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

One of the following:
AUTO("auto")
LOW("low")
HIGH("high")
JsonValue; type "image_url"constant"image_url"constant

The type of the content part.

class TextContentBlockParam:

The text content that is part of a message.

String text

Text content to be sent to the model

JsonValue; type "text"constant"text"constant

Always text.

Role role

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.
One of the following:
USER("user")
ASSISTANT("assistant")
Optional<List<Attachment>> attachments

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

Optional<String> fileId

The ID of the file to attach to the message.

Optional<List<Tool>> tools

The tools to add this file to.

One of the following:
class CodeInterpreterTool:
JsonValue; type "code_interpreter"constant"code_interpreter"constant

The type of tool being defined: code_interpreter

JsonValue;
JsonValue; type "file_search"constant"file_search"constant

The type of tool being defined: file_search

Optional<Metadata> metadata

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.

Optional<Metadata> metadata

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.

Optional<ToolResources> toolResources

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.

Optional<CodeInterpreter> codeInterpreter
Optional<List<String>> fileIds

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

One of the following:
ReturnsExpand Collapse
class Thread:

Represents a thread that contains messages.

String id

The identifier, which can be referenced in API endpoints.

long createdAt

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

Optional<Metadata> metadata

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.

JsonValue; object_ "thread"constant"thread"constant

The object type, which is always thread.

Optional<ToolResources> toolResources

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.

Optional<CodeInterpreter> codeInterpreter
Optional<List<String>> fileIds

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

Create thread

package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.threads.Thread;
import com.openai.models.beta.threads.ThreadCreateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        Thread thread = client.beta().threads().create();
    }
}
{
  "id": "id",
  "created_at": 0,
  "metadata": {
    "foo": "string"
  },
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "string"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ]
    }
  }
}
Returns Examples
{
  "id": "id",
  "created_at": 0,
  "metadata": {
    "foo": "string"
  },
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "string"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "string"
      ]
    }
  }
}