ThreadsApi

Struct ThreadsApi 

Source
pub struct ThreadsApi { /* private fields */ }
Expand description

OpenAI Threads API client for managing conversation threads and messages

Implementations§

Source§

impl ThreadsApi

Source

pub fn with_base_url<S: Into<String>>(api_key: S, base_url: S) -> Result<Self>

Creates a new Threads API client with custom base URL

§Arguments
  • api_key - Your OpenAI API key
  • base_url - Custom base URL for the API
§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::with_base_url("your-api-key", "https://custom-api.example.com")?;
Source§

impl ThreadsApi

Source

pub async fn list_message_files( &self, thread_id: impl Into<String>, message_id: impl Into<String>, ) -> Result<ListMessageFilesResponse>

List files attached to a message

§Arguments
  • thread_id - The ID of the thread that contains the message
  • message_id - The ID of the message to list files for
§Returns

Returns a list of message file objects

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::new("your-api-key")?;
let files = api.list_message_files("thread_abc123", "msg_abc123").await?;
println!("Found {} files", files.data.len());
Source

pub async fn retrieve_message_file( &self, thread_id: impl Into<String>, message_id: impl Into<String>, file_id: impl Into<String>, ) -> Result<MessageFile>

Retrieve a specific file attached to a message

§Arguments
  • thread_id - The ID of the thread that contains the message
  • message_id - The ID of the message that contains the file
  • file_id - The ID of the file to retrieve
§Returns

Returns the message file object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::new("your-api-key")?;
let file = api.retrieve_message_file("thread_abc123", "msg_abc123", "file_abc123").await?;
println!("File created at: {}", file.created_at);
Source§

impl ThreadsApi

Source

pub async fn create_message( &self, thread_id: impl Into<String>, request: MessageRequest, ) -> Result<Message>

Create a message in a thread

§Arguments
  • thread_id - The ID of the thread to add the message to
  • request - The message creation request
§Returns

Returns the created message object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};
use openai_rust_sdk::models::threads::{MessageRequest, MessageRole};

let api = ThreadsApi::new("your-api-key")?;
let message_request = MessageRequest::builder()
    .role(MessageRole::User)
    .content("Hello, I need help with my account.")
    .build()?;

let message = api.create_message("thread_abc123", message_request).await?;
println!("Created message: {}", message.id);
Source

pub async fn retrieve_message( &self, thread_id: impl Into<String>, message_id: impl Into<String>, ) -> Result<Message>

Retrieve a message from a thread

§Arguments
  • thread_id - The ID of the thread that contains the message
  • message_id - The ID of the message to retrieve
§Returns

Returns the message object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::new("your-api-key")?;
let message = api.retrieve_message("thread_abc123", "msg_abc123").await?;
println!("Message content: {:?}", message.content);
Source

pub async fn modify_message( &self, thread_id: impl Into<String>, message_id: impl Into<String>, request: MessageRequest, ) -> Result<Message>

Modify a message’s metadata

§Arguments
  • thread_id - The ID of the thread that contains the message
  • message_id - The ID of the message to modify
  • request - The message modification request
§Returns

Returns the modified message object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};
use openai_rust_sdk::models::threads::{MessageRequest, MessageRole};

let api = ThreadsApi::new("your-api-key")?;
let message_request = MessageRequest::builder()
    .role(MessageRole::User)
    .content("Updated content")
    .metadata_pair("priority", "high")
    .build()?;

let message = api.modify_message("thread_abc123", "msg_abc123", message_request).await?;
println!("Modified message: {}", message.id);
Source

pub async fn list_messages( &self, thread_id: impl Into<String>, params: Option<ListMessagesParams>, ) -> Result<ListMessagesResponse>

List messages in a thread

§Arguments
  • thread_id - The ID of the thread to list messages from
  • params - Optional parameters for pagination and filtering
§Returns

Returns a list of message objects with pagination information

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};
use openai_rust_sdk::models::threads::{ListMessagesParams, SortOrder};

let api = ThreadsApi::new("your-api-key")?;
let params = ListMessagesParams::new()
    .limit(10)
    .order(SortOrder::Desc);

let messages = api.list_messages("thread_abc123", Some(params)).await?;
println!("Found {} messages", messages.data.len());
Source§

impl ThreadsApi

Source

pub async fn create_thread(&self, request: ThreadRequest) -> Result<Thread>

Create a new conversation thread

§Arguments
  • request - The thread creation request
§Returns

Returns the created thread object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};
use openai_rust_sdk::models::threads::ThreadRequest;

let api = ThreadsApi::new("your-api-key")?;
let thread_request = ThreadRequest::builder()
    .metadata_pair("purpose", "customer_support")
    .build();

let thread = api.create_thread(thread_request).await?;
println!("Created thread: {}", thread.id);
Source

pub async fn retrieve_thread( &self, thread_id: impl Into<String>, ) -> Result<Thread>

Retrieve a thread by its ID

§Arguments
  • thread_id - The ID of the thread to retrieve
§Returns

Returns the thread object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::new("your-api-key")?;
let thread = api.retrieve_thread("thread_abc123").await?;
println!("Thread metadata: {:?}", thread.metadata);
Source

pub async fn modify_thread( &self, thread_id: impl Into<String>, request: ThreadRequest, ) -> Result<Thread>

Modify a thread’s metadata

§Arguments
  • thread_id - The ID of the thread to modify
  • request - The thread modification request
§Returns

Returns the modified thread object

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};
use openai_rust_sdk::models::threads::ThreadRequest;

let api = ThreadsApi::new("your-api-key")?;
let thread_request = ThreadRequest::builder()
    .metadata_pair("status", "resolved")
    .build();

let thread = api.modify_thread("thread_abc123", thread_request).await?;
println!("Modified thread: {}", thread.id);
Source

pub async fn delete_thread( &self, thread_id: impl Into<String>, ) -> Result<DeletionStatus>

Delete a thread

§Arguments
  • thread_id - The ID of the thread to delete
§Returns

Returns the deletion status

§Example
use openai_rust_sdk::api::{threads::ThreadsApi, common::ApiClientConstructors};

let api = ThreadsApi::new("your-api-key")?;
let deleted = api.delete_thread("thread_abc123").await?;
println!("Deleted: {}", deleted.deleted);

Trait Implementations§

Source§

impl ApiClientConstructors for ThreadsApi

Source§

fn from_http_client(http_client: HttpClient) -> Self

Create a new instance with the HTTP client
Source§

fn new<S: Into<String>>(api_key: S) -> Result<Self>

Creates a new API client Read more
Source§

fn new_with_base_url<S: Into<String>>(api_key: S, base_url: S) -> Result<Self>

Creates a new API client with custom base URL Read more
Source§

impl Clone for ThreadsApi

Source§

fn clone(&self) -> ThreadsApi

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ThreadsApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,