pub struct Client { /* private fields */ }
Expand description
Main client for interacting with the Replicate API.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_token: impl Into<String>) -> Result<Self>
pub fn new(api_token: impl Into<String>) -> Result<Self>
Create a new client with the given API token.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new client using the API token from the environment.
Looks for the token in the REPLICATE_API_TOKEN
environment variable.
Sourcepub fn with_base_url(
api_token: impl Into<String>,
base_url: impl Into<String>,
) -> Result<Self>
pub fn with_base_url( api_token: impl Into<String>, base_url: impl Into<String>, ) -> Result<Self>
Create a new client with custom base URL.
Sourcepub fn predictions(&self) -> &PredictionsApi
pub fn predictions(&self) -> &PredictionsApi
Get access to the predictions API.
Sourcepub fn create_prediction(&self, version: impl Into<String>) -> PredictionBuilder
pub fn create_prediction(&self, version: impl Into<String>) -> PredictionBuilder
Create a new prediction with a fluent builder API.
§Examples
let client = Client::new("your-api-token")?;
let prediction = client
.create_prediction("stability-ai/sdxl:version-id")
.input("prompt", "A futuristic city skyline")
.input("width", 1024)
.input("height", 1024)
.send()
.await?;
println!("Prediction ID: {}", prediction.id);
Sourcepub fn run(&self, version: impl Into<String>) -> PredictionBuilder
pub fn run(&self, version: impl Into<String>) -> PredictionBuilder
Run a model and wait for completion (convenience method).
This is equivalent to creating a prediction and waiting for it to complete.
§Examples
let client = Client::new("your-api-token")?;
let result = client
.run("stability-ai/sdxl:version-id")
.input("prompt", "A futuristic city skyline")
.send_and_wait()
.await?;
println!("Result: {:?}", result.output);
Sourcepub fn http_client(&self) -> &HttpClient
pub fn http_client(&self) -> &HttpClient
Get the underlying HTTP client.
Sourcepub fn http_client_mut(&mut self) -> &mut HttpClient
pub fn http_client_mut(&mut self) -> &mut HttpClient
Get mutable access to the underlying HTTP client.
This allows configuring retry settings after client creation.
Sourcepub fn configure_retries(
&mut self,
max_retries: u32,
min_delay: Duration,
max_delay: Duration,
) -> Result<()>
pub fn configure_retries( &mut self, max_retries: u32, min_delay: Duration, max_delay: Duration, ) -> Result<()>
Configure retry settings for this client.
This is a convenience method that delegates to the HTTP client.
§Examples
let mut client = Client::new("your-api-token")?;
// Configure more aggressive retry settings
client.configure_retries(
5, // max_retries
Duration::from_millis(100), // min_delay
Duration::from_secs(60), // max_delay
)?;
Sourcepub fn configure_timeouts(
&mut self,
connect_timeout: Option<Duration>,
request_timeout: Option<Duration>,
) -> Result<()>
pub fn configure_timeouts( &mut self, connect_timeout: Option<Duration>, request_timeout: Option<Duration>, ) -> Result<()>
Configure timeout settings for this client.
This is a convenience method that delegates to the HTTP client.
§Examples
let mut client = Client::new("your-api-token")?;
// Configure custom timeouts
client.configure_timeouts(
Some(Duration::from_secs(10)), // connect_timeout
Some(Duration::from_secs(120)), // request_timeout
)?;
Sourcepub fn with_http_config(
api_token: impl Into<String>,
http_config: HttpConfig,
) -> Result<Self>
pub fn with_http_config( api_token: impl Into<String>, http_config: HttpConfig, ) -> Result<Self>
Create a new client with custom HTTP configuration.
Sourcepub fn timeout_config(&self) -> &TimeoutConfig
pub fn timeout_config(&self) -> &TimeoutConfig
Get the current timeout configuration.
Sourcepub fn http_config(&self) -> &HttpConfig
pub fn http_config(&self) -> &HttpConfig
Get the current HTTP configuration.