pub struct ModelsResource<'a> { /* private fields */ }
Expand description
Resource for managing models
Implementations§
Source§impl<'a> ModelsResource<'a>
impl<'a> ModelsResource<'a>
Sourcepub async fn list(&self, params: Option<ModelListParams>) -> Result<ModelList>
pub async fn list(&self, params: Option<ModelListParams>) -> Result<ModelList>
List all available models with pagination support
§Arguments
params
- Optional pagination parameters
§Example
use anthropic_sdk::{Anthropic, ModelListParams};
let client = Anthropic::from_env()?;
// List all models
let models = client.models().list(None).await?;
println!("Found {} models", models.data.len());
// List with pagination
let params = ModelListParams::new().limit(10);
let models = client.models().list(Some(params)).await?;
Sourcepub async fn get(&self, model_id: &str) -> Result<ModelObject>
pub async fn get(&self, model_id: &str) -> Result<ModelObject>
Get a specific model by ID or alias
§Arguments
model_id
- Model identifier or alias (e.g., “claude-3-5-sonnet-latest”)
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
// Get specific model
let model = client.models().get("claude-3-5-sonnet-latest").await?;
println!("Model: {} ({})", model.display_name, model.id);
Sourcepub async fn list_by_family(&self, family: &str) -> Result<Vec<ModelObject>>
pub async fn list_by_family(&self, family: &str) -> Result<Vec<ModelObject>>
List models by family (e.g., “claude-3”, “claude-3-5”)
§Arguments
family
- Model family to filter by
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let claude35_models = client.models().list_by_family("claude-3-5").await?;
println!("Found {} Claude 3.5 models", claude35_models.len());
Sourcepub async fn get_capabilities(
&self,
model_id: &str,
) -> Result<ModelCapabilities>
pub async fn get_capabilities( &self, model_id: &str, ) -> Result<ModelCapabilities>
Get model capabilities and limitations
Note: This method provides enhanced capabilities based on known model information. The actual API may not return all these details.
§Arguments
model_id
- Model identifier
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let capabilities = client.models().get_capabilities("claude-3-5-sonnet-latest").await?;
println!("Max context: {} tokens", capabilities.max_context_length);
println!("Supports vision: {}", capabilities.supports_vision);
Sourcepub async fn get_pricing(&self, model_id: &str) -> Result<ModelPricing>
pub async fn get_pricing(&self, model_id: &str) -> Result<ModelPricing>
Get current pricing information for a model
Note: This method provides estimated pricing based on known information. Actual pricing may vary and should be verified with official documentation.
§Arguments
model_id
- Model identifier
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let pricing = client.models().get_pricing("claude-3-5-sonnet-latest").await?;
println!("Input: ${:.3}/1M tokens", pricing.input_price_per_million);
println!("Output: ${:.3}/1M tokens", pricing.output_price_per_million);
Sourcepub async fn find_best_model(
&self,
requirements: &ModelRequirements,
) -> Result<ModelObject>
pub async fn find_best_model( &self, requirements: &ModelRequirements, ) -> Result<ModelObject>
Find the best model based on requirements
§Arguments
requirements
- Model requirements and preferences
§Example
use anthropic_sdk::{Anthropic, ModelRequirements, ModelCapability};
let client = Anthropic::from_env()?;
let requirements = ModelRequirements::new()
.max_input_cost_per_token(0.01)
.min_context_length(100000)
.require_capability(ModelCapability::Vision);
let best_model = client.models().find_best_model(&requirements).await?;
println!("Best model: {}", best_model.display_name);
Sourcepub async fn compare_models(
&self,
model_ids: &[&str],
) -> Result<ModelComparison>
pub async fn compare_models( &self, model_ids: &[&str], ) -> Result<ModelComparison>
Compare multiple models side by side
§Arguments
model_ids
- List of model identifiers to compare
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let comparison = client.models().compare_models(&[
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest"
]).await?;
println!("Fastest: {}", comparison.summary.fastest_model);
println!("Best quality: {}", comparison.summary.highest_quality_model);
Sourcepub async fn estimate_cost(
&self,
model_id: &str,
input_tokens: u64,
output_tokens: u64,
) -> Result<CostEstimation>
pub async fn estimate_cost( &self, model_id: &str, input_tokens: u64, output_tokens: u64, ) -> Result<CostEstimation>
Estimate cost for specific usage patterns
§Arguments
model_id
- Model identifierinput_tokens
- Expected input tokensoutput_tokens
- Expected output tokens
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let cost = client.models().estimate_cost("claude-3-5-sonnet-latest", 1000, 500).await?;
println!("Estimated cost: ${:.4}", cost.final_cost_usd);
println!("Cost per 1K tokens: ${:.4}", cost.cost_per_1k_tokens());
Sourcepub async fn get_recommendations(
&self,
use_case: &str,
) -> Result<ModelUsageRecommendations>
pub async fn get_recommendations( &self, use_case: &str, ) -> Result<ModelUsageRecommendations>
Get usage recommendations for specific use cases
§Arguments
use_case
- Use case category (e.g., “code-generation”, “creative-writing”)
§Example
use anthropic_sdk::Anthropic;
let client = Anthropic::from_env()?;
let recommendations = client.models().get_recommendations("code-generation").await?;
for rec in &recommendations.recommended_models {
println!("Recommended: {} - {}", rec.model_id, rec.reason);
}
Auto Trait Implementations§
impl<'a> Freeze for ModelsResource<'a>
impl<'a> !RefUnwindSafe for ModelsResource<'a>
impl<'a> Send for ModelsResource<'a>
impl<'a> Sync for ModelsResource<'a>
impl<'a> Unpin for ModelsResource<'a>
impl<'a> !UnwindSafe for ModelsResource<'a>
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
Mutably borrows from an owned value. Read more