api_gemini 0.5.0

Gemini's API for accessing large language models (LLMs).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
//! Model metadata and discovery API implementation.
//!
//! This module provides access to model information and metadata through the Gemini API.

use reqwest::Method;
use crate::client::ModelsApi;
use crate::error::Error;
use crate::models::{ Model, ListModelsResponse };
use crate::internal::http;

use super::ModelApi;

impl ModelsApi< '_ >
{
  /// Lists all available Gemini models.
  ///
  /// This method fetches the complete list of models available through the Gemini API,
  /// including both generative and embedding models. The response includes detailed
  /// information about each model such as supported features, input/output token limits,
  /// and version information.
  ///
  /// # Returns
  ///
  /// Returns a [`ListModelsResponse`] containing:
  /// - `models`: Vector of [`Model`] objects with detailed model information
  /// - `next_page_token`: Token for pagination (if applicable)
  ///
  /// # Errors
  ///
  /// This method returns an error in the following cases:
  /// - [`Error::NetworkError`] - Network connectivity issues or request timeout
  /// - [`Error::AuthenticationError`] - Invalid or missing API key
  /// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
  /// - [`Error::DeserializationError`] - Failed to parse the API response
  /// - [`Error::ApiError`] - Other API-related errors
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  ///
  /// // List all available models
  /// let response = models_api.list().await?;
  /// println!( "Found {} models", response.models.len() );
  ///
  /// // Print model names and capabilities
  /// for model in &response.models {
  ///   println!( "Model : {} - {}", model.name, model.display_name.as_deref().unwrap_or("N/A") );
  ///   if let Some( ref supported_generation_methods ) = model.supported_generation_methods {
  ///     println!( "  Supported methods : {:?}", supported_generation_methods );
  ///   }
  /// }
  /// # Ok( () )
  /// # }
  /// ```
  #[ inline ]
  pub async fn list( &self ) -> Result< ListModelsResponse, Error >
  {
    let url = format!( "{}/v1beta/models", self.client.base_url );

    http ::execute_with_optional_retries::< (), ListModelsResponse >
    (
      self.client,
      Method::GET,
      &url,
      &self.client.api_key,
      None,
    )
    .await
    .map_err( Self::enhance_list_error )
  }

  /// Gets information about a specific model by ID.
  ///
  /// This method retrieves detailed information about a specific Gemini model,
  /// including its capabilities, token limits, supported features, and version details.
  /// Model IDs can be provided with or without the "models/" prefix.
  ///
  /// # Arguments
  ///
  /// * `model_id` - The model identifier. Can be:
  ///   - Simple name : `"gemini-2.5-flash"`
  ///   - Full name : `"models/gemini-2.5-flash"`
  ///
  /// # Returns
  ///
  /// Returns a [`Model`] object containing detailed information about the model:
  /// - Basic info : name, display name, description
  /// - Capabilities : supported generation methods, modalities
  /// - Limits : input/output token limits, rate limits
  /// - Version info : version, creation date
  ///
  /// # Errors
  ///
  /// This method returns an error in the following cases:
  /// - [`Error::InvalidArgument`] - Invalid model ID format or model not found (404)
  /// - [`Error::NetworkError`] - Network connectivity issues or timeout
  /// - [`Error::AuthenticationError`] - Invalid or missing API key
  /// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
  /// - [`Error::DeserializationError`] - Failed to parse the API response
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  ///
  /// // Get model by simple name
  /// let model = models_api.get( "gemini-2.5-flash" ).await?;
  /// println!( "Model : {} - {}",
  ///   model.display_name.as_deref().unwrap_or( "N/A" ),
  ///   model.name
  /// );
  ///
  /// // Check capabilities
  /// if let Some( ref methods ) = model.supported_generation_methods {
  ///   println!( "Supported generation methods:" );
  ///   for method in methods {
  ///     println!( "  - {}", method );
  ///   }
  /// }
  ///
  /// // Check token limits
  /// if let Some( input_limit ) = model.input_token_limit {
  ///   println!( "Max input tokens : {}", input_limit );
  /// }
  /// if let Some( output_limit ) = model.output_token_limit {
  ///   println!( "Max output tokens : {}", output_limit );
  /// }
  /// # Ok( () )
  /// # }
  /// ```
  #[ inline ]
  pub async fn get( &self, model_id : &str ) -> Result< Model, Error >
  {
    // Remove "models/" prefix if already present for clean URL construction
    let clean_model_id = model_id.strip_prefix( "models/" ).unwrap_or( model_id );

    // Validate model ID format
    if clean_model_id.is_empty()
    {
      return Err( Error::InvalidArgument(
        "Model ID cannot be empty. Please provide a valid model identifier.".to_string()
      ) );
    }

    let url = format!( "{}/v1beta/models/{clean_model_id}", self.client.base_url );

    http ::execute_with_optional_retries::< (), Model >
    (
      self.client,
      Method::GET,
      &url,
      &self.client.api_key,
      None,
    )
    .await
    .map_err( | e | Self::enhance_get_error( model_id, e ) )
  }

