LanguageModel

Struct LanguageModel 

Source
pub struct LanguageModel {
    pub name: String,
    pub aliases: Vec<String>,
    pub version: String,
    pub input_modalities: Vec<Modality>,
    pub output_modalities: Vec<Modality>,
    pub prompt_text_token_price: i64,
    pub prompt_image_token_price: i64,
    pub cached_prompt_token_price: i64,
    pub completion_text_token_price: i64,
    pub search_price: i64,
    pub max_prompt_length: i32,
    pub system_fingerprint: String,
}
Expand description

Information about a language model.

This struct contains comprehensive metadata about an xAI language model, including its capabilities, pricing, and technical specifications.

§Pricing Units

The pricing fields use specific units to represent fractional cents:

  • prompt_text_token_price: 1/100 USD cents per 1M tokens (e.g., 500 = $0.05 per 1M tokens)
  • prompt_image_token_price: 1/100 USD cents per 1M tokens
  • completion_text_token_price: 1/100 USD cents per 1M tokens
  • cached_prompt_token_price: USD cents per 100M tokens (e.g., 50 = $0.50 per 100M tokens)
  • search_price: 1/100 USD cents per 1M searches

Use calculate_cost to convert these to USD amounts.

§Examples

let model = client.get_model("grok-2-1212").await?;

// Check capabilities
if model.supports_multimodal() {
    println!("{} supports images!", model.name);
}

// Calculate costs
let cost = model.calculate_cost(50_000, 5_000, 0);
println!("50K prompt + 5K completion costs: ${:.4}", cost);

Fields§

§name: String

The model name used in API requests (e.g., “grok-2-1212”).

§aliases: Vec<String>

Alternative names that can be used for this model (e.g., [“grok-2-latest”]).

Aliases provide convenient shortcuts for referring to models without needing to know the specific version number.

§version: String

Version number of the model (e.g., “2.0”).

§input_modalities: Vec<Modality>

Supported input modalities.

Common combinations:

  • [Text] - Text-only model
  • [Text, Image] - Multimodal model supporting vision
§output_modalities: Vec<Modality>

Supported output modalities.

Most models output [Text], but some specialized models may support image generation or embeddings.

§prompt_text_token_price: i64

Price per million prompt text tokens in 1/100 USD cents.

Example: 500 = $0.05 per 1M tokens = $0.00005 per token

§prompt_image_token_price: i64

Price per million prompt image tokens in 1/100 USD cents.

Only applicable for multimodal models that accept images.

§cached_prompt_token_price: i64

Price per 100 million cached prompt tokens in USD cents.

Example: 50 = $0.50 per 100M tokens

Cached tokens are significantly cheaper as they’re reused from previous requests with the same prefix.

§completion_text_token_price: i64

Price per million completion text tokens in 1/100 USD cents.

Example: 1500 = $0.15 per 1M tokens = $0.00015 per token

§search_price: i64

Price per million searches in 1/100 USD cents.

Only applicable when using web search or X search tools.

§max_prompt_length: i32

Maximum context length in tokens (prompt + completion).

This represents the total number of tokens the model can process in a single request, including both input and output.

§system_fingerprint: String

Backend configuration fingerprint.

This identifier tracks the specific backend configuration used by the model, useful for debugging and reproducibility.

Implementations§

Source§

impl LanguageModel

Source

pub fn calculate_cost( &self, prompt_tokens: u32, completion_tokens: u32, cached_tokens: u32, ) -> f64

Calculate the cost (in USD) for a given number of prompt and completion tokens.

§Examples
let cost = model.calculate_cost(1000, 500, 0);
println!("Cost: ${:.4}", cost);
Source

pub fn supports_multimodal(&self) -> bool

Check if the model supports multimodal input (text + images).

Returns true if the model accepts both text and image inputs, allowing you to send image URLs alongside text prompts.

§Examples
let model = client.get_model("grok-2-vision-1212").await?;

if model.supports_multimodal() {
    println!("{} can process images!", model.name);
} else {
    println!("{} is text-only", model.name);
}

Trait Implementations§

Source§

impl Clone for LanguageModel

Source§

fn clone(&self) -> LanguageModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LanguageModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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