api_claude 0.4.0

Claude API for accessing Anthropic's 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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
//! Core error types for Anthropic API client
//!
//! Basic error types including HTTP errors, authentication errors, rate limiting, etc.

#[ allow( clippy::missing_inline_in_public_items ) ]
mod private
{
  use serde::{ Serialize, Deserialize };
  use std::{ fmt, time::Duration };

  #[ cfg( feature = "error-handling" ) ]
  use super::super::enhanced::orphan::{ EnhancedAnthropicError, ErrorContext };

  /// Structured HTTP error information
  ///
  /// # Examples
  ///
  /// ```
  /// # #[ cfg( feature = "error-handling" ) ]
  /// # {
  /// use api_claude::AnthropicError;
  ///
  /// // Create HTTP error through AnthropicError
  /// let error = AnthropicError::http_error( "Request failed".to_string() );
  ///
  /// // Create HTTP error with status code
  /// let error_with_status = AnthropicError::http_error_with_status( "Not found".to_string(), 404 );
  ///
  /// // Errors can be displayed
  /// let error_message = format!( "{}", error );
  /// assert!( error_message.contains( "Request failed" ) );
  /// # }
  /// ```
  #[ derive( Debug, Clone ) ]
  pub struct HttpError
  {
    /// HTTP status code
    status_code : Option< u16 >,
    /// Error message
    message : String,
    /// Request URL (if available)
    url : Option< String >,
    /// Request method
    method : Option< String >,
    /// Response headers (if available)
    headers : Option< Vec< ( String, String ) > >,
  }

  impl HttpError
  {
    /// Create new HTTP error
    pub fn new( message : String ) -> Self
    {
      Self {
        status_code : None,
        message,
        url : None,
        method : None,
        headers : None,
      }
    }

    /// Create HTTP error with status code
    #[ must_use ]
    pub fn with_status_code( mut self, status_code : u16 ) -> Self
    {
      self.status_code = Some( status_code );
      self
    }

    /// Add request information
    #[ must_use ]
    pub fn with_request_info( mut self, method : String, url : String ) -> Self
    {
      self.method = Some( method );
      self.url = Some( url );
      self
    }

    /// Get status code
    pub fn status_code( &self ) -> Option< u16 >
    {
      self.status_code
    }

    /// Get message
    pub fn message( &self ) -> &str
    {
      &self.message
    }

    /// Check if retryable based on status code
    pub fn is_retryable( &self ) -> bool
    {
      match self.status_code
      {
        Some( code ) => matches!( code, 500..=599 | 429 | 408 ),
        None => false,
      }
    }

    /// Get response headers (if available)
    pub fn headers( &self ) -> Option< &Vec< ( String, String ) > >
    {
      self.headers.as_ref()
    }
  }

  impl fmt::Display for HttpError
  {
    fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
    {
      match ( &self.status_code, &self.method, &self.url )
      {
        ( Some( code ), Some( method ), Some( url ) ) =>
          write!( f, "HTTP {} error for {} {}: {}", code, method, url, self.message ),
        ( Some( code ), _, _ ) =>
          write!( f, "HTTP {} error : {}", code, self.message ),
        _ =>
          write!( f, "HTTP error : {}", self.message ),
      }
    }
  }

  /// Anthropic API error types
  #[ derive( Debug, Clone ) ]
  pub enum AnthropicError
  {
    /// HTTP request error with structured information
    Http( HttpError ),
    /// API error returned by Anthropic
    Api( AnthropicApiError ),
    /// Invalid argument provided
    InvalidArgument( String ),
    /// Invalid request parameters
    InvalidRequest( String ),
    /// Missing environment variable or secret
    MissingEnvironment( String ),
    /// Authentication error (invalid API key, etc.)
    Authentication( AuthenticationError ),
    /// Rate limiting error
    RateLimit( RateLimitError ),
    /// File operation error
    File( String ),
    /// Internal error
    Internal( String ),
    /// Streaming error
    Stream( String ),
    /// Parsing error
    Parsing( String ),
    /// Functionality not yet implemented
    NotImplemented( String ),
    /// Circuit breaker is open
    #[ cfg( feature = "circuit-breaker" ) ]
    CircuitOpen( String ),
    /// Enhanced error with context (when error-handling feature is enabled)
    #[ cfg( feature = "error-handling" ) ]
    Enhanced( Box< EnhancedAnthropicError > ),
  }