  /// Creates a handle for a specific model by name.
  ///
  /// This method returns a [`ModelApi`] handle that can be used to interact
  /// with the specified model. The model name can be provided with or without
  /// the "models/" prefix.
  ///
  /// # Arguments
  ///
  /// * `model_id` - The model identifier (e.g., "gemini-2.5-flash")
  ///
  /// # Returns
  ///
  /// Returns a [`ModelApi`] handle for the specified model.
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # use api_gemini::models::{ GenerateContentRequest, Content, Part };
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  /// let model = models_api.by_name( "gemini-2.5-flash" );
  ///
  /// // Use the model handle for operations
  /// let request = GenerateContentRequest {
  ///   contents : vec![ Content {
  ///     parts : vec![ Part {
  ///       text : Some( "Hello!".to_string() ),
  ///       ..Default::default()
  ///     } ],
  ///     role : "user".to_string(),
  ///   } ],
  ///   ..Default::default()
  /// };
  ///
  /// let response = model.generate_content( &request ).await?;
  /// # Ok( () )
  /// # }
  /// ```
  #[ must_use ]
  #[ inline ]
  pub fn by_name( &self, model_id : &str ) -> ModelApi< '_ >
  {
    ModelApi {
      client : self.client,
      model_id : model_id.to_string(),
    }
  }

  /// Enhance errors from list operation with additional context.
  fn enhance_list_error( error : Error ) -> Error
  {
    match error
    {
      Error::NetworkError( ref msg ) =>
        Error::NetworkError(
          format!( "Failed to retrieve model list : {msg}. Please check your internet connection and try again." )
        ),
      Error::AuthenticationError( ref msg ) =>
        Error::AuthenticationError(
          format!( "Authentication failed while listing models : {msg}. Please verify your API key." )
        ),
      Error::ServerError( ref msg ) =>
        Error::ServerError(
          format!( "Gemini API server error while listing models : {msg}" )
        ),
      other => other,
    }
  }

  /// Enhance errors from get operation with model-specific context.
  fn enhance_get_error( model_id : &str, error : Error ) -> Error
  {
    match error
    {
      Error::NetworkError( ref msg ) =>
        Error::NetworkError(
          format!( "Failed to retrieve model '{model_id}': {msg}. Please check your internet connection." )
        ),
      Error::AuthenticationError( ref msg ) =>
        Error::AuthenticationError(
          format!( "Authentication failed for model '{model_id}': {msg}. Please verify your API key." )
        ),
      Error::ServerError( ref msg ) if msg.contains( "404" ) || msg.contains( "not found" ) =>
        Error::InvalidArgument(
          format!( "Model '{model_id}' not found. Please check the model ID and try again. Use models().list() to see available models." )
        ),
      Error::ServerError( ref msg ) =>
        Error::ServerError(
          format!( "Gemini API server error for model '{model_id}': {msg}" )
        ),
      other => other,
    }
  }

