pub struct HttpClient { /* private fields */ }Expand description
Common HTTP client for all OpenAI API operations
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new<S: Into<String>>(api_key: S) -> Result<Self>
pub fn new<S: Into<String>>(api_key: S) -> Result<Self>
Create a new HTTP client with the given API key
Sourcepub fn new_with_base_url<S: Into<String>>(
api_key: S,
base_url: S,
) -> Result<Self>
pub fn new_with_base_url<S: Into<String>>( api_key: S, base_url: S, ) -> Result<Self>
Create a new HTTP client with custom base URL
Sourcepub fn build_headers(&self) -> Result<HeaderMap>
pub fn build_headers(&self) -> Result<HeaderMap>
Build standard headers for API requests
Sourcepub fn build_auth_headers(&self) -> Result<HeaderMap>
pub fn build_auth_headers(&self) -> Result<HeaderMap>
Build headers without Content-Type (for multipart requests)
Sourcepub fn build_headers_with_beta(&self) -> Result<HeaderMap>
pub fn build_headers_with_beta(&self) -> Result<HeaderMap>
Build headers with additional OpenAI-Beta header for assistant APIs
Sourcepub fn build_simple_url(&self, path: &str) -> String
pub fn build_simple_url(&self, path: &str) -> String
Build a URL from the base URL and path
Source§impl HttpClient
impl HttpClient
Sourcepub async fn get_with_query<T>(
&self,
path: &str,
query_params: &[(String, String)],
) -> Result<T>where
T: DeserializeOwned,
pub async fn get_with_query<T>(
&self,
path: &str,
query_params: &[(String, String)],
) -> Result<T>where
T: DeserializeOwned,
Make a GET request with query parameters
Sourcepub async fn get_with_query_and_beta<T>(
&self,
path: &str,
query_params: &[(String, String)],
) -> Result<T>where
T: DeserializeOwned,
pub async fn get_with_query_and_beta<T>(
&self,
path: &str,
query_params: &[(String, String)],
) -> Result<T>where
T: DeserializeOwned,
Make a GET request with query parameters and beta headers
Sourcepub async fn post_multipart<T>(&self, path: &str, form: Form) -> Result<T>where
T: DeserializeOwned,
pub async fn post_multipart<T>(&self, path: &str, form: Form) -> Result<T>where
T: DeserializeOwned,
Make a POST request with multipart form data
Source§impl HttpClient
impl HttpClient
Sourcepub async fn get<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
pub async fn get<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
Make a GET request to the specified path
Sourcepub async fn get_with_beta<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
pub async fn get_with_beta<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
Make a GET request with beta headers to the specified path
Sourcepub async fn post<T, B>(&self, path: &str, body: &B) -> Result<T>where
T: DeserializeOwned,
B: Serialize,
pub async fn post<T, B>(&self, path: &str, body: &B) -> Result<T>where
T: DeserializeOwned,
B: Serialize,
Make a POST request with JSON body to the specified path
Sourcepub async fn post_with_beta<T, B>(&self, path: &str, body: &B) -> Result<T>where
T: DeserializeOwned,
B: Serialize,
pub async fn post_with_beta<T, B>(&self, path: &str, body: &B) -> Result<T>where
T: DeserializeOwned,
B: Serialize,
Make a POST request with JSON body and beta headers to the specified path
Sourcepub async fn delete<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
pub async fn delete<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
Make a DELETE request to the specified path
Sourcepub async fn delete_with_beta<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
pub async fn delete_with_beta<T>(&self, path: &str) -> Result<T>where
T: DeserializeOwned,
Make a DELETE request with beta headers to the specified path
Source§impl HttpClient
impl HttpClient
Sourcepub async fn handle_response<T>(&self, response: Response) -> Result<T>where
T: DeserializeOwned,
pub async fn handle_response<T>(&self, response: Response) -> Result<T>where
T: DeserializeOwned,
Handle API response and convert to the desired type
Sourcepub async fn get_text(&self, path: &str) -> Result<String>
pub async fn get_text(&self, path: &str) -> Result<String>
Make a GET request and return raw text content
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more