  impl fmt::Display for AnthropicError
  {
    fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
    {
      match self
      {
        AnthropicError::Http( err ) => write!( f, "{err}" ),
        AnthropicError::Api( err ) => write!( f, "API error : {err}" ),
        AnthropicError::InvalidArgument( msg ) => write!( f, "Invalid argument : {msg}" ),
        AnthropicError::InvalidRequest( msg ) => write!( f, "Invalid request : {msg}" ),
        AnthropicError::MissingEnvironment( msg ) => write!( f, "Missing environment : {msg}" ),
        AnthropicError::Authentication( err ) => write!( f, "Authentication error : {err}" ),
        AnthropicError::RateLimit( err ) => write!( f, "Rate limit error : {err}" ),
        AnthropicError::File( msg ) => write!( f, "File error : {msg}" ),
        AnthropicError::Internal( msg ) => write!( f, "Internal error : {msg}" ),
        AnthropicError::Stream( msg ) => write!( f, "Stream error : {msg}" ),
        AnthropicError::Parsing( msg ) => write!( f, "Parsing error : {msg}" ),
        AnthropicError::NotImplemented( msg ) => write!( f, "Not implemented : {msg}" ),
        #[ cfg( feature = "circuit-breaker" ) ]
        AnthropicError::CircuitOpen( msg ) => write!( f, "Circuit breaker open : {msg}" ),
        #[ cfg( feature = "error-handling" ) ]
        AnthropicError::Enhanced( err ) => write!( f, "Enhanced error : {}", err.message() ),
      }
    }
  }

  impl core::error::Error for AnthropicError
  {}

  /// Core error analysis and recovery methods (always available)
  impl AnthropicError
  {
    /// Check if this error is retryable
    #[ must_use ]
    pub fn is_retryable( &self ) -> bool
    {
      match self
      {
        AnthropicError::Http( http_err ) => http_err.is_retryable(),
        AnthropicError::RateLimit( _ ) | AnthropicError::Stream( _ ) | AnthropicError::Internal( _ ) => true,
        AnthropicError::Api( api_err ) => api_err.is_retryable(),
        _ => false,
      }
    }

    /// Get error severity level
    #[ must_use ]
    pub fn severity( &self ) -> ErrorSeverity
    {
      match self
      {
        AnthropicError::Authentication( _ ) | AnthropicError::MissingEnvironment( _ ) => ErrorSeverity::Critical,
        AnthropicError::InvalidArgument( _ ) | AnthropicError::InvalidRequest( _ ) => ErrorSeverity::High,
        AnthropicError::RateLimit( _ ) | AnthropicError::Http( _ ) | AnthropicError::Stream( _ ) | AnthropicError::Api( _ ) => ErrorSeverity::Medium,
        _ => ErrorSeverity::Low,
      }
    }

    /// Get suggested recovery actions
    #[ must_use ]
    pub fn recovery_suggestions( &self ) -> Vec< String >
    {
      match self
      {
        AnthropicError::Authentication( _ ) => vec![
          "Verify your API key is correct and properly formatted".to_string(),
          "Check that your API key has the required permissions".to_string(),
          "Ensure the API key starts with 'sk-ant-'".to_string(),
        ],
        AnthropicError::RateLimit( rate_err ) => {
          let mut suggestions = vec![
            "Implement exponential backoff retry strategy".to_string(),
            "Reduce request frequency".to_string(),
          ];
          if let Some( retry_after ) = rate_err.retry_after()
          {
            suggestions.push( format!( "Wait {retry_after} seconds before retrying" ) );
          }
          suggestions
        },
        AnthropicError::Http( http_err ) => {
          if http_err.is_retryable()
          {
            vec![
              "Retry the request with exponential backoff".to_string(),
              "Check network connectivity".to_string(),
            ]
          } else {
            vec![
              "Verify request parameters and format".to_string(),
              "Check API endpoint URL".to_string(),
            ]
          }
        },
        AnthropicError::MissingEnvironment( msg ) => vec![
          format!( "Set the required environment variable : {}", msg ),
          "Check your .env file or environment configuration".to_string(),
        ],
        _ => vec![ "Check error message for specific guidance".to_string() ],
      }
    }

    /// Create structured HTTP error
    pub fn http_error( message : String ) -> Self
    {
      Self::Http( HttpError::new( message ) )
    }

    /// Create HTTP error with status code
    pub fn http_error_with_status( message : String, status_code : u16 ) -> Self
    {
      Self::Http( HttpError::new( message ).with_status_code( status_code ) )
    }

    /// Create HTTP error with full request info
    pub fn http_error_with_request( message : String, status_code : u16, method : String, url : String ) -> Self
    {
      Self::Http(
        HttpError::new( message )
          .with_status_code( status_code )
          .with_request_info( method, url )
      )
    }
  }

