bitrouter_core/routers/routing_table.rs
1use serde::Serialize;
2
3use crate::errors::Result;
4
5/// The target to route a request to.
6pub struct RoutingTarget {
7 /// The provider name to route to.
8 pub provider_name: String,
9 /// The actual upstream provider's model ID to route to.
10 pub model_id: String,
11}
12
13/// A single entry in the route listing, describing a configured model route.
14#[derive(Debug, Clone)]
15pub struct RouteEntry {
16 /// The virtual model name (e.g. "default", "my-gpt4").
17 pub model: String,
18 /// The provider name this model routes to.
19 pub provider: String,
20 /// The API protocol the provider uses ("openai", "anthropic", "google").
21 pub protocol: String,
22}
23
24/// Input token pricing per million tokens.
25#[derive(Debug, Clone, Default, Serialize)]
26pub struct InputTokenPricing {
27 /// Cost per million non-cached input tokens.
28 pub no_cache: f64,
29 /// Cost per million cache-read input tokens.
30 pub cache_read: f64,
31 /// Cost per million cache-write input tokens.
32 pub cache_write: f64,
33}
34
35/// Output token pricing per million tokens.
36#[derive(Debug, Clone, Default, Serialize)]
37pub struct OutputTokenPricing {
38 /// Cost per million text output tokens.
39 pub text: f64,
40 /// Cost per million reasoning output tokens.
41 pub reasoning: f64,
42}
43
44/// Token pricing per million tokens for a model.
45#[derive(Debug, Clone, Default, Serialize)]
46pub struct ModelPricing {
47 pub input_tokens: InputTokenPricing,
48 pub output_tokens: OutputTokenPricing,
49}
50
51/// A routing table that maps incoming model names to routing targets (provider + model ID).
52pub trait RoutingTable {
53 /// Routes an incoming model name to a routing target.
54 fn route(
55 &self,
56 incoming_model_name: &str,
57 ) -> impl Future<Output = Result<RoutingTarget>> + Send;
58
59 /// Lists all configured model routes.
60 fn list_routes(&self) -> Vec<RouteEntry> {
61 Vec::new()
62 }
63}