Skip to main content

ModelListingClient

Trait ModelListingClient 

Source
pub trait ModelListingClient {
    // Required method
    fn list_models(
        &self,
    ) -> impl Future<Output = Result<ModelList, ModelListingError>> + WasmCompatSend;
}
Expand description

A provider client with model listing capabilities.

This trait provides methods to discover and list available models from LLM providers. All models are returned in a single list.

§Type Parameters

  • ModelLister: The type that implements the actual model listing logic

§Example

use rig::client::ModelListingClient;
use rig::providers::openai::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the OpenAI client
    let openai = Client::new("your-open-ai-api-key");

    // List all available models
    let models = openai.list_models().await?;

    println!("Available models:");
    for model in models.iter() {
        println!("- {} ({})", model.display_name(), model.id);
    }

    Ok(())
}

Required Methods§

Source

fn list_models( &self, ) -> impl Future<Output = Result<ModelList, ModelListingError>> + WasmCompatSend

List all available models from the provider.

This method retrieves all available models. Providers that support pagination internally handle fetching all pages and return complete results.

§Returns

A ModelList containing all available models from the provider.

§Errors

Returns a ModelListingError if:

  • The request to the provider fails
  • Authentication fails
  • The provider returns an error response
  • The response cannot be parsed
§Example
use rig::client::ModelListingClient;
use rig::providers::openai::Client;

let openai = Client::from_env();
let models = openai.list_models().await?;

println!("Found {} models", models.len());
for model in models.iter() {
    println!("- {} ({})", model.display_name(), model.id);
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<M, Ext, H> ModelListingClient for Client<Ext, H>
where Ext: Capabilities<H, ModelListing = Capable<M>> + Clone, M: ModelLister<H, Client = Self> + Send + Sync + Clone + 'static, H: Send + Sync + Clone,