  /// Error severity levels
  #[ derive( Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ) ]
  pub enum ErrorSeverity
  {
    /// Low severity - informational
    Low,
    /// Medium severity - operation failed but recoverable
    Medium,
    /// High severity - significant issue requiring attention
    High,
    /// Critical severity - system-level failure
    Critical,
  }

  #[ cfg( feature = "error-handling" ) ]
  impl AnthropicError
  {
    /// Check if error has context
    #[ must_use ]
    pub fn has_context( &self ) -> bool
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.has_context(),
        _ => false,
      }
    }

    /// Get error context  
    #[ must_use ]
    pub fn context( &self ) -> &str
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.context().map_or( "", ErrorContext::context ),
        _ => "",
      }
    }

    /// Check if error has stack trace
    #[ must_use ]
    pub fn has_stack_trace( &self ) -> bool
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.has_stack_trace(),
        _ => false,
      }
    }

    /// Get stack trace
    #[ must_use ]
    pub fn stack_trace( &self ) -> Vec< String >
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.stack_trace().clone(),
        _ => vec![],
      }
    }

    /// Get request ID
    #[ must_use ]
    pub fn request_id( &self ) -> Option< String >
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.request_id().clone(),
        _ => None,
      }
    }

    /// Get correlation ID
    #[ must_use ]
    pub fn correlation_id( &self ) -> Option< String >
    {
      match self
      {
        AnthropicError::Enhanced( err ) => err.correlation_id().clone(),
        _ => None,
      }
    }
  }

  /// Anthropic API error response structure
  #[ derive( Debug, Serialize, Deserialize, Clone ) ]
  pub struct AnthropicApiError
  {
    /// Error type
    pub r#type : String,
    /// Error message
    pub message : String,
  }

  impl fmt::Display for AnthropicApiError
  {
    fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
    {
      write!( f, "{}: {}", self.r#type, self.message )
    }
  }

  impl AnthropicApiError
  {
    /// Check if this API error is retryable
    #[ must_use ]
    pub fn is_retryable( &self ) -> bool
    {
      // Certain error types from Anthropic API are retryable
      matches!(
        self.r#type.as_str(),
        "rate_limit_error" |
        "internal_server_error" |
        "service_unavailable" |
        "timeout_error"
      )
    }
  }
  
  /// Enhanced authentication error
  #[ derive( Debug, Clone ) ]
  pub struct AuthenticationError
  {
    /// Error message
    message : String,
    /// Whether the error is recoverable
    recoverable : bool,
    /// Suggested retry duration
    retry_after : Option< Duration >,
    /// Suggested action for recovery
    suggested_action : Option< String >,
  }
  
  impl AuthenticationError
  {
    /// Create new authentication error
    #[ inline ]
    #[ must_use ]
    pub fn new( message : String ) -> Self
    {
      Self
      {
        message,
        recoverable : false,
        retry_after : None,
        suggested_action : None,
      }
    }
    
    /// Create recoverable authentication error
    #[ inline ]
    #[ must_use ]
    pub fn recoverable( message : String, retry_after : Option< Duration >, suggested_action : Option< String > ) -> Self
    {
      Self
      {
        message,
        recoverable : true,
        retry_after,
        suggested_action,
      }
    }
    
    /// Check if error is recoverable
    #[ inline ]
    #[ must_use ]
    pub fn is_recoverable( &self ) -> bool
    {
      self.recoverable
    }
    
    /// Get retry after duration
    #[ inline ]
    #[ must_use ]
    pub fn retry_after( &self ) -> &Option< Duration >
    {
      &self.retry_after
    }
    
    /// Get suggested action
    #[ inline ]
    #[ must_use ]
    pub fn suggested_action( &self ) -> &Option< String >
    {
      &self.suggested_action
    }
  }
  
  impl fmt::Display for AuthenticationError
  {
    fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
    {
      write!( f, "{}", self.message )
    }
  }
  
  /// Rate limiting error with Anthropic API headers
  #[ derive( Debug, Clone ) ]
  pub struct RateLimitError
  {
    /// Error message
    message : String,
    /// Retry after duration in seconds (from retry-after header)
    retry_after : Option< u64 >,
    /// Type of rate limit (authentication, request, tokens)
    limit_type : String,
    /// Rate limit information from headers (boxed to reduce enum size)
    rate_limit_info : Option< Box< AnthropicRateLimitInfo > >,
  }

  /// Rate limit information from Anthropic API response headers
  #[ derive( Debug, Clone ) ]
  pub struct AnthropicRateLimitInfo
  {
    /// Maximum requests allowed (anthropic-ratelimit-requests-limit)
    pub requests_limit : Option< u64 >,
    /// Remaining requests (anthropic-ratelimit-requests-remaining)
    pub requests_remaining : Option< u64 >,
    /// When request limit resets (anthropic-ratelimit-requests-reset timestamp)
    pub requests_reset : Option< String >,
    /// Maximum tokens allowed (anthropic-ratelimit-tokens-limit)
    pub tokens_limit : Option< u64 >,
    /// Remaining tokens (anthropic-ratelimit-tokens-remaining)
    pub tokens_remaining : Option< u64 >,
    /// When token limit resets (anthropic-ratelimit-tokens-reset timestamp)
    pub tokens_reset : Option< String >,
  }

  impl AnthropicRateLimitInfo
  {
    /// Create new rate limit info from headers
    #[ must_use ]
    pub fn from_headers( headers : &reqwest::header::HeaderMap ) -> Self
    {
      Self
      {
        requests_limit : Self::parse_header_u64( headers, "anthropic-ratelimit-requests-limit" ),
        requests_remaining : Self::parse_header_u64( headers, "anthropic-ratelimit-requests-remaining" ),
        requests_reset : Self::parse_header_string( headers, "anthropic-ratelimit-requests-reset" ),
        tokens_limit : Self::parse_header_u64( headers, "anthropic-ratelimit-tokens-limit" ),
        tokens_remaining : Self::parse_header_u64( headers, "anthropic-ratelimit-tokens-remaining" ),
        tokens_reset : Self::parse_header_string( headers, "anthropic-ratelimit-tokens-reset" ),
      }
    }

    /// Check if any rate limit headers are present
    #[ must_use ]
    pub fn has_data( &self ) -> bool
    {
      self.requests_limit.is_some() ||
      self.requests_remaining.is_some() ||
      self.tokens_limit.is_some() ||
      self.tokens_remaining.is_some()
    }

    /// Get requests usage percentage (0.0 to 1.0)
    #[ must_use ]
    pub fn requests_usage_percentage( &self ) -> Option< f64 >
    {
      match ( self.requests_limit, self.requests_remaining )
      {
        ( Some( limit ), Some( remaining ) ) if limit > 0 =>
        {
          let used = limit.saturating_sub( remaining );
          Some( used as f64 / limit as f64 )
        },
        _ => None,
      }
    }

    /// Get tokens usage percentage (0.0 to 1.0)
    #[ must_use ]
    pub fn tokens_usage_percentage( &self ) -> Option< f64 >
    {
      match ( self.tokens_limit, self.tokens_remaining )
      {
        ( Some( limit ), Some( remaining ) ) if limit > 0 =>
        {
          let used = limit.saturating_sub( remaining );
          Some( used as f64 / limit as f64 )
        },
        _ => None,
      }
    }

    fn parse_header_u64( headers : &reqwest::header::HeaderMap, name : &str ) -> Option< u64 >
    {
      headers.get( name )
        .and_then( | v | v.to_str().ok() )
        .and_then( | s | s.parse::< u64 >().ok() )
    }

    fn parse_header_string( headers : &reqwest::header::HeaderMap, name : &str ) -> Option< String >
    {
      headers.get( name )
        .and_then( | v | v.to_str().ok() )
        .map( String::from )
    }
  }

  impl RateLimitError
  {
    /// Create new rate limit error
    #[ inline ]
    #[ must_use ]
    pub fn new( message : String, retry_after : Option< u64 >, limit_type : String ) -> Self
    {
      Self { message, retry_after, limit_type, rate_limit_info : None }
    }

    /// Create rate limit error with header information
    #[ inline ]
    #[ must_use ]
    pub fn with_headers( message : String, retry_after : Option< u64 >, limit_type : String, rate_limit_info : AnthropicRateLimitInfo ) -> Self
    {
      Self { message, retry_after, limit_type, rate_limit_info : Some( Box::new( rate_limit_info ) ) }
    }

    /// Get retry after duration
    #[ inline ]
    #[ must_use ]
    pub fn retry_after( &self ) -> &Option< u64 >
    {
      &self.retry_after
    }

    /// Get limit type
    #[ inline ]
    #[ must_use ]
    pub fn limit_type( &self ) -> &str
    {
      &self.limit_type
    }

    /// Get rate limit information from headers
    #[ inline ]
    #[ must_use ]
    pub fn rate_limit_info( &self ) -> Option< &AnthropicRateLimitInfo >
    {
      self.rate_limit_info.as_deref()
    }
  }
  
  impl fmt::Display for RateLimitError
  {
    fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
    {
      write!( f, "{}", self.message )?;

      if let Some( retry_after ) = self.retry_after
      {
        write!( f, " (retry after {retry_after}s)" )?;
      }

      if let Some( ref info ) = self.rate_limit_info
      {
        if let ( Some( remaining ), Some( limit ) ) = ( info.requests_remaining, info.requests_limit )
        {
          write!( f, " [requests : {remaining}/{limit}]" )?;
        }
        if let ( Some( remaining ), Some( limit ) ) = ( info.tokens_remaining, info.tokens_limit )
        {
          write!( f, " [tokens : {remaining}/{limit}]" )?;
        }
      }

      Ok( () )
    }
  }

  /// Wrapper for API error responses
  #[ derive( Debug, Serialize, Deserialize ) ]
  pub struct ApiErrorWrap
  {
    /// The error details
    pub error : AnthropicApiError,
  }

  impl From< reqwest::Error > for AnthropicError
  {
    fn from( error : reqwest::Error ) -> Self
    {
      Self::http_error( error.to_string() )
    }
  }

  impl From< serde_json::Error > for AnthropicError
  {
    fn from( error : serde_json::Error ) -> Self
    {
      Self::Internal( format!( "JSON error : {error}" ) )
    }
  }

  // From implementation is provided by error_tools blanket impl

  /// Result type for Anthropic API operations
  pub type AnthropicResult< T > = core::result::Result< T, AnthropicError >;

  /// Map deserialization error to `AnthropicError`
  pub fn map_deserialization_error( error : &serde_json::Error ) -> AnthropicError
  {
    AnthropicError::Parsing( format!( "Failed to deserialize response : {error}" ) )
  }

  // Enhanced Error Handling System

  /// Error classification categories
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum ErrorClass
  {
    /// Authentication related errors
    Authentication,
    /// Invalid request parameters
    InvalidRequest,
    /// Server-side errors
    ServerError,
    /// Rate limiting errors
    RateLimit,
    /// Network connectivity errors
    Network,
    /// Timeout related errors
    Timeout,
    /// Parsing/serialization errors
    Parsing,
    /// Internal client errors
    Internal,
  }


  /// Specific error types for detailed classification
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum ErrorType
  {
    /// Authentication errors
    Authentication,
    /// Invalid request parameters
    InvalidRequest,
    /// Server internal errors
    ServerError,
    /// Rate limiting
    RateLimit,
    /// Network connectivity issues
    Network,
    /// Timeout errors
    Timeout,
    /// Parsing errors
    Parsing,
    /// Internal client errors
    Internal,
  }

  /// Timeout error types
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum TimeoutType
  {
    /// Connection timeout
    Connection,
    /// Read timeout
    Read,
    /// Write timeout
    Write,
    /// Request timeout
    Request,
  }

  /// Network error types
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum NetworkErrorType
  {
    /// DNS resolution failure
    DnsResolution,
    /// SSL/TLS handshake failure
    SslHandshake,
    /// Connection refused
    ConnectionRefused,
    /// Connection reset
    ConnectionReset,
    /// Host unreachable
    HostUnreachable,
    /// Generic network error
    Generic,
  }

  /// Backoff strategy types
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum BackoffStrategy
  {
    /// Linear backoff
    Linear,
    /// Exponential backoff
    ExponentialBackoff,
    /// Fixed delay
    Fixed,
    /// Custom backoff
    Custom,
  }

  /// Backoff types for rate limiting
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum BackoffType
  {
    /// Linear backoff
    Linear,
    /// Exponential backoff
    Exponential,
    /// Fixed delay
    Fixed,
  }

  /// Log severity levels
  #[ derive( Debug, Clone, PartialEq, Eq, Serialize, Deserialize ) ]
  pub enum LogSeverity
  {
    /// Debug level
    Debug,
    /// Info level
    Info,
    /// Warning level
    Warning,
    /// Error level
    Error,
    /// Critical level
    Critical,
  }

}

crate::mod_interface!
{
  exposed use HttpError;
  exposed use AnthropicError;
  exposed use ErrorSeverity;
  exposed use AnthropicApiError;
  exposed use AuthenticationError;
  exposed use RateLimitError;
  exposed use AnthropicRateLimitInfo;
  exposed use ApiErrorWrap;
  exposed use AnthropicResult;
  exposed use map_deserialization_error;
  exposed use ErrorClass;
  exposed use ErrorType;
  exposed use TimeoutType;
  exposed use NetworkErrorType;
  exposed use BackoffStrategy;
  exposed use BackoffType;
  exposed use LogSeverity;
}