pub struct OpenAI { /* private fields */ }Expand description
The main OpenAI client.
See OpenAI API docs for the full API reference.
Use with_options() to create a cheap clone with
per-request customization (extra headers, query params, timeout):
ⓘ
use openai_oxide::RequestOptions;
use std::time::Duration;
let custom = client.with_options(
RequestOptions::new()
.header("X-Custom", "value")
.timeout(Duration::from_secs(30))
);Implementations§
Source§impl OpenAI
impl OpenAI
Sourcepub fn with_config<C: Config + 'static>(config: C) -> Self
pub fn with_config<C: Config + 'static>(config: C) -> Self
Create a client from a full config.
Sourcepub fn with_options(&self, options: RequestOptions) -> Self
pub fn with_options(&self, options: RequestOptions) -> Self
Create a cheap clone of this client with additional request options.
The returned client shares the same HTTP connection pool (reqwest::Client
uses Arc internally) but applies the merged options to every request.
ⓘ
use openai_oxide::RequestOptions;
let custom = client.with_options(
RequestOptions::new().header("X-Custom", "value")
);
// All requests through `custom` will include the X-Custom header.
let resp = custom.chat().completions().create(req).await?;Sourcepub fn from_env() -> Result<Self, OpenAIError>
pub fn from_env() -> Result<Self, OpenAIError>
Create a client using the OPENAI_API_KEY environment variable.
Sourcepub fn azure(config: AzureConfig) -> Result<Self, OpenAIError>
pub fn azure(config: AzureConfig) -> Result<Self, OpenAIError>
Sourcepub fn beta(&self) -> Beta<'_>
pub fn beta(&self) -> Beta<'_>
Access the Beta resources (Assistants, Threads, Runs, Vector Stores).
Sourcepub fn fine_tuning(&self) -> FineTuning<'_>
pub fn fine_tuning(&self) -> FineTuning<'_>
Access the Fine-tuning resource.
Sourcepub fn moderations(&self) -> Moderations<'_>
pub fn moderations(&self) -> Moderations<'_>
Access the Moderations resource.
Sourcepub fn embeddings(&self) -> Embeddings<'_>
pub fn embeddings(&self) -> Embeddings<'_>
Access the Embeddings resource.
Sourcepub fn conversations(&self) -> Conversations<'_>
pub fn conversations(&self) -> Conversations<'_>
Access conversation endpoints (multi-turn server-side state).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OpenAI
impl !RefUnwindSafe for OpenAI
impl Send for OpenAI
impl Sync for OpenAI
impl Unpin for OpenAI
impl UnsafeUnpin for OpenAI
impl !UnwindSafe for OpenAI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more