pub struct Client { /* private fields */ }Expand description
Asynchronous client for OpenAI-compatible APIs.
Construct with Client::new (environment variables) or
Client::builder. Cloning is cheap (shared connection pool).
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Result<Self, OpenAIError>
pub fn new() -> Result<Self, OpenAIError>
Build a client from environment variables (OPENAI_API_KEY,
OPENAI_BASE_URL, OPENAI_ORG_ID, OPENAI_PROJECT_ID).
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start configuring a client.
Sourcepub fn embeddings(&self) -> Embeddings
pub fn embeddings(&self) -> Embeddings
The embeddings resource.
Sourcepub fn moderations(&self) -> Moderations
pub fn moderations(&self) -> Moderations
The moderations resource.
Sourcepub fn completions(&self) -> Completions
pub fn completions(&self) -> Completions
The legacy completions resource.
Sourcepub fn fine_tuning(&self) -> FineTuning
pub fn fine_tuning(&self) -> FineTuning
Fine-tuning endpoints: client.fine_tuning().jobs().
Sourcepub fn vector_stores(&self) -> VectorStores
pub fn vector_stores(&self) -> VectorStores
The vector stores resource.
Sourcepub fn assistants(&self) -> Assistants
pub fn assistants(&self) -> Assistants
The assistants resource (beta v2): client.assistants().
Sourcepub fn threads(&self) -> Threads
pub fn threads(&self) -> Threads
The threads resource (beta v2): client.threads(), with nested
.messages() and .runs().
Sourcepub async fn connect_realtime(
&self,
model: &str,
) -> Result<RealtimeSession, RealtimeError>
pub async fn connect_realtime( &self, model: &str, ) -> Result<RealtimeSession, RealtimeError>
Open a realtime WebSocket session for model, using this client’s
API key, base URL, and organization/project settings.
Azure realtime (deployment paths, api-version query, api-key
header over WebSocket) is not supported; Azure-configured clients
return an error.
Source§impl Client
impl Client
Sourcepub async fn get<T: DeserializeOwned>(
&self,
path: &str,
query: &[(&str, &str)],
) -> Result<T, OpenAIError>
pub async fn get<T: DeserializeOwned>( &self, path: &str, query: &[(&str, &str)], ) -> Result<T, OpenAIError>
Escape hatch: GET an arbitrary API path with query parameters.
T may be serde_json::Value for untyped access.
Sourcepub async fn post<B: Serialize, T: DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T, OpenAIError>
pub async fn post<B: Serialize, T: DeserializeOwned>( &self, path: &str, body: &B, ) -> Result<T, OpenAIError>
Escape hatch: POST an arbitrary API path with a JSON body.
T may be serde_json::Value for untyped access.
Sourcepub async fn delete<T: DeserializeOwned>(
&self,
path: &str,
) -> Result<T, OpenAIError>
pub async fn delete<T: DeserializeOwned>( &self, path: &str, ) -> Result<T, OpenAIError>
Escape hatch: DELETE an arbitrary API path.