pub struct ThreadsApi { /* private fields */ }Expand description
OpenAI Threads API client for managing conversation threads and messages
Implementations§
Source§impl ThreadsApi
impl ThreadsApi
Sourcepub fn with_base_url<S: Into<String>>(api_key: S, base_url: S) -> Result<Self>
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- YourOpenAIAPI keybase_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
impl ThreadsApi
Sourcepub async fn list_message_files(
&self,
thread_id: impl Into<String>,
message_id: impl Into<String>,
) -> Result<ListMessageFilesResponse>
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 messagemessage_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());Sourcepub async fn retrieve_message_file(
&self,
thread_id: impl Into<String>,
message_id: impl Into<String>,
file_id: impl Into<String>,
) -> Result<MessageFile>
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 messagemessage_id- The ID of the message that contains the filefile_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
impl ThreadsApi
Sourcepub async fn create_message(
&self,
thread_id: impl Into<String>,
request: MessageRequest,
) -> Result<Message>
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 torequest- 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);Sourcepub async fn retrieve_message(
&self,
thread_id: impl Into<String>,
message_id: impl Into<String>,
) -> Result<Message>
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 messagemessage_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);Sourcepub async fn modify_message(
&self,
thread_id: impl Into<String>,
message_id: impl Into<String>,
request: MessageRequest,
) -> Result<Message>
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 messagemessage_id- The ID of the message to modifyrequest- 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);Sourcepub async fn list_messages(
&self,
thread_id: impl Into<String>,
params: Option<ListMessagesParams>,
) -> Result<ListMessagesResponse>
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 fromparams- 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
impl ThreadsApi
Sourcepub async fn create_thread(&self, request: ThreadRequest) -> Result<Thread>
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);Sourcepub async fn retrieve_thread(
&self,
thread_id: impl Into<String>,
) -> Result<Thread>
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);Sourcepub async fn modify_thread(
&self,
thread_id: impl Into<String>,
request: ThreadRequest,
) -> Result<Thread>
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 modifyrequest- 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);Sourcepub async fn delete_thread(
&self,
thread_id: impl Into<String>,
) -> Result<DeletionStatus>
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
impl ApiClientConstructors for ThreadsApi
Source§fn from_http_client(http_client: HttpClient) -> Self
fn from_http_client(http_client: HttpClient) -> Self
Source§impl Clone for ThreadsApi
impl Clone for ThreadsApi
Source§fn clone(&self) -> ThreadsApi
fn clone(&self) -> ThreadsApi
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more