oxicode_catalog/catalog/
model.rs1use serde::{Deserialize, Serialize};
4
5use super::provider::AuthMethod;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct BuiltinModelEntry {
14 pub id: String,
16 pub name: String,
18 pub api: String,
20 pub provider: String,
22 #[serde(default)]
24 pub reasoning: bool,
25 #[serde(default)]
27 pub input: Vec<String>,
28 #[serde(default)]
30 pub cost_input: f64,
31 #[serde(default)]
33 pub cost_output: f64,
34 #[serde(default)]
36 pub cost_cache_read: f64,
37 #[serde(default)]
39 pub cost_cache_write: f64,
40 #[serde(default)]
42 pub context_window: u32,
43 #[serde(default)]
45 pub max_tokens: u32,
46 #[serde(default)]
48 pub auth_method: AuthMethod,
49 #[serde(default)]
51 pub base_url: Option<String>,
52}
53
54impl BuiltinModelEntry {
55 pub fn supports_vision(&self) -> bool {
57 self.input.iter().any(|m| m == "image" || m == "Image")
58 }
59
60 pub fn supports_reasoning(&self) -> bool {
62 self.reasoning
63 }
64
65 pub fn calculate_cost(
67 &self,
68 input_tokens: u64,
69 output_tokens: u64,
70 cache_read: u64,
71 cache_write: u64,
72 ) -> f64 {
73 let in_cost = (input_tokens as f64 / 1_000_000.0) * self.cost_input;
74 let out_cost = (output_tokens as f64 / 1_000_000.0) * self.cost_output;
75 let cr_cost = (cache_read as f64 / 1_000_000.0) * self.cost_cache_read;
76 let cw_cost = (cache_write as f64 / 1_000_000.0) * self.cost_cache_write;
77 in_cost + out_cost + cr_cost + cw_cost
78 }
79}