refactor(cost): match OpenAI, Together, and Vertex call types through CallTypes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yujong Lee 2026-09-23 20:36:19 -07:00
parent bdf1cd17fc
commit d4bb9cb85b
3 changed files with 17 additions and 3 deletions

View file

@ -1,13 +1,17 @@
use crate::error::CostError;
use serde_json::Value;
use crate::call_type::CallTypes;
use crate::non_token::{Charge, Unit, calculate};
use crate::wire::py_float;
pub use crate::non_token::video_resolution_to_cost_field_suffix;
pub fn cost_router(call_type: &str) -> &'static str {
if matches!(call_type, "transcription" | "atranscription") {
if matches!(
call_type.parse::<CallTypes>(),
Ok(CallTypes::transcription | CallTypes::atranscription)
) {
"cost_per_second"
} else {
"cost_per_token"

View file

@ -5,6 +5,7 @@ use std::sync::LazyLock;
use regex::Regex;
use serde_json::Value;
use crate::call_type::CallTypes;
use crate::catalog::ModelInfoCatalog;
use crate::provider::LlmProviders;
@ -39,7 +40,10 @@ pub fn get_model_params_and_category(
call_type: &str,
thresholds: TogetherThresholds,
) -> String {
if matches!(call_type, "embedding" | "aembedding") {
if matches!(
call_type.parse::<CallTypes>(),
Ok(CallTypes::embedding | CallTypes::aembedding)
) {
return get_model_params_and_category_embeddings(model_name, thresholds);
}
let name = model_name.to_ascii_lowercase();

View file

@ -1,11 +1,13 @@
use jiff::Timestamp;
use serde_json::Value;
use crate::call_type::CallTypes;
use crate::catalog::{ModelCostRequest, ModelInfoCatalog};
use crate::cost_calculator::cost_per_token as catalog_cost_per_token;
use crate::error::CostError;
use crate::generic_cost::calculate_generic_cost_from_model_info_with_region;
use crate::per_second::per_second_pricing_cost;
use crate::provider::LlmProviders;
use crate::regional_uplift::get_vertex_regional_endpoint_uplift;
use crate::responses_usage::ChatUsage;
@ -27,7 +29,11 @@ pub fn cost_router(model: &str, provider: &str, call_type: &str) -> CostRoute {
]
.iter()
.any(|name| model.contains(name));
if provider == "vertex_ai" && (token_model || matches!(call_type, "embedding" | "aembedding")) {
let embedding = matches!(
call_type.parse::<CallTypes>(),
Ok(CallTypes::embedding | CallTypes::aembedding)
);
if LlmProviders::VERTEX_AI.matches(Some(provider)) && (token_model || embedding) {
CostRoute::PerToken
} else {
CostRoute::PerCharacter