pub enum TokenModel {
Show 27 variants
Gpt52,
Gpt52Pro,
Gpt51,
Gpt51Mini,
Gpt51Codex,
Gpt5,
Gpt5Mini,
Gpt5Nano,
O4Mini,
O3,
O3Mini,
O1,
O1Mini,
O1Preview,
Gpt4o,
Gpt4oMini,
Gpt4,
Gpt35Turbo,
Claude,
Gemini,
Llama,
CodeLlama,
Mistral,
DeepSeek,
Qwen,
Cohere,
Grok,
}Expand description
Supported LLM models for token counting
Models are grouped by their tokenizer encoding family. Use TokenModel::from_model_name
to parse user-friendly model names like “gpt-5.2”, “o3”, “claude-sonnet”, etc.
Variants§
Gpt52
GPT-5.2 - Latest flagship model (Dec 2025), uses o200k_base
Gpt52Pro
GPT-5.2 Pro - Enhanced GPT-5.2 variant, uses o200k_base
Gpt51
GPT-5.1 - Previous flagship (Nov 2025), uses o200k_base
Gpt51Mini
GPT-5.1 Mini - Smaller GPT-5.1 variant, uses o200k_base
Gpt51Codex
GPT-5.1 Codex - Code-specialized variant, uses o200k_base
Gpt5
GPT-5 - Original GPT-5 (Aug 2025), uses o200k_base
Gpt5Mini
GPT-5 Mini - Smaller GPT-5 variant, uses o200k_base
Gpt5Nano
GPT-5 Nano - Smallest GPT-5 variant, uses o200k_base
O4Mini
O4 Mini - Latest reasoning model, uses o200k_base
O3
O3 - Reasoning model, uses o200k_base
O3Mini
O3 Mini - Smaller O3 variant, uses o200k_base
O1
O1 - Original reasoning model, uses o200k_base
O1Mini
O1 Mini - Smaller O1 variant, uses o200k_base
O1Preview
O1 Preview - O1 preview version, uses o200k_base
Gpt4o
GPT-4o - Omni model, uses o200k_base encoding (most efficient)
Gpt4oMini
GPT-4o Mini - Smaller GPT-4o variant, uses o200k_base encoding
Gpt4
GPT-4/GPT-4 Turbo - uses cl100k_base encoding (legacy)
Gpt35Turbo
GPT-3.5-turbo - uses cl100k_base encoding (legacy)
Claude
Claude (all versions) - uses estimation based on ~3.5 chars/token
Gemini
Gemini (all versions including 3, 2.5, 1.5) - estimation ~3.8 chars/token
Llama
Llama 3/4 - estimation based on ~3.5 chars/token
CodeLlama
CodeLlama - more granular for code (~3.2 chars/token)
Mistral
Mistral (Large, Medium, Small, Codestral) - estimation ~3.5 chars/token
DeepSeek
DeepSeek (V3, R1, Coder) - estimation ~3.5 chars/token
Qwen
Qwen (Qwen3, Qwen2.5) - estimation ~3.5 chars/token
Cohere
Cohere (Command R+, Command R) - estimation ~3.6 chars/token
Grok
Grok (Grok 2, Grok 3) - estimation ~3.5 chars/token
Implementations§
Source§impl TokenModel
impl TokenModel
Sourcepub fn chars_per_token(&self) -> f32
pub fn chars_per_token(&self) -> f32
Get average characters per token (for estimation fallback)
Sourcepub fn has_exact_tokenizer(&self) -> bool
pub fn has_exact_tokenizer(&self) -> bool
Whether this model has an exact tokenizer available (via tiktoken)
Sourcepub fn uses_o200k(&self) -> bool
pub fn uses_o200k(&self) -> bool
Whether this model uses the o200k_base encoding
Sourcepub fn uses_cl100k(&self) -> bool
pub fn uses_cl100k(&self) -> bool
Whether this model uses the cl100k_base encoding (legacy)
Sourcepub fn from_model_name(name: &str) -> Option<Self>
pub fn from_model_name(name: &str) -> Option<Self>
Parse a model name string into a TokenModel
Supports various formats:
- OpenAI: “gpt-5.2”, “gpt-5.2-pro”, “gpt-5.1”, “gpt-5”, “o3”, “o1”, “gpt-4o”, etc.
- Claude: “claude”, “claude-3”, “claude-4”, “claude-opus”, “claude-sonnet”, “claude-haiku”
- Gemini: “gemini”, “gemini-pro”, “gemini-flash”, “gemini-2.5”, “gemini-3”
- Llama: “llama”, “llama-3”, “llama-4”, “codellama”
- Others: “mistral”, “deepseek”, “qwen”, “cohere”, “grok”
§Examples
use infiniloom_engine::tokenizer::TokenModel;
assert_eq!(TokenModel::from_model_name("gpt-5.2"), Some(TokenModel::Gpt52));
assert_eq!(TokenModel::from_model_name("o3"), Some(TokenModel::O3));
assert_eq!(TokenModel::from_model_name("claude-sonnet"), Some(TokenModel::Claude));
assert_eq!(TokenModel::from_model_name("unknown-model"), None);Trait Implementations§
Source§impl Clone for TokenModel
impl Clone for TokenModel
Source§fn clone(&self) -> TokenModel
fn clone(&self) -> TokenModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenModel
impl Debug for TokenModel
Source§impl<'de> Deserialize<'de> for TokenModel
impl<'de> Deserialize<'de> for TokenModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Hash for TokenModel
impl Hash for TokenModel
Source§impl PartialEq for TokenModel
impl PartialEq for TokenModel
Source§impl Serialize for TokenModel
impl Serialize for TokenModel
impl Copy for TokenModel
impl Eq for TokenModel
impl StructuralPartialEq for TokenModel
Auto Trait Implementations§
impl Freeze for TokenModel
impl RefUnwindSafe for TokenModel
impl Send for TokenModel
impl Sync for TokenModel
impl Unpin for TokenModel
impl UnwindSafe for TokenModel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);