@@ -186,15 +186,25 @@ pub async fn run_async(ctx: AppConfig, config: RunAsyncConfig) -> Result<(), Str
186186
187187 // Make chat completion request
188188 let llm_start = Instant :: now ( ) ;
189- let response = client
189+ let response_result = client
190190 . chat_completion (
191191 config. model . clone ( ) ,
192192 chat_messages. clone ( ) ,
193193 Some ( tools. clone ( ) ) ,
194194 current_session_id,
195195 )
196- . await
197- . map_err ( |e| e. to_string ( ) ) ?;
196+ . await ;
197+
198+ let response = match response_result {
199+ Ok ( response) => response,
200+ Err ( e) => {
201+ print ! (
202+ "{}" ,
203+ renderer. render_error( & format!( "Error during execution: {}" , e) )
204+ ) ;
205+ break ;
206+ }
207+ } ;
198208 llm_response_time += llm_start. elapsed ( ) ;
199209
200210 // Accumulate token usage
@@ -434,6 +444,33 @@ pub async fn run_async(ctx: AppConfig, config: RunAsyncConfig) -> Result<(), Str
434444 ) ;
435445 }
436446
447+ // Attempt to print billing info (cost)
448+ if let Ok ( account_data) = client. get_my_account ( ) . await {
449+ let billing_username = account_data
450+ . scope
451+ . as_ref ( )
452+ . map ( |s| s. name . as_str ( ) )
453+ . unwrap_or ( & account_data. username ) ;
454+
455+ if let Ok ( billing_info) = client. get_billing_info ( billing_username) . await {
456+ let mut info_str = String :: new ( ) ;
457+ for ( name, feature) in billing_info. features {
458+ if let Some ( balance) = feature. balance {
459+ info_str. push_str ( & format ! ( " - {}: {:.2}\n " , name, balance) ) ;
460+ }
461+ // Check for included usage as well which might represent "credits" in some contexts
462+ if let Some ( usage) = feature. usage {
463+ info_str. push_str ( & format ! ( " - {} Usage: {:.2}\n " , name, usage) ) ;
464+ }
465+ }
466+
467+ if !info_str. is_empty ( ) {
468+ print ! ( "{}" , renderer. render_info( "Billing Status:" ) ) ;
469+ print ! ( "{}" , renderer. render_info( & info_str) ) ;
470+ }
471+ }
472+ }
473+
437474 // Print session ID if available
438475 if let Some ( session_id) = current_session_id {
439476 println ! ( "Session ID: {}" , session_id) ;
0 commit comments