Skip to main content

anthropic/types/
model.rs

1//! Model identifiers.
2//!
3//! [`Model`] is a transparent newtype around a string, so callers can pass any
4//! ID the API accepts — including future models the SDK doesn't know about
5//! yet — via [`Model::custom`]. Pre-baked constants for the current Claude
6//! family are exposed as `pub const` items below.
7
8// Each constant is named after its API ID; an extra `///` doc would just
9// repeat that. Suppress the lint at module scope.
10#![allow(missing_docs)]
11
12use std::borrow::Cow;
13use std::fmt;
14
15use serde::{Deserialize, Serialize};
16
17/// A Claude model identifier (e.g. `claude-opus-4-7`).
18///
19/// Use one of the `pub const` constants on this module for known models, or
20/// [`Model::custom`] for anything not pre-baked.
21#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
22#[serde(transparent)]
23pub struct Model(pub Cow<'static, str>);
24
25impl Model {
26    /// Wrap an arbitrary string as a model identifier.
27    pub fn custom(id: impl Into<String>) -> Self {
28        Self(Cow::Owned(id.into()))
29    }
30
31    /// The model identifier as a string slice.
32    pub fn as_str(&self) -> &str {
33        &self.0
34    }
35}
36
37impl fmt::Display for Model {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        f.write_str(&self.0)
40    }
41}
42
43impl From<&'static str> for Model {
44    fn from(s: &'static str) -> Self {
45        Self(Cow::Borrowed(s))
46    }
47}
48
49impl From<String> for Model {
50    fn from(s: String) -> Self {
51        Self(Cow::Owned(s))
52    }
53}
54
55/// Mirrors the Go SDK's `ModelClaude*` constants in `message.go`.
56/// Keep this list in sync with upstream when porting new model IDs.
57pub const CLAUDE_OPUS_4_7: Model = Model(Cow::Borrowed("claude-opus-4-7"));
58pub const CLAUDE_OPUS_4_6: Model = Model(Cow::Borrowed("claude-opus-4-6"));
59pub const CLAUDE_OPUS_4_5: Model = Model(Cow::Borrowed("claude-opus-4-5"));
60pub const CLAUDE_OPUS_4_5_20251101: Model = Model(Cow::Borrowed("claude-opus-4-5-20251101"));
61pub const CLAUDE_OPUS_4_1: Model = Model(Cow::Borrowed("claude-opus-4-1"));
62pub const CLAUDE_OPUS_4_1_20250805: Model = Model(Cow::Borrowed("claude-opus-4-1-20250805"));
63pub const CLAUDE_OPUS_4_0: Model = Model(Cow::Borrowed("claude-opus-4-0"));
64pub const CLAUDE_OPUS_4_20250514: Model = Model(Cow::Borrowed("claude-opus-4-20250514"));
65
66pub const CLAUDE_SONNET_4_6: Model = Model(Cow::Borrowed("claude-sonnet-4-6"));
67pub const CLAUDE_SONNET_4_5: Model = Model(Cow::Borrowed("claude-sonnet-4-5"));
68pub const CLAUDE_SONNET_4_5_20250929: Model = Model(Cow::Borrowed("claude-sonnet-4-5-20250929"));
69pub const CLAUDE_SONNET_4_0: Model = Model(Cow::Borrowed("claude-sonnet-4-0"));
70pub const CLAUDE_SONNET_4_20250514: Model = Model(Cow::Borrowed("claude-sonnet-4-20250514"));
71
72pub const CLAUDE_HAIKU_4_5: Model = Model(Cow::Borrowed("claude-haiku-4-5"));
73pub const CLAUDE_HAIKU_4_5_20251001: Model = Model(Cow::Borrowed("claude-haiku-4-5-20251001"));
74
75pub const CLAUDE_3_HAIKU_20240307: Model = Model(Cow::Borrowed("claude-3-haiku-20240307"));