Skip to main content

DefaultClient

Struct DefaultClient 

Source
pub struct DefaultClient { /* private fields */ }
Expand description

Default client implementation backed by reqwest.

The provider is resolved at construction time from model_hint (or defaults to OpenAI). However, individual requests can override the provider when their model string contains a prefix that clearly identifies a different provider (e.g. "anthropic/claude-3" will route to Anthropic even if the client was built without a hint).

When the model prefix does not match any known provider, the construction-time provider is used as the fallback.

The provider is stored behind an Arc so it can be shared cheaply into async closures and streaming tasks that must be 'static.

Implementations§

Source§

impl DefaultClient

Source

pub fn new(config: ClientConfig, model_hint: Option<&str>) -> Result<Self>

Build a client.

model_hint guides provider auto-detection when no explicit base_url override is present in the config. For example, passing Some("groq/llama3-70b") selects the Groq provider. Pass None to default to OpenAI.

§Errors

Returns a wrapped reqwest::Error if the underlying HTTP client cannot be constructed. Header names and values are pre-validated by ClientConfigBuilder::header, so they are inserted directly here.

Trait Implementations§

Source§

impl BatchClient for DefaultClient

Available on crate features native-http or wasm-http only.
Source§

fn create_batch( &self, req: CreateBatchRequest, ) -> BoxFuture<'_, Result<BatchObject>>

Create a new batch job.
Source§

fn retrieve_batch(&self, batch_id: &str) -> BoxFuture<'_, Result<BatchObject>>

Retrieve a batch by ID.
Source§

fn list_batches( &self, query: Option<BatchListQuery>, ) -> BoxFuture<'_, Result<BatchListResponse>>

List batches, optionally filtered by query parameters.
Source§

fn cancel_batch(&self, batch_id: &str) -> BoxFuture<'_, Result<BatchObject>>

Cancel an in-progress batch.
Source§

impl Clone for DefaultClient

Source§

fn clone(&self) -> DefaultClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl FileClient for DefaultClient

Available on crate features native-http or wasm-http only.
Source§

fn create_file( &self, req: CreateFileRequest, ) -> BoxFuture<'_, Result<FileObject>>

Upload a file.
Source§

fn retrieve_file(&self, file_id: &str) -> BoxFuture<'_, Result<FileObject>>

Retrieve metadata for a file.
Source§

fn delete_file(&self, file_id: &str) -> BoxFuture<'_, Result<DeleteResponse>>

Delete a file.
Source§

fn list_files( &self, query: Option<FileListQuery>, ) -> BoxFuture<'_, Result<FileListResponse>>

List files, optionally filtered by query parameters.
Source§

fn file_content(&self, file_id: &str) -> BoxFuture<'_, Result<Bytes>>

Retrieve the raw content of a file.
Source§

impl LlmClient for DefaultClient

Available on crate features native-http or wasm-http only.
Source§

fn chat( &self, req: ChatCompletionRequest, ) -> BoxFuture<'_, Result<ChatCompletionResponse>>

Send a chat completion request.
Source§

fn chat_stream( &self, req: ChatCompletionRequest, ) -> BoxFuture<'_, Result<BoxStream<'static, Result<ChatCompletionChunk>>>>

Send a streaming chat completion request.
Source§

fn embed( &self, req: EmbeddingRequest, ) -> BoxFuture<'_, Result<EmbeddingResponse>>

Send an embedding request.
Source§

fn list_models(&self) -> BoxFuture<'_, Result<ModelsListResponse>>

List available models.
Source§

fn image_generate( &self, req: CreateImageRequest, ) -> BoxFuture<'_, Result<ImagesResponse>>

Generate an image.
Source§

fn speech(&self, req: CreateSpeechRequest) -> BoxFuture<'_, Result<Bytes>>

Generate speech audio from text.
Source§

fn transcribe( &self, req: CreateTranscriptionRequest, ) -> BoxFuture<'_, Result<TranscriptionResponse>>

Transcribe audio to text.
Source§

fn moderate( &self, req: ModerationRequest, ) -> BoxFuture<'_, Result<ModerationResponse>>

Check content against moderation policies.
Source§

fn rerank(&self, req: RerankRequest) -> BoxFuture<'_, Result<RerankResponse>>

Rerank documents by relevance to a query.
Source§

fn search(&self, req: SearchRequest) -> BoxFuture<'_, Result<SearchResponse>>

Perform a web/document search.
Source§

fn ocr(&self, req: OcrRequest) -> BoxFuture<'_, Result<OcrResponse>>

Extract text from a document via OCR.
Source§

impl LlmClientRaw for DefaultClient

Available on crate features native-http or wasm-http only.
Source§

fn chat_raw( &self, req: ChatCompletionRequest, ) -> BoxFuture<'_, Result<RawExchange<ChatCompletionResponse>>>

Send a chat completion request and return the raw exchange. Read more
Source§

fn chat_stream_raw( &self, req: ChatCompletionRequest, ) -> BoxFuture<'_, Result<RawStreamExchange<BoxStream<'static, Result<ChatCompletionChunk>>>>>

Send a streaming chat completion request and return the raw exchange. Read more
Source§

fn embed_raw( &self, req: EmbeddingRequest, ) -> BoxFuture<'_, Result<RawExchange<EmbeddingResponse>>>

Send an embedding request and return the raw exchange.
Source§

fn image_generate_raw( &self, req: CreateImageRequest, ) -> BoxFuture<'_, Result<RawExchange<ImagesResponse>>>

Generate an image and return the raw exchange.
Source§

fn transcribe_raw( &self, req: CreateTranscriptionRequest, ) -> BoxFuture<'_, Result<RawExchange<TranscriptionResponse>>>

Transcribe audio to text and return the raw exchange.
Source§

fn moderate_raw( &self, req: ModerationRequest, ) -> BoxFuture<'_, Result<RawExchange<ModerationResponse>>>

Check content against moderation policies and return the raw exchange.
Source§

fn rerank_raw( &self, req: RerankRequest, ) -> BoxFuture<'_, Result<RawExchange<RerankResponse>>>

Rerank documents by relevance to a query and return the raw exchange.
Source§

fn search_raw( &self, req: SearchRequest, ) -> BoxFuture<'_, Result<RawExchange<SearchResponse>>>

Perform a web/document search and return the raw exchange.
Source§

fn ocr_raw( &self, req: OcrRequest, ) -> BoxFuture<'_, Result<RawExchange<OcrResponse>>>

Extract text from a document via OCR and return the raw exchange.
Source§

impl ResponseClient for DefaultClient

Available on crate features native-http or wasm-http only.
Source§

fn create_response( &self, req: CreateResponseRequest, ) -> BoxFuture<'_, Result<ResponseObject>>

Create a new response.
Source§

fn retrieve_response(&self, id: &str) -> BoxFuture<'_, Result<ResponseObject>>

Retrieve a response by ID.
Source§

fn cancel_response(&self, id: &str) -> BoxFuture<'_, Result<ResponseObject>>

Cancel an in-progress response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more