Skip to content

Index

Modules:

Name Description
messages
runs
threads

The threads module facilitates the creation, retrieval, update, deletion, and execution of Threads. Threads represent a series of messages or interactions with an assistant and support a conversational context or a sequence of operations.

Classes:

Name Description
AsyncMessages
AsyncMessagesWithRawResponse
AsyncMessagesWithStreamingResponse
AsyncRuns
AsyncRunsWithRawResponse
AsyncRunsWithStreamingResponse
AsyncThreads
AsyncThreadsWithRawResponse
AsyncThreadsWithStreamingResponse
Messages
MessagesWithRawResponse
MessagesWithStreamingResponse
Runs
RunsWithRawResponse
RunsWithStreamingResponse
Threads
ThreadsWithRawResponse
ThreadsWithStreamingResponse

AsyncMessages

AsyncMessages(client: AsyncOpenAI)

Methods:

Name Description
create

Create a message.

files
list

Returns a list of messages for a given thread.

retrieve

Retrieve a message.

update

Modifies a message.

with_raw_response
with_streaming_response

create async

create(
    thread_id: str,
    *,
    content: str,
    role: Literal["user"],
    file_ids: List[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Create a message.

Parameters:

Name Type Description Default
content str

The content of the message.

required
role Literal['user']

The role of the entity that is creating the message. Currently only user is supported.

required
file_ids List[str] | NotGiven

A list of File IDs that the message should use. There can be a maximum of 10 files attached to a message. Useful for tools like retrieval and code_interpreter that can access and use files.

NOT_GIVEN
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

files

files() -> AsyncFiles

list

list(
    thread_id: str,
    *,
    after: str | NotGiven = NOT_GIVEN,
    before: str | NotGiven = NOT_GIVEN,
    limit: int | NotGiven = NOT_GIVEN,
    order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncPaginator[Message, AsyncCursorPage[Message]]

Returns a list of messages for a given thread.

Parameters:

Name Type Description Default
after str | NotGiven

A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

NOT_GIVEN
before str | NotGiven

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

NOT_GIVEN
limit int | NotGiven

A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

NOT_GIVEN
order Literal['asc', 'desc'] | NotGiven

Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

retrieve async

retrieve(
    message_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Retrieve a message.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

update async

update(
    message_id: str,
    *,
    thread_id: str,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Modifies a message.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> AsyncMessagesWithRawResponse

with_streaming_response

with_streaming_response() -> (
    AsyncMessagesWithStreamingResponse
)

AsyncMessagesWithRawResponse

AsyncMessagesWithRawResponse(messages: AsyncMessages)

Methods:

Name Description
files

Attributes:

Name Type Description
create
list
retrieve
update

create instance-attribute

create = async_to_raw_response_wrapper(create)

list instance-attribute

list = async_to_raw_response_wrapper(list)

retrieve instance-attribute

retrieve = async_to_raw_response_wrapper(retrieve)

update instance-attribute

update = async_to_raw_response_wrapper(update)

files

AsyncMessagesWithStreamingResponse

AsyncMessagesWithStreamingResponse(messages: AsyncMessages)

Methods:

Name Description
files

Attributes:

Name Type Description
create
list
retrieve
update

create instance-attribute

create = async_to_streamed_response_wrapper(create)

list instance-attribute

list = async_to_streamed_response_wrapper(list)

retrieve instance-attribute

retrieve = async_to_streamed_response_wrapper(retrieve)

update instance-attribute

update = async_to_streamed_response_wrapper(update)

AsyncRuns

AsyncRuns(client: AsyncOpenAI)

Methods:

Name Description
cancel

Cancels a run that is in_progress.

create
create_and_stream

Create a Run stream

list

Returns a list of runs belonging to a thread.

retrieve

Retrieves a run.

steps
submit_tool_outputs
submit_tool_outputs_stream

Submit the tool outputs from a previous run and stream the run to a terminal

update

Modifies a run.

with_raw_response
with_streaming_response

cancel async

cancel(
    run_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Cancels a run that is in_progress.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

create async

create(
    thread_id: str,
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
create(
    thread_id: str,
    *,
    assistant_id: str,
    stream: Literal[True],
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncStream[AssistantStreamEvent]
create(
    thread_id: str,
    *,
    assistant_id: str,
    stream: bool,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]
create(
    thread_id: str,
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]

create_and_stream

create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandler
]
create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    event_handler: AsyncAssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandlerT
]
create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    event_handler: (
        AsyncAssistantEventHandlerT | None
    ) = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AsyncAssistantStreamManager[AsyncAssistantEventHandler]
    | AsyncAssistantStreamManager[
        AsyncAssistantEventHandlerT
    ]
)

Create a Run stream

list

list(
    thread_id: str,
    *,
    after: str | NotGiven = NOT_GIVEN,
    before: str | NotGiven = NOT_GIVEN,
    limit: int | NotGiven = NOT_GIVEN,
    order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncPaginator[Run, AsyncCursorPage[Run]]

Returns a list of runs belonging to a thread.

Parameters:

Name Type Description Default
after str | NotGiven

A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

NOT_GIVEN
before str | NotGiven

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

NOT_GIVEN
limit int | NotGiven

A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

NOT_GIVEN
order Literal['asc', 'desc'] | NotGiven

Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

retrieve async

retrieve(
    run_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Retrieves a run.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

steps

steps() -> AsyncSteps

submit_tool_outputs async

submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    tool_outputs: Iterable[ToolOutput],
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    stream: Literal[True],
    tool_outputs: Iterable[ToolOutput],
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncStream[AssistantStreamEvent]
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    stream: bool,
    tool_outputs: Iterable[ToolOutput],
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    tool_outputs: Iterable[ToolOutput],
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]

submit_tool_outputs_stream

submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandler
]
submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    event_handler: AsyncAssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandlerT
]
submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    event_handler: (
        AsyncAssistantEventHandlerT | None
    ) = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AsyncAssistantStreamManager[AsyncAssistantEventHandler]
    | AsyncAssistantStreamManager[
        AsyncAssistantEventHandlerT
    ]
)

Submit the tool outputs from a previous run and stream the run to a terminal state.

update async

update(
    run_id: str,
    *,
    thread_id: str,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Modifies a run.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> AsyncRunsWithRawResponse

with_streaming_response

with_streaming_response() -> AsyncRunsWithStreamingResponse

AsyncRunsWithRawResponse

AsyncRunsWithRawResponse(runs: AsyncRuns)

Methods:

Name Description
steps

Attributes:

Name Type Description
cancel
create
list
retrieve
submit_tool_outputs
update

cancel instance-attribute

cancel = async_to_raw_response_wrapper(cancel)

create instance-attribute

create = async_to_raw_response_wrapper(create)

list instance-attribute

list = async_to_raw_response_wrapper(list)

retrieve instance-attribute

retrieve = async_to_raw_response_wrapper(retrieve)

submit_tool_outputs instance-attribute

submit_tool_outputs = async_to_raw_response_wrapper(
    submit_tool_outputs
)

update instance-attribute

update = async_to_raw_response_wrapper(update)

steps

AsyncRunsWithStreamingResponse

AsyncRunsWithStreamingResponse(runs: AsyncRuns)

Methods:

Name Description
steps

Attributes:

Name Type Description
cancel
create
list
retrieve
submit_tool_outputs
update

cancel instance-attribute

cancel = async_to_streamed_response_wrapper(cancel)

create instance-attribute

create = async_to_streamed_response_wrapper(create)

list instance-attribute

list = async_to_streamed_response_wrapper(list)

retrieve instance-attribute

retrieve = async_to_streamed_response_wrapper(retrieve)

submit_tool_outputs instance-attribute

submit_tool_outputs = async_to_streamed_response_wrapper(
    submit_tool_outputs
)

update instance-attribute

update = async_to_streamed_response_wrapper(update)

AsyncThreads

AsyncThreads(client: AsyncOpenAI)

Methods:

Name Description
create

Create a thread.

create_and_run
create_and_run_stream

Create a thread and stream the run back

delete

Delete a thread.

messages
retrieve

Retrieves a thread.

runs
update

Modifies a thread.

with_raw_response
with_streaming_response

create async

create(
    *,
    messages: Iterable[Message] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Create a thread.

Parameters:

Name Type Description Default
messages Iterable[Message] | NotGiven

A list of messages to start the thread with.

NOT_GIVEN
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

create_and_run async

create_and_run(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
create_and_run(
    *,
    assistant_id: str,
    stream: Literal[True],
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncStream[AssistantStreamEvent]
create_and_run(
    *,
    assistant_id: str,
    stream: bool,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]
create_and_run(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | AsyncStream[AssistantStreamEvent]

create_and_run_stream

create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandler
]
create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    event_handler: AsyncAssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AsyncAssistantStreamManager[
    AsyncAssistantEventHandlerT
]
create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    event_handler: (
        AsyncAssistantEventHandlerT | None
    ) = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AsyncAssistantStreamManager[AsyncAssistantEventHandler]
    | AsyncAssistantStreamManager[
        AsyncAssistantEventHandlerT
    ]
)

Create a thread and stream the run back

delete async

delete(
    thread_id: str,
    *,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> ThreadDeleted

Delete a thread.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

messages

messages() -> AsyncMessages

retrieve async

retrieve(
    thread_id: str,
    *,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Retrieves a thread.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

runs

runs() -> AsyncRuns

update async

update(
    thread_id: str,
    *,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Modifies a thread.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> AsyncThreadsWithRawResponse

with_streaming_response

with_streaming_response() -> (
    AsyncThreadsWithStreamingResponse
)

AsyncThreadsWithRawResponse

AsyncThreadsWithRawResponse(threads: AsyncThreads)

Methods:

Name Description
messages
runs

Attributes:

Name Type Description
create
create_and_run
delete
retrieve
update

create instance-attribute

create = async_to_raw_response_wrapper(create)

create_and_run instance-attribute

create_and_run = async_to_raw_response_wrapper(
    create_and_run
)

delete instance-attribute

delete = async_to_raw_response_wrapper(delete)

retrieve instance-attribute

retrieve = async_to_raw_response_wrapper(retrieve)

update instance-attribute

update = async_to_raw_response_wrapper(update)

messages

runs

AsyncThreadsWithStreamingResponse

AsyncThreadsWithStreamingResponse(threads: AsyncThreads)

Methods:

Name Description
messages
runs

Attributes:

Name Type Description
create
create_and_run
delete
retrieve
update

create instance-attribute

create = async_to_streamed_response_wrapper(create)

create_and_run instance-attribute

create_and_run = async_to_streamed_response_wrapper(
    create_and_run
)

delete instance-attribute

delete = async_to_streamed_response_wrapper(delete)

retrieve instance-attribute

retrieve = async_to_streamed_response_wrapper(retrieve)

update instance-attribute

update = async_to_streamed_response_wrapper(update)

messages

Messages

Messages(client: OpenAI)

Methods:

Name Description
create

Create a message.

files
list

Returns a list of messages for a given thread.

retrieve

Retrieve a message.

update

Modifies a message.

with_raw_response
with_streaming_response

create

create(
    thread_id: str,
    *,
    content: str,
    role: Literal["user"],
    file_ids: List[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Create a message.

Parameters:

Name Type Description Default
content str

The content of the message.

required
role Literal['user']

The role of the entity that is creating the message. Currently only user is supported.

required
file_ids List[str] | NotGiven

A list of File IDs that the message should use. There can be a maximum of 10 files attached to a message. Useful for tools like retrieval and code_interpreter that can access and use files.

NOT_GIVEN
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

files

files() -> Files

list

list(
    thread_id: str,
    *,
    after: str | NotGiven = NOT_GIVEN,
    before: str | NotGiven = NOT_GIVEN,
    limit: int | NotGiven = NOT_GIVEN,
    order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> SyncCursorPage[Message]

Returns a list of messages for a given thread.

Parameters:

Name Type Description Default
after str | NotGiven

A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

NOT_GIVEN
before str | NotGiven

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

NOT_GIVEN
limit int | NotGiven

A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

NOT_GIVEN
order Literal['asc', 'desc'] | NotGiven

Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

retrieve

retrieve(
    message_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Retrieve a message.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

update

update(
    message_id: str,
    *,
    thread_id: str,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Message

Modifies a message.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> MessagesWithRawResponse

with_streaming_response

with_streaming_response() -> MessagesWithStreamingResponse

MessagesWithRawResponse

MessagesWithRawResponse(messages: Messages)

Methods:

Name Description
files

Attributes:

Name Type Description
create
list
retrieve
update

create instance-attribute

create = to_raw_response_wrapper(create)

list instance-attribute

list = to_raw_response_wrapper(list)

retrieve instance-attribute

retrieve = to_raw_response_wrapper(retrieve)

update instance-attribute

update = to_raw_response_wrapper(update)

files

MessagesWithStreamingResponse

MessagesWithStreamingResponse(messages: Messages)

Methods:

Name Description
files

Attributes:

Name Type Description
create
list
retrieve
update

create instance-attribute

create = to_streamed_response_wrapper(create)

list instance-attribute

list = to_streamed_response_wrapper(list)

retrieve instance-attribute

retrieve = to_streamed_response_wrapper(retrieve)

update instance-attribute

update = to_streamed_response_wrapper(update)

files

Runs

Runs(client: OpenAI)

Methods:

Name Description
cancel

Cancels a run that is in_progress.

create
create_and_stream

Create a Run stream

list

Returns a list of runs belonging to a thread.

retrieve

Retrieves a run.

steps
submit_tool_outputs
submit_tool_outputs_stream

Submit the tool outputs from a previous run and stream the run to a terminal

update

Modifies a run.

with_raw_response
with_streaming_response

cancel

cancel(
    run_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Cancels a run that is in_progress.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

create

create(
    thread_id: str,
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
create(
    thread_id: str,
    *,
    assistant_id: str,
    stream: Literal[True],
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Stream[AssistantStreamEvent]
create(
    thread_id: str,
    *,
    assistant_id: str,
    stream: bool,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]
create(
    thread_id: str,
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]

create_and_stream

create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandler]
create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    event_handler: AssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandlerT]
create_and_stream(
    *,
    assistant_id: str,
    additional_instructions: (
        Optional[str] | NotGiven
    ) = NOT_GIVEN,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    tools: (
        Optional[Iterable[AssistantToolParam]] | NotGiven
    ) = NOT_GIVEN,
    thread_id: str,
    event_handler: AssistantEventHandlerT | None = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AssistantStreamManager[AssistantEventHandler]
    | AssistantStreamManager[AssistantEventHandlerT]
)

Create a Run stream

list

list(
    thread_id: str,
    *,
    after: str | NotGiven = NOT_GIVEN,
    before: str | NotGiven = NOT_GIVEN,
    limit: int | NotGiven = NOT_GIVEN,
    order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> SyncCursorPage[Run]

Returns a list of runs belonging to a thread.

Parameters:

Name Type Description Default
after str | NotGiven

A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

NOT_GIVEN
before str | NotGiven

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

NOT_GIVEN
limit int | NotGiven

A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

NOT_GIVEN
order Literal['asc', 'desc'] | NotGiven

Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

retrieve

retrieve(
    run_id: str,
    *,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Retrieves a run.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

steps

steps() -> Steps

submit_tool_outputs

submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    tool_outputs: Iterable[ToolOutput],
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    stream: Literal[True],
    tool_outputs: Iterable[ToolOutput],
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Stream[AssistantStreamEvent]
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    stream: bool,
    tool_outputs: Iterable[ToolOutput],
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]
submit_tool_outputs(
    run_id: str,
    *,
    thread_id: str,
    tool_outputs: Iterable[ToolOutput],
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]

submit_tool_outputs_stream

submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandler]
submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    event_handler: AssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandlerT]
submit_tool_outputs_stream(
    *,
    tool_outputs: Iterable[ToolOutput],
    run_id: str,
    thread_id: str,
    event_handler: AssistantEventHandlerT | None = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AssistantStreamManager[AssistantEventHandler]
    | AssistantStreamManager[AssistantEventHandlerT]
)

Submit the tool outputs from a previous run and stream the run to a terminal state.

update

update(
    run_id: str,
    *,
    thread_id: str,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run

Modifies a run.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> RunsWithRawResponse

with_streaming_response

with_streaming_response() -> RunsWithStreamingResponse

RunsWithRawResponse

RunsWithRawResponse(runs: Runs)

Methods:

Name Description
steps

Attributes:

Name Type Description
cancel
create
list
retrieve
submit_tool_outputs
update

cancel instance-attribute

cancel = to_raw_response_wrapper(cancel)

create instance-attribute

create = to_raw_response_wrapper(create)

list instance-attribute

list = to_raw_response_wrapper(list)

retrieve instance-attribute

retrieve = to_raw_response_wrapper(retrieve)

submit_tool_outputs instance-attribute

submit_tool_outputs = to_raw_response_wrapper(
    submit_tool_outputs
)

update instance-attribute

update = to_raw_response_wrapper(update)

steps

RunsWithStreamingResponse

RunsWithStreamingResponse(runs: Runs)

Methods:

Name Description
steps

Attributes:

Name Type Description
cancel
create
list
retrieve
submit_tool_outputs
update

cancel instance-attribute

cancel = to_streamed_response_wrapper(cancel)

create instance-attribute

create = to_streamed_response_wrapper(create)

list instance-attribute

list = to_streamed_response_wrapper(list)

retrieve instance-attribute

retrieve = to_streamed_response_wrapper(retrieve)

submit_tool_outputs instance-attribute

submit_tool_outputs = to_streamed_response_wrapper(
    submit_tool_outputs
)

update instance-attribute

update = to_streamed_response_wrapper(update)

steps

Threads

Threads(client: OpenAI)

Methods:

Name Description
create

Create a thread.

create_and_run
create_and_run_stream

Create a thread and stream the run back

delete

Delete a thread.

messages
retrieve

Retrieves a thread.

runs
update

Modifies a thread.

with_raw_response
with_streaming_response

create

create(
    *,
    messages: Iterable[Message] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Create a thread.

Parameters:

Name Type Description Default
messages Iterable[Message] | NotGiven

A list of messages to start the thread with.

NOT_GIVEN
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

create_and_run

create_and_run(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run
create_and_run(
    *,
    assistant_id: str,
    stream: Literal[True],
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Stream[AssistantStreamEvent]
create_and_run(
    *,
    assistant_id: str,
    stream: bool,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]
create_and_run(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    stream: (
        Optional[Literal[False]] | Literal[True] | NotGiven
    ) = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Run | Stream[AssistantStreamEvent]

create_and_run_stream

create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandler]
create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    event_handler: AssistantEventHandlerT,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> AssistantStreamManager[AssistantEventHandlerT]
create_and_run_stream(
    *,
    assistant_id: str,
    instructions: Optional[str] | NotGiven = NOT_GIVEN,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    model: Optional[str] | NotGiven = NOT_GIVEN,
    thread: Thread | NotGiven = NOT_GIVEN,
    tools: Optional[Iterable[Tool]] | NotGiven = NOT_GIVEN,
    event_handler: AssistantEventHandlerT | None = None,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> (
    AssistantStreamManager[AssistantEventHandler]
    | AssistantStreamManager[AssistantEventHandlerT]
)

Create a thread and stream the run back

delete

delete(
    thread_id: str,
    *,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> ThreadDeleted

Delete a thread.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

messages

messages() -> Messages

retrieve

retrieve(
    thread_id: str,
    *,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Retrieves a thread.

Parameters:

Name Type Description Default
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

runs

runs() -> Runs

update

update(
    thread_id: str,
    *,
    metadata: Optional[object] | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> Thread

Modifies a thread.

Parameters:

Name Type Description Default
metadata Optional[object] | NotGiven

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.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> ThreadsWithRawResponse

with_streaming_response

with_streaming_response() -> ThreadsWithStreamingResponse

ThreadsWithRawResponse

ThreadsWithRawResponse(threads: Threads)

Methods:

Name Description
messages
runs

Attributes:

Name Type Description
create
create_and_run
delete
retrieve
update

create instance-attribute

create = to_raw_response_wrapper(create)

create_and_run instance-attribute

create_and_run = to_raw_response_wrapper(create_and_run)

delete instance-attribute

delete = to_raw_response_wrapper(delete)

retrieve instance-attribute

retrieve = to_raw_response_wrapper(retrieve)

update instance-attribute

update = to_raw_response_wrapper(update)

messages

runs

ThreadsWithStreamingResponse

ThreadsWithStreamingResponse(threads: Threads)

Methods:

Name Description
messages
runs

Attributes:

Name Type Description
create
create_and_run
delete
retrieve
update

create instance-attribute

create = to_streamed_response_wrapper(create)

create_and_run instance-attribute

create_and_run = to_streamed_response_wrapper(
    create_and_run
)

delete instance-attribute

delete = to_streamed_response_wrapper(delete)

retrieve instance-attribute

retrieve = to_streamed_response_wrapper(retrieve)

update instance-attribute

update = to_streamed_response_wrapper(update)

messages

runs