  /// Counts tokens for the specified model.
  ///
  /// This convenience method provides direct access to token counting functionality
  /// without needing to create a model handle first. It's equivalent to calling
  /// `models_api.by_name(model_id).count_tokens(request)`.
  ///
  /// # Arguments
  ///
  /// * `model_id` - The model identifier (e.g., "gemini-1.5-flash", "gemini-1.5-pro-latest")
  /// * `request` - A [`crate::models::CountTokensRequest`] containing the content to count
  ///
  /// # Returns
  ///
  /// Returns a [`crate::models::CountTokensResponse`] with token count information.
  ///
  /// # Errors
  ///
  /// Returns the same errors as [`ModelApi::count_tokens`] method.
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # use api_gemini::models::{ Content, Part, CountTokensRequest };
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  ///
  /// let content = Content {
  ///   parts : vec![ Part {
  ///     text : Some( "Hello world".to_string() ),
  ///     ..Default::default()
  ///   } ],
  ///   role : "user".to_string(),
  /// };
  ///
  /// let request = CountTokensRequest {
  ///   contents : vec![ content ],
  ///   generate_content_request : None,
  /// };
  ///
  /// // Direct token counting
  /// let response = models_api.count_tokens( "gemini-1.5-flash", &request ).await?;
  /// println!( "Tokens : {}", response.total_tokens );
  /// # Ok( () )
  /// # }
  /// ```
  #[ inline ]
  pub async fn count_tokens
  (
    &self,
    model_id : &str,
    request : &crate::models::CountTokensRequest,
  )
  ->
  Result< crate::models::CountTokensResponse, Error >
  {
    self.by_name( model_id ).count_tokens( request ).await
  }
}

impl ModelApi< '_ >
{
  /// Gets information about this specific model.
  ///
  /// This method retrieves detailed information about the model bound to this
  /// handle, including its capabilities, token limits, supported features,
  /// and version details. This is useful for understanding what the model
  /// can do before making requests.
  ///
  /// # Returns
  ///
  /// Returns a [`Model`] object containing:
  /// - Basic information : name, display name, description
  /// - Capabilities : supported generation methods, input/output modalities
  /// - Limits : token limits, rate limits, safety settings
  /// - Version : model version, creation date, update date
  ///
  /// # Errors
  ///
  /// This method returns an error in the following cases:
  /// - [`Error::InvalidArgument`] - Model not found or invalid model ID
  /// - [`Error::NetworkError`] - Network connectivity issues or timeout
  /// - [`Error::AuthenticationError`] - Invalid or missing API key
  /// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
  /// - [`Error::DeserializationError`] - Failed to parse the API response
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  /// let model = models_api.by_name( "gemini-2.5-flash" );
  ///
  /// let info = model.get().await?;
  /// println!( "Model : {} ({})", info.display_name.as_deref().unwrap_or( "N/A" ), info.name );
  ///
  /// // Check what the model can do
  /// if let Some( ref methods ) = info.supported_generation_methods {
  ///   println!( "Supported operations:" );
  ///   for method in methods {
  ///     match method.as_str() {
  ///       "generateContent" => println!( "  ✓ Text generation" ),
  ///       "embedContent" => println!( "  ✓ Text embeddings" ),
  ///       other => println!( "  ✓ {}", other ),
  ///     }
  ///   }
  /// }
  ///
  /// // Check token limits
  /// if let Some( input_limit ) = info.input_token_limit {
  ///   println!( "Max input tokens : {}", input_limit );
  /// }
  /// # Ok( () )
  /// # }
  /// ```
  #[ inline ]
  pub async fn get( &self ) -> Result< Model, Error >
  {
    // Remove "models/" prefix if already present for clean URL construction
    let clean_model_id = self.model_id.strip_prefix( "models/" ).unwrap_or( &self.model_id );

    let url = format!( "{}/v1beta/models/{clean_model_id}", self.client.base_url );

    http ::execute_with_optional_retries::< (), Model >
    (
      self.client,
      Method::GET,
      &url,
      &self.client.api_key,
      None,
    )
    .await
    .map_err( | e | self.enhance_model_operation_error( "retrieve model information", e ) )
  }

