pub struct ApiClient { /* private fields */ }Expand description
Lightweight API HTTP client.
Implementations§
Source§impl ApiClient
impl ApiClient
pub fn with_client(token: impl Into<String>, client: Client) -> Self
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 BoxStream of parsed
ChatCompletionChunks.
The stream borrows &self via the response lifetime, so it cannot
outlive the client. Use into_stream when you
need a 'static stream (e.g. inside a state machine that owns the
client).
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 (SSE) request, consuming self, and return a
'static BoxStream of parsed ChatCompletionChunks.
Taking ownership of the client means the returned stream is not tied to
any borrow, making it suitable for storage inside a state machine (e.g.
AgentStream).
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>.