Struct ModelsResource

Source
pub struct ModelsResource<'a> { /* private fields */ }
Expand description

Resource for managing models

Implementations§

Source§

impl<'a> ModelsResource<'a>

Source

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?;
Source

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);
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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 identifier
  • input_tokens - Expected input tokens
  • output_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());
Source

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> 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> 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> 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, 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,