pub struct HFClientBuilder { /* private fields */ }Expand description
Builder for HFClient.
Get one via HFClient::builder() or HFClientBuilder::new().
Call build() when all options are set.
Implementations§
Source§impl HFClientBuilder
impl HFClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a builder with all options unset; defaults are applied at build time.
Sourcepub fn endpoint(self, endpoint: impl Into<String>) -> Self
pub fn endpoint(self, endpoint: impl Into<String>) -> Self
Overrides the Hub base URL (default: https://huggingface.co, or HF_ENDPOINT env var).
Sourcepub fn token(self, token: impl Into<String>) -> Self
pub fn token(self, token: impl Into<String>) -> Self
Sets the authentication token. Without this, the client falls back to the HF_TOKEN env
var and the cached token file written by huggingface-cli login.
Sourcepub fn user_agent(self, user_agent: impl Into<String>) -> Self
pub fn user_agent(self, user_agent: impl Into<String>) -> Self
Overrides the User-Agent header sent with every request.
Sourcepub fn headers(self, headers: HeaderMap) -> Self
pub fn headers(self, headers: HeaderMap) -> Self
Merges additional default headers into every request. Ignored when a custom
client is supplied (configure headers on that client directly).
Sourcepub fn client(self, client: Client) -> Self
pub fn client(self, client: Client) -> Self
Supplies a pre-configured reqwest::Client. Retry middleware is still applied on top.
The caller is responsible for any default headers (including User-Agent) on this client;
the headers and user_agent options are ignored.
Sourcepub fn cache_dir(self, path: impl Into<PathBuf>) -> Self
pub fn cache_dir(self, path: impl Into<PathBuf>) -> Self
Sets the local cache directory. Defaults to HF_HUB_CACHE → $HF_HOME/hub →
~/.cache/huggingface/hub.
Sourcepub fn cache_enabled(self, enabled: bool) -> Self
pub fn cache_enabled(self, enabled: bool) -> Self
Enables or disables the local file cache. Caching is on by default.
Sourcepub fn retry_max_attempts(self, n: usize) -> Self
pub fn retry_max_attempts(self, n: usize) -> Self
Overrides the maximum number of retry attempts after an initial failure (default: 3).
Sourcepub fn retry_base_delay(self, delay: Duration) -> Self
pub fn retry_base_delay(self, delay: Duration) -> Self
Overrides the base delay for exponential backoff between retries (default: 100ms).
Sourcepub fn build_sync(self) -> HFResult<HFClientSync>
Available on crate feature blocking only.
pub fn build_sync(self) -> HFResult<HFClientSync>
blocking only.Builds the crate::blocking::HFClientSync.
Requires the blocking feature and is equivalent to calling
build and then HFClientSync::from_inner.
§Errors
Returns an error if the endpoint URL is not a valid URL, if the reqwest client
cannot be constructed (e.g., an invalid User-Agent string was provided), or if the
tokio runtime handle could not be correctly created for the blocking client.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for HFClientBuilder
impl !UnwindSafe for HFClientBuilder
impl Freeze for HFClientBuilder
impl Send for HFClientBuilder
impl Sync for HFClientBuilder
impl Unpin for HFClientBuilder
impl UnsafeUnpin for HFClientBuilder
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
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more