  /// Returns the model ID for this model handle.
  ///
  /// This is a simple accessor method that returns the model identifier
  /// associated with this `ModelApi` instance.
  ///
  /// # Returns
  ///
  /// The model ID string.
  ///
  /// # Examples
  ///
  /// ```rust
  /// # use api_gemini::client::Client;
  /// # fn example() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  /// let model = models_api.by_name( "gemini-2.5-flash" );
  ///
  /// assert_eq!( model.model_id(), "gemini-2.5-flash" );
  /// # Ok( () )
  /// # }
  /// ```
  #[ must_use ]
  #[ inline ]
  pub fn model_id( &self ) -> &str
  {
    &self.model_id
  }

  /// Create a WebSocket stream for real-time bidirectional communication.
  ///
  /// This method provides WebSocket-like functionality with fallback to HTTP streaming.
  /// Since the Gemini API uses HTTP with Server-Sent Events, this implementation
  /// simulates WebSocket behavior over the existing streaming infrastructure.
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # async fn example() -> Result< (), Box< dyn std::error::Error > > {
  /// use std::time::Duration;
  ///
  /// let client = Client::new()?;
  ///
  /// let mut websocket_stream = client
  ///   .models()
  ///   .by_name( "gemini-pro" )
  ///   .websocket_stream()
  ///   .with_message( "Hello, let's have a conversation!" )
  ///   .with_keepalive( Duration::from_secs( 30 ) )
  ///   .with_reconnect( true )
  ///   .connect()
  ///   .await?;
  ///
  /// // Use websocket_stream for bidirectional communication
  /// # Ok( () )
  /// # }
  /// ```
  #[ must_use ]
  #[ inline ]
  pub fn websocket_stream( &self ) -> crate::models::websocket_streaming::WebSocketStreamBuilder< '_ >
  {
    crate ::models::websocket_streaming::WebSocketStreamBuilder::new( self )
  }

  /// Create a fine-tuning job for custom model training.
  ///
  /// This method provides comprehensive fine-tuning capabilities including supervised learning,
  /// parameter-efficient training methods (`LoRA`, adapters), and hyperparameter optimization.
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # async fn example() -> Result< (), Box< dyn std::error::Error > > {
  /// use api_gemini::models::{ HyperparameterConfig, LoRAConfig, TrainingObjective };
  ///
  /// let client = Client::new()?;
  ///
  /// let training_job = client
  ///   .models()
  ///   .by_name( "gemini-pro" )
  ///   .fine_tune()
  ///   .with_training_data( "path/to/training_data.jsonl" )
  ///   .with_validation_data( "path/to/validation_data.jsonl" )
  ///   .with_epochs( 3 )
  ///   .with_learning_rate( 0.0001 )
  ///   .with_lora_config( LoRAConfig::builder()
  ///     .rank( 16 )
  ///     .alpha( 32.0 )
  ///     .build()? )
  ///   .start_training()
  ///   .await?;
  ///
  /// // Monitor training progress
  /// let mut progress_receiver = training_job.subscribe_progress();
  /// # Ok( () )
  /// # }
  /// ```
  #[ must_use ]
  #[ inline ]
  pub fn fine_tune( &self ) -> crate::models::model_tuning::FineTuningBuilder< '_ >
  {
    crate ::models::model_tuning::FineTuningBuilder::new( self )
  }

  /// Deploy a model to production environments.
  ///
  /// This method provides comprehensive deployment capabilities including orchestration,
  /// scaling, monitoring, and various deployment strategies (blue-green, canary, rolling).
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # async fn example() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  ///
  /// // Get deployment builder (API for configuration and deployment)
  /// let _deployment_builder = client
  ///   .models()
  ///   .by_name( "gemini-pro" )
  ///   .deploy();
  ///
  /// // Use builder methods to configure deployment settings
  /// // (Full deployment API is available through the builder)
  /// # Ok( () )
  /// # }
  /// ```
  #[ must_use ]
  #[ inline ]
  pub fn deploy( &self ) -> crate::models::model_deployment::DeploymentBuilder< '_ >
  {
    crate ::models::model_deployment::DeploymentBuilder::new( self )
  }

