@@ -178,25 +178,22 @@ async fn apply_model(ctx: &mut SlashCtx<'_>, model_id: &str) {
178178 if let Some ( ( input, output) ) = lookup_pricing_from_cache ( & ctx. session . provider , model_id) {
179179 ctx. session . input_token_cost = input;
180180 ctx. session . output_token_cost = output;
181- } else if ctx. session . provider == "openrouter" {
182- if let Ok ( prices) = crate :: provider:: fetch_openrouter_pricing (
181+ } else if ctx. session . provider == "openrouter"
182+ && let Ok ( prices) = crate :: provider:: fetch_openrouter_pricing (
183183 ctx. cli . api_key . as_deref ( ) ,
184184 & ctx. cfg . custom_providers_map ( ) ,
185185 ctx. cfg . api_keys . as_ref ( ) ,
186186 )
187187 . await
188+ && let Some ( info) = prices. get ( model_id)
189+ {
190+ ctx. session . input_token_cost = info. input_cost ;
191+ ctx. session . output_token_cost = info. output_cost ;
192+ if ctx. cfg . context_window . is_none ( )
193+ && crate :: config:: Config :: catalog_context_window ( "openrouter" , model_id) . is_none ( )
194+ && let Some ( cw) = info. context_length
188195 {
189- if let Some ( info) = prices. get ( model_id) {
190- ctx. session . input_token_cost = info. input_cost ;
191- ctx. session . output_token_cost = info. output_cost ;
192- if ctx. cfg . context_window . is_none ( )
193- && crate :: config:: Config :: catalog_context_window ( "openrouter" , model_id)
194- . is_none ( )
195- && let Some ( cw) = info. context_length
196- {
197- ctx. session . update_context_window ( cw) ;
198- }
199- }
196+ ctx. session . update_context_window ( cw) ;
200197 }
201198 }
202199 write_ok ( ctx. renderer , format ! ( "switched to model: {}" , new_model) ) ;
@@ -290,25 +287,22 @@ async fn handle_model(parts: &[&str], ctx: &mut SlashCtx<'_>) -> anyhow::Result<
290287 if let Some ( ( input, output) ) = lookup_pricing_from_cache ( & ctx. session . provider , & new_model) {
291288 ctx. session . input_token_cost = input;
292289 ctx. session . output_token_cost = output;
293- } else if ctx. session . provider == "openrouter" {
294- if let Ok ( prices) = crate :: provider:: fetch_openrouter_pricing (
290+ } else if ctx. session . provider == "openrouter"
291+ && let Ok ( prices) = crate :: provider:: fetch_openrouter_pricing (
295292 ctx. cli . api_key . as_deref ( ) ,
296293 & ctx. cfg . custom_providers_map ( ) ,
297294 ctx. cfg . api_keys . as_ref ( ) ,
298295 )
299296 . await
297+ && let Some ( info) = prices. get ( & * new_model)
298+ {
299+ ctx. session . input_token_cost = info. input_cost ;
300+ ctx. session . output_token_cost = info. output_cost ;
301+ if ctx. cfg . context_window . is_none ( )
302+ && crate :: config:: Config :: catalog_context_window ( "openrouter" , & new_model) . is_none ( )
303+ && let Some ( cw) = info. context_length
300304 {
301- if let Some ( info) = prices. get ( & * new_model) {
302- ctx. session . input_token_cost = info. input_cost ;
303- ctx. session . output_token_cost = info. output_cost ;
304- if ctx. cfg . context_window . is_none ( )
305- && crate :: config:: Config :: catalog_context_window ( "openrouter" , & new_model)
306- . is_none ( )
307- && let Some ( cw) = info. context_length
308- {
309- ctx. session . update_context_window ( cw) ;
310- }
311- }
305+ ctx. session . update_context_window ( cw) ;
312306 }
313307 }
314308 write_ok ( ctx. renderer , format ! ( "switched to model: {}" , new_model) ) ;
0 commit comments