use serde::{Deserialize, Serialize};
use super::provider::AuthMethod;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuiltinModelEntry {
pub id: String,
pub name: String,
pub api: String,
pub provider: String,
#[serde(default)]
pub reasoning: bool,
#[serde(default)]
pub input: Vec<String>,
#[serde(default)]
pub cost_input: f64,
#[serde(default)]
pub cost_output: f64,
#[serde(default)]
pub cost_cache_read: f64,
#[serde(default)]
pub cost_cache_write: f64,
#[serde(default)]
pub context_window: u32,
#[serde(default)]
pub max_tokens: u32,
#[serde(default)]
pub auth_method: AuthMethod,
#[serde(default)]
pub base_url: Option<String>,
}
impl BuiltinModelEntry {
pub fn supports_vision(&self) -> bool {
self.input.iter().any(|m| m == "image" || m == "Image")
}
pub fn supports_reasoning(&self) -> bool {
self.reasoning
}
pub fn calculate_cost(
&self,
input_tokens: u64,
output_tokens: u64,
cache_read: u64,
cache_write: u64,
) -> f64 {
let in_cost = (input_tokens as f64 / 1_000_000.0) * self.cost_input;
let out_cost = (output_tokens as f64 / 1_000_000.0) * self.cost_output;
let cr_cost = (cache_read as f64 / 1_000_000.0) * self.cost_cache_read;
let cw_cost = (cache_write as f64 / 1_000_000.0) * self.cost_cache_write;
in_cost + out_cost + cr_cost + cw_cost
}
}