  /// Counts the number of tokens in the provided content.
  ///
  /// This method helps you understand token usage before making generation requests,
  /// allowing you to stay within model limits and estimate costs. It supports counting
  /// tokens for both simple content and full generation requests.
  ///
  /// # Arguments
  ///
  /// * `request` - The token counting request containing content to analyze
  ///
  /// # Returns
  ///
  /// Returns a [`CountTokensResponse`] containing:
  /// - `total_tokens`: Total number of tokens in the input
  /// - `cached_content_token_count`: Number of cached content tokens (if applicable)
  ///
  /// # Errors
  ///
  /// This method returns an error in the following cases:
  /// - [`Error::InvalidArgument`] - Empty content or invalid request structure
  /// - [`Error::NetworkError`] - Network connectivity issues or timeout
  /// - [`Error::AuthenticationError`] - Invalid or missing API key
  /// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
  /// - [`Error::DeserializationError`] - Failed to parse the API response
  ///
  /// # Examples
  ///
  /// ```rust,no_run
  /// # use api_gemini::client::Client;
  /// # use api_gemini::models::{ CountTokensRequest, Content, Part };
  /// # #[ tokio::main ]
  /// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
  /// let client = Client::new()?;
  /// let models_api = client.models();
  /// let model = models_api.by_name( "gemini-2.5-flash" );
  ///
  /// // Count tokens for simple text
  /// let request = CountTokensRequest {
  ///   contents : vec![ Content {
  ///     parts : vec![ Part {
  ///       text : Some( "How many tokens is this?".to_string() ),
  ///       ..Default::default()
  ///     } ],
  ///     role : "user".to_string(),
  ///   } ],
  ///   ..Default::default()
  /// };
  ///
  /// let response = model.count_tokens( &request ).await?;
  /// println!( "This text contains {} tokens", response.total_tokens );
  ///
  /// // Use the count to check against model limits
  /// let model_info = model.get().await?;
  /// if let Some( limit ) = model_info.input_token_limit {
  ///   if response.total_tokens > limit {
  ///     println!( "Warning : Input exceeds model limit of {} tokens", limit );
  ///   }
  /// }
  /// # Ok( () )
  /// # }
  /// ```
  #[ inline ]
  pub async fn count_tokens
  (
    &self,
    request : &crate::models::CountTokensRequest,
  )
  ->
  Result< crate::models::CountTokensResponse, Error >
  {
    // Validate request before sending
    if request.contents.is_empty()
    {
      return Err( Error::InvalidArgument(
        "Count tokens request cannot have empty contents. Please provide at least one content item.".to_string()
      ) );
    }

    let url = format!(
      "{}/v1beta/models/{}:countTokens",
      self.client.base_url,
      self.model_id
    );

    http ::execute_with_optional_retries
    (
      self.client,
      Method::POST,
      &url,
      &self.client.api_key,
      Some( request ),
    )
    .await
    .map_err( |e| self.enhance_model_operation_error( "count tokens", e ) )
  }

  /// Enhance errors from model operations with model-specific context.
  pub( super ) fn enhance_model_operation_error( &self, operation : &str, error : Error ) -> Error
  {
    match error
    {
      Error::NetworkError( ref msg ) =>
        Error::NetworkError(
          format!( "Failed to {operation} for model '{}': {msg}. Please check your internet connection.", self.model_id )
        ),
      Error::AuthenticationError( ref msg ) =>
        Error::AuthenticationError(
          format!( "Authentication failed while trying to {operation} for model '{}': {msg}. Please verify your API key.", self.model_id )
        ),
      Error::ServerError( ref msg ) if msg.contains( "404" ) || msg.contains( "not found" ) =>
        Error::InvalidArgument(
          format!( "Model '{}' not found while trying to {operation}. Please check the model ID.", self.model_id )
        ),
      Error::ServerError( ref msg ) =>
        Error::ServerError(
          format!( "Gemini API server error for model '{}' while trying to {operation}: {msg}", self.model_id )
        ),
      other => other,
    }
  }
}