pub struct ApiClient { /* private fields */ }Expand description
Lightweight API HTTP client.
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn with_base_url(self, base: impl Into<String>) -> Self
pub fn with_base_url(self, base: impl Into<String>) -> Self
Replace base URL (builder style).
Sourcepub fn with_token(self, token: impl Into<String>) -> Self
pub fn with_token(self, token: impl Into<String>) -> Self
Replace token (builder style).
Sourcepub fn with_timeout(self, t: Duration) -> Self
pub fn with_timeout(self, t: Duration) -> Self
Set optional timeout for non-streaming requests.
Sourcepub async fn send(&self, req: ApiRequest) -> Result<ChatCompletionResponse>
pub async fn send(&self, req: ApiRequest) -> Result<ChatCompletionResponse>
Send a non-streaming request and parse the full ChatCompletionResponse.
Sourcepub async fn send_stream(
&self,
req: ApiRequest,
) -> Result<BoxStream<'_, Result<ChatCompletionChunk, ApiError>>>
pub async fn send_stream( &self, req: ApiRequest, ) -> Result<BoxStream<'_, Result<ChatCompletionChunk, ApiError>>>
Send a streaming (SSE) request and return a boxed pinned stream of parsed ChatCompletionChunk.
Sourcepub async fn into_stream(
self,
req: ApiRequest,
) -> Result<BoxStream<'static, Result<ChatCompletionChunk, ApiError>>>
pub async fn into_stream( self, req: ApiRequest, ) -> Result<BoxStream<'static, Result<ChatCompletionChunk, ApiError>>>
Send a streaming request consuming self, returning a 'static BoxStream.
Unlike send_stream, this takes ownership so the returned stream is not tied
to a client lifetime — useful when the stream must outlive the client reference
(e.g. storing it inside a state machine).
Sourcepub async fn stream_text(
&self,
req: ApiRequest,
) -> Result<BoxStream<'_, Result<String, ApiError>>>
pub async fn stream_text( &self, req: ApiRequest, ) -> Result<BoxStream<'_, Result<String, ApiError>>>
Convenience: stream only text fragments (delta.content) as String items.
Each yielded item is Result<String, ApiError>.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl UnsafeUnpin for ApiClient
impl !UnwindSafe for ApiClient
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