Skip to main content

anthropic_async/resources/
models.rs

1use crate::{
2    client::Client,
3    config::Config,
4    error::AnthropicError,
5    types::models::{Model, ModelListParams, ModelsListResponse},
6};
7
8/// API resource for the `/v1/models` endpoints
9///
10/// Provides methods to list and retrieve model information.
11pub struct Models<'c, C: Config> {
12    client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Models<'c, C> {
16    /// Creates a new Models resource
17    pub const fn new(client: &'c Client<C>) -> Self {
18        Self { client }
19    }
20
21    /// Lists all available models with optional pagination parameters.
22    ///
23    /// # Errors
24    ///
25    /// Returns an error if the API request fails or the response cannot be parsed.
26    pub async fn list(
27        &self,
28        params: &ModelListParams,
29    ) -> Result<ModelsListResponse, AnthropicError> {
30        self.client.get_with_query("/v1/models", params).await
31    }
32
33    /// Gets details for a specific model.
34    ///
35    /// # Errors
36    ///
37    /// Returns an error if the API request fails or the response cannot be parsed.
38    pub async fn get(&self, model_id: &str) -> Result<Model, AnthropicError> {
39        self.client.get(&format!("/v1/models/{model_id}")).await
40    }
41}
42
43impl<C: Config> crate::Client<C> {
44    /// Returns the Models API resource
45    #[must_use]
46    pub const fn models(&self) -> Models<'_, C> {
47        Models::new(self)
48    }
49}