ai_lib/provider/
pricing.rs

1//! Provider/model pricing table (indicative). Used for defaults and docs.
2//! This scaffold provides a minimal lookup; for production, prefer env/remote config.
3//!
4//! Last updated: 2025-01-27
5//! Sources: Official provider pricing pages (as of update date)
6//! Note: Prices are USD per 1K tokens, subject to change by providers
7
8use crate::client::Provider;
9#[cfg(feature = "routing_mvp")]
10use crate::provider::models::PricingInfo;
11
12#[cfg(not(feature = "routing_mvp"))]
13#[derive(Debug, Clone)]
14pub struct PricingInfo {
15    pub input_cost_per_1k: f64,
16    pub output_cost_per_1k: f64,
17}
18
19#[cfg(not(feature = "routing_mvp"))]
20impl PricingInfo {
21    pub fn new(input_cost_per_1k: f64, output_cost_per_1k: f64) -> Self {
22        Self {
23            input_cost_per_1k,
24            output_cost_per_1k,
25        }
26    }
27}
28
29/// Return indicative pricing for a given provider/model, if known.
30/// Values are USD per 1K input/output tokens.
31pub fn get_pricing(provider: Provider, model: &str) -> Option<PricingInfo> {
32    let m = model.to_ascii_lowercase();
33    match provider {
34        Provider::OpenAI => match m.as_str() {
35            // Reference values are illustrative only
36            "gpt-3.5-turbo" => Some(PricingInfo::new(0.50, 1.50)),
37            "gpt-4o" => Some(PricingInfo::new(5.00, 15.00)),
38            _ => None,
39        },
40        Provider::Groq => match m.as_str() {
41            "llama-3.1-8b-instant" | "llama3-8b" => Some(PricingInfo::new(0.05, 0.08)),
42            _ => None,
43        },
44        Provider::DeepSeek => match m.as_str() {
45            "deepseek-chat" => Some(PricingInfo::new(0.27, 1.10)),
46            "deepseek-reasoner" => Some(PricingInfo::new(0.55, 2.20)),
47            _ => None,
48        },
49        Provider::Mistral => match m.as_str() {
50            "mistral-small" => Some(PricingInfo::new(0.20, 0.60)),
51            _ => None,
52        },
53        Provider::Cohere => match m.as_str() {
54            "command-r" => Some(PricingInfo::new(0.50, 1.50)),
55            _ => None,
56        },
57        Provider::Gemini => match m.as_str() {
58            "gemini-pro" | "gemini-1.5-flash" => Some(PricingInfo::new(0.10, 0.30)),
59            _ => None,
60        },
61        Provider::AzureOpenAI
62        | Provider::Anthropic
63        | Provider::HuggingFace
64        | Provider::TogetherAI
65        | Provider::OpenRouter
66        | Provider::Replicate
67        | Provider::ZhipuAI
68        | Provider::MiniMax
69        | Provider::Perplexity
70        | Provider::AI21
71        | Provider::Qwen
72        | Provider::BaiduWenxin
73        | Provider::TencentHunyuan
74        | Provider::IflytekSpark
75        | Provider::Moonshot
76        | Provider::Ollama
77        | Provider::XaiGrok => None,
78    }
79}