Skip to main content

list_models

Function list_models 

Source
pub async fn list_models(
    provider: &dyn TokenProvider,
    provider_name: &str,
) -> Result<Vec<CachedModel>>
Expand description

Lists available models from a provider API with caching.

This function fetches the list of available models from a provider’s API, with automatic caching and TTL validation. If the cache is valid, it returns cached data. Otherwise, it fetches from the API and updates the cache.

§Arguments

  • provider - Token provider for API credentials
  • provider_name - Name of the provider (e.g., “openrouter”, “gemini”)

§Returns

A vector of ModelInfo structs with available models.

§Errors

Returns an error if:

  • Provider is not found
  • API request fails
  • Response parsing fails