TripoClient

Struct TripoClient 

Source
pub struct TripoClient {
    pub s3_endpoint_override: Option<String>,
    /* private fields */
}
Expand description

The main client for interacting with the Tripo3D API.

It holds the shared reqwest::Client and the base URL for all API requests. It is designed to be cloneable and safe to share across threads.

Fields§

§s3_endpoint_override: Option<String>

(For testing) Overrides the S3 endpoint to allow mocking S3 uploads.

Implementations§

Source§

impl TripoClient

Source

pub fn new(api_key: Option<String>) -> Result<Self, TripoError>

Creates a new TripoClient.

This method initializes the client with an API key. It first checks for the api_key parameter. If it’s None, it falls back to the TRIPO_API_KEY environment variable.

§Arguments
  • api_key - An Option<String> containing the API key.
§Errors

Returns TripoError::MissingApiKey if the API key is not provided either via the parameter or the environment variable.

§Example
// Create a client using a provided API key
let client_from_key = TripoClient::new(Some("your_api_key_here".to_string()));

// Or create a client using the TRIPO_API_KEY environment variable
// (ensure it's set in your environment)
let client_from_env = TripoClient::new(None);
Source

pub fn new_with_url(api_key: String, base_url: &str) -> Result<Self, TripoError>

Creates a new TripoClient with a custom base URL.

This is useful for testing or for connecting to a different API endpoint.

§Arguments
  • api_key - The API key for authentication.
  • base_url - The base URL for the API (e.g., for a mock server).
§Errors

This function can return an error if the internal HTTP client fails to build or if the provided base_url is invalid.

Source

pub async fn text_to_model( &self, prompt: &str, ) -> Result<TaskResponse, TripoError>

Submits a new text-to-model generation task.

§Arguments
  • prompt - A text description of the 3D model to generate.
§Returns

On success, a TaskResponse containing the ID of the newly created task.

§Errors

Returns a TripoError if the API request fails.

Source

pub async fn upload_file_s3<P: AsRef<Path>>( &self, image_path: P, ) -> Result<FileContent, TripoError>

Uploads a file to a temporary S3 location using STS credentials.

This method replicates a secondary upload mechanism from the official Python SDK. It first requests temporary STS credentials from the Tripo API, then uses those credentials to upload the specified file directly to an S3 bucket.

Note: This is generally not the primary method for file uploads. upload_file is preferred for most use cases.

§Arguments
  • image_path - The path to the local image file to upload.
§Returns

On success, a FileContent struct containing the S3 object details.

§Errors

Returns a TripoError if fetching STS tokens, reading the file, or uploading to S3 fails.

Source

pub async fn upload_file<P: AsRef<Path>>( &self, image_path: P, ) -> Result<String, TripoError>

Uploads a file using the standard multipart method to get a file token.

This is the primary and recommended method for uploading files. It sends the file directly to the Tripo API as a multipart/form-data request and receives a file_token in return, which can then be used in other API calls.

§Arguments
  • image_path - The path to the local image file to upload.
§Returns

On success, a file_token as a String.

§Errors

Returns a TripoError if the file cannot be read or if the API request fails.

Source

pub async fn image_to_model( &self, image: &str, ) -> Result<TaskResponse, TripoError>

Submits a new image-to-model generation task.

The image parameter is flexible and accepts one of three input types:

  1. A public URL string starting with http:// or https://.
  2. A file token (as a UUID string) obtained from a previous upload.
  3. A path to a local file, which will be uploaded automatically.
§Arguments
  • image - A string representing the image input (URL, file token, or local path).
§Returns

On success, a TaskResponse containing the ID of the newly created task.

§Errors

Returns a TripoError if the input string is a file path that doesn’t exist, if the file upload fails, or if the final API request fails.

Source

pub async fn get_task(&self, task_id: &str) -> Result<TaskStatus, TripoError>

Retrieves the status of a specific task.

This is the primary method for polling the status of a long-running generation task.

§Arguments
  • task_id - The unique identifier of the task to query.
§Returns

On success, a TaskStatus struct with the latest status of the task.

§Errors

Returns a TripoError if the API request fails.

Source

pub async fn get_balance(&self) -> Result<Balance, TripoError>

Queries the user’s current account balance.

§Returns

On success, a Balance struct containing the user’s balance information.

§Errors

Returns a TripoError if the API request fails.

Source

pub async fn wait_for_task( &self, task_id: &str, verbose: bool, ) -> Result<TaskStatus, TripoError>

Waits for a task to complete by polling its status.

This method repeatedly calls get_task until the task status is either Success or Failed.

§Arguments
  • task_id - The ID of the task to wait for.
  • verbose - If true, prints the task progress to the console.
§Returns

On success, the final TaskStatus of the completed or failed task.

§Errors

Returns a TripoError if polling fails at any point.

§Example
let final_status = client.wait_for_task(task_id, true).await?;
println!("Task finished with status: {:?}", final_status.status);
Source

pub async fn download_model<P: AsRef<Path>>( &self, model_file: &ResultFile, dest_dir: P, ) -> Result<PathBuf, TripoError>

Downloads a single model file to a specified directory.

This function handles the HTTP request to the model’s URL and saves the content to a local file. The filename is inferred from the URL.

§Arguments
  • model_file - A reference to a ResultFile struct containing the download URL.
  • dest_dir - The local directory path where the file will be saved.
§Returns

A Result containing the PathBuf of the newly created file.

§Errors

Returns a TripoError if the download fails, the destination directory or file cannot be created, or there’s an issue writing the file to disk.

Source

pub async fn download_all_models<P: AsRef<Path>>( &self, task_status: &TaskStatus, dest_dir: P, ) -> Result<Vec<PathBuf>, TripoError>

Downloads all models from a completed task to a specified directory.

This is a convenience method that iterates over the results in a TaskStatus and downloads each available model file.

§Arguments
  • task_status - The completed TaskStatus containing the models to download.
  • dest_dir - The directory where the models will be saved.
§Returns

A Vec containing the PathBuf of each downloaded file.

§Errors

Returns a TripoError if any of the model downloads fail.

Trait Implementations§

Source§

impl Clone for TripoClient

Source§

fn clone(&self) -> TripoClient

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,