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
// Implementation blocks for helper types in enhanced error handling
//
// This file contains implementation blocks that are included directly.

// Simplified implementations for test compatibility
// These would be fully implemented in a real system

impl ErrorParser
{
  /// Parse API error response
  ///
  /// # Errors
  ///
  /// Returns an error if parsing is not yet implemented
  pub fn parse_api_error( _response : &str ) -> AnthropicResult< EnhancedAnthropicError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorParser not fully implemented".to_string() ) )
  }
}

impl ErrorMapper
{
  /// Map HTTP status to error type
  ///
  /// # Errors
  ///
  /// Returns an error if mapping is not yet implemented
  pub fn map_http_status( _status : u16, _message : &str ) -> AnthropicResult< EnhancedAnthropicError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorMapper not fully implemented".to_string() ) )
  }
}

impl ErrorClassifier
{
  /// Classify timeout error
  ///
  /// # Errors
  ///
  /// Returns an error if classification is not yet implemented
  pub fn classify_timeout( _timeout_error : &TimeoutError ) -> AnthropicResult< TimeoutClassification >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorClassifier not fully implemented".to_string() ) )
  }
}

impl ErrorRecovery
{
  /// Analyze error for recovery strategy
  ///
  /// # Errors
  ///
  /// Returns an error if analysis is not yet implemented
  pub fn analyze_error( _error : &AnthropicError ) -> AnthropicResult< RecoveryStrategy >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorRecovery not fully implemented".to_string() ) )
  }
}

impl RecoveryStrategy
{
  /// Check if should retry
  #[ must_use ]
  pub fn should_retry( &self ) -> bool
  {
    self.should_retry
  }

  /// Get max retries
  #[ must_use ]
  pub fn max_retries( &self ) -> u32
  {
    self.max_retries
  }

  /// Get backoff strategy
  #[ must_use ]
  pub fn backoff_strategy( &self ) -> BackoffStrategy
  {
    self.backoff_strategy.clone()
  }

  /// Get base delay
  #[ must_use ]
  pub fn base_delay( &self ) -> Duration
  {
    self.base_delay
  }

  /// Check if requires user action
  #[ must_use ]
  pub fn requires_user_action( &self ) -> bool
  {
    self.requires_user_action
  }

  /// Get suggested action
  #[ must_use ]
  pub fn suggested_action( &self ) -> &str
  {
    &self.suggested_action
  }
}

impl ActionableError
{
  /// Create actionable error from standard error
  ///
  /// # Errors
  ///
  /// Returns an error if creation is not yet implemented
  pub fn from_error( _error : &AnthropicError ) -> AnthropicResult< ActionableError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ActionableError not fully implemented".to_string() ) )
  }

  /// Get remediation steps
  #[ must_use ]
  pub fn remediation_steps( &self ) -> &Vec< String >
  {
    &self.remediation_steps
  }

  /// Check if has documentation links
  #[ must_use ]
  pub fn has_documentation_links( &self ) -> bool
  {
    !self.documentation_links.is_empty()
  }

  /// Get estimated fix time
  #[ must_use ]
  pub fn estimated_fix_time( &self ) -> &Option< Duration >
  {
    &self.estimated_fix_time
  }
}

impl BatchError
{
  /// Create batch error from standard error
  ///
  /// # Errors
  ///
  /// Returns an error if creation is not yet implemented
  pub fn from_error( _error : &AnthropicError ) -> AnthropicResult< BatchError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "BatchError not fully implemented".to_string() ) )
  }

  /// Get error count
  #[ must_use ]
  pub fn error_count( &self ) -> usize
  {
    self.errors.len()
  }

  /// Check if has partial success
  #[ must_use ]
  pub fn has_partial_success( &self ) -> bool
  {
    self.has_partial_success
  }

  /// Get errors
  #[ must_use ]
  pub fn errors( &self ) -> &Vec< EnhancedAnthropicError >
  {
    &self.errors
  }

  /// Get summary
  #[ must_use ]
  pub fn summary( &self ) -> &str
  {
    &self.summary
  }
}

impl TimeoutClassification
{
  /// Get timeout type
  #[ must_use ]
  pub fn timeout_type( &self ) -> TimeoutType
  {
    self.timeout_type.clone()
  }

  /// Check if network related
  #[ must_use ]
  pub fn is_network_related( &self ) -> bool
  {
    self.is_network_related
  }

  /// Check if server processing related
  #[ must_use ]
  pub fn is_server_processing_related( &self ) -> bool
  {
    self.is_server_processing_related
  }

  /// Get suggested timeout increase
  #[ must_use ]
  pub fn suggested_timeout_increase( &self ) -> Duration
  {
    self.suggested_timeout_increase
  }

  /// Check if supports streaming fallback
  #[ must_use ]
  pub fn supports_streaming_fallback( &self ) -> bool
  {
    self.supports_streaming_fallback
  }
}

impl NetworkErrorClassifier
{
  /// Classify network error
  ///
  /// # Errors
  ///
  /// Returns an error if classification is not yet implemented
  pub fn classify( _error : &NetworkError ) -> AnthropicResult< NetworkErrorClassification >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "NetworkErrorClassifier not fully implemented".to_string() ) )
  }
}

impl NetworkErrorClassification
{
  /// Get error type
  #[ must_use ]
  pub fn error_type( &self ) -> NetworkErrorType
  {
    self.error_type.clone()
  }

  /// Check if infrastructure related
  #[ must_use ]
  pub fn is_infrastructure_related( &self ) -> bool
  {
    self.is_infrastructure_related
  }

  /// Check if security related
  #[ must_use ]
  pub fn is_security_related( &self ) -> bool
  {
    self.is_security_related
  }

  /// Check if service availability related
  #[ must_use ]
  pub fn is_service_availability_related( &self ) -> bool
  {
    self.is_service_availability_related
  }

  /// Get suggested actions
  #[ must_use ]
  pub fn suggested_actions( &self ) -> &Vec< String >
  {
    &self.suggested_actions
  }

  /// Check if supports retry with backoff
  #[ must_use ]
  pub fn supports_retry_with_backoff( &self ) -> bool
  {
    self.supports_retry_with_backoff
  }
}

impl BackoffCalculator
{
  /// Calculate backoff strategy
  ///
  /// # Errors
  ///
  /// Returns an error if calculation fails
  #[ cfg( feature = "retry-logic" ) ]
  pub fn calculate_backoff( error : &RateLimitError ) -> AnthropicResult< BackoffStrategyDetails >
  {
    let base_delay = if let Some( retry_after ) = error.retry_after()
    {
      // Respect retry-after header
      ( *retry_after * 1000 ).max( 1000 ) // At least 1 second
    }
    else
    {
      // Default backoff based on limit type
      match error.limit_type()
      {
        "authentication" => 5000,  // 5 seconds for auth limits
        "tokens" => 2000,          // 2 seconds for token limits
        _ => 1000,                 // Default 1 second including requests
      }
    };

    let strategy = BackoffStrategyDetails {
      initial_delay : Duration::from_millis( base_delay ),
      backoff_type : BackoffType::Linear,
      max_retries : 5,
      jitter_enabled : true,
      suggested_batch_size_reduction : Some( 0.5 ),
    };

    Ok( strategy )
  }

  /// Fallback implementation when retry-logic feature is not enabled
  ///
  /// # Errors
  ///
  /// Always returns `NotImplemented` error when retry-logic feature is disabled
  #[ cfg( not( feature = "retry-logic" ) ) ]
  pub fn calculate_backoff( _error : &RateLimitError ) -> AnthropicResult< BackoffStrategyDetails >
  {
    Err( AnthropicError::NotImplemented( "BackoffCalculator requires retry-logic feature".to_string() ) )
  }
}

impl BackoffStrategyDetails
{
  /// Get initial delay
  #[ must_use ]
  pub fn initial_delay( &self ) -> Duration
  {
    self.initial_delay
  }

  /// Get backoff type
  #[ must_use ]
  pub fn backoff_type( &self ) -> BackoffType
  {
    self.backoff_type.clone()
  }

  /// Get max retries
  #[ must_use ]
  pub fn max_retries( &self ) -> u32
  {
    self.max_retries
  }

  /// Check if jitter enabled
  #[ must_use ]
  pub fn jitter_enabled( &self ) -> bool
  {
    self.jitter_enabled
  }

  /// Get suggested batch size reduction
  #[ must_use ]
  pub fn suggested_batch_size_reduction( &self ) -> &Option< f32 >
  {
    &self.suggested_batch_size_reduction
  }
}

impl CredentialHintGenerator
{
  /// Generate credential hints
  ///
  /// # Errors
  ///
  /// Returns an error if hint generation is not yet implemented
  pub fn generate_hints( _error : &AuthenticationError ) -> AnthropicResult< CredentialHints >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "CredentialHintGenerator not fully implemented".to_string() ) )
  }
}

impl CredentialHints
{
  /// Get remediation steps
  #[ must_use ]
  pub fn remediation_steps( &self ) -> &Vec< String >
  {
    &self.remediation_steps
  }

  /// Check if has format example
  #[ must_use ]
  pub fn has_format_example( &self ) -> bool
  {
    self.has_format_example
  }

  /// Get documentation link
  #[ must_use ]
  pub fn documentation_link( &self ) -> Option< &String >
  {
    self.documentation_link.as_ref()
  }

  /// Check if requires renewal
  #[ must_use ]
  pub fn requires_renewal( &self ) -> bool
  {
    self.requires_renewal
  }

  /// Get renewal instructions
  #[ must_use ]
  pub fn renewal_instructions( &self ) -> Option< &String >
  {
    self.renewal_instructions.as_ref()
  }

  /// Get estimated resolution time
  #[ must_use ]
  pub fn estimated_resolution_time( &self ) -> Option< &Duration >
  {
    self.estimated_resolution_time.as_ref()
  }

  /// Check if permission upgrade required
  #[ must_use ]
  pub fn permission_upgrade_required( &self ) -> bool
  {
    self.permission_upgrade_required
  }

  /// Get required permissions
  #[ must_use ]
  pub fn required_permissions( &self ) -> Option< &Vec< String > >
  {
    self.required_permissions.as_ref()
  }

  /// Get upgrade instructions
  #[ must_use ]
  pub fn upgrade_instructions( &self ) -> Option< &String >
  {
    self.upgrade_instructions.as_ref()
  }
}

impl ErrorSerializer
{
  /// Serialize error to JSON
  ///
  /// # Errors
  ///
  /// Returns an error if serialization is not yet implemented
  pub fn serialize( _error : &EnhancedAnthropicError ) -> AnthropicResult< String >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorSerializer not fully implemented".to_string() ) )
  }

  /// Deserialize error from JSON
  ///
  /// # Errors
  ///
  /// Returns an error if deserialization is not yet implemented
  pub fn deserialize( _json : &str ) -> AnthropicResult< EnhancedAnthropicError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorSerializer not fully implemented".to_string() ) )
  }
}

impl ErrorLogger
{
  /// Create new error logger
  #[ must_use ]
  pub fn new() -> Self
  {
    Self
  }

  /// Log error with structured data
  ///
  /// # Errors
  ///
  /// Returns an error if logging is not yet implemented
  pub fn log_error( &self, _error : &AnthropicError ) -> AnthropicResult< LogEntry >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorLogger not fully implemented".to_string() ) )
  }
}

impl Default for ErrorLogger
{
  fn default() -> Self
  {
    Self::new()
  }
}

impl LogEntry
{
  /// Check if has structured data
  #[ must_use ]
  pub fn has_structured_data( &self ) -> bool
  {
    !self.structured_data.is_empty()
  }

  /// Get severity
  #[ must_use ]
  pub fn severity( &self ) -> LogSeverity
  {
    self.severity.clone()
  }

  /// Check if contains field
  #[ must_use ]
  pub fn contains_field( &self, field : &str ) -> bool
  {
    self.structured_data.contains_key( field )
  }
}

impl ErrorMetrics
{
  /// Create new error metrics
  #[ must_use ]
  pub fn new() -> Self
  {
    Self
    {
      error_counts : std::collections::HashMap::new(),
      alert_thresholds : std::collections::HashMap::new(),
    }
  }

  /// Report error
  ///
  /// # Errors
  ///
  /// Returns an error if metrics reporting is not yet implemented
  pub fn report_error( &mut self, _error : &AnthropicError ) -> AnthropicResult< () >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorMetrics not fully implemented".to_string() ) )
  }

  /// Get error count
  #[ must_use ]
  pub fn error_count( &self, error_type : &str ) -> u64
  {
    self.error_counts.get( error_type ).copied().unwrap_or( 0 )
  }

  /// Check if has alert thresholds
  #[ must_use ]
  pub fn has_alert_thresholds( &self ) -> bool
  {
    !self.alert_thresholds.is_empty()
  }
}

impl Default for ErrorMetrics
{
  fn default() -> Self
  {
    Self::new()
  }
}

impl CorrelationTracker
{
  /// Create correlation tracker from error
  ///
  /// # Errors
  ///
  /// Returns an error if correlation tracking is not yet implemented
  pub fn from_error( _error : &AnthropicError ) -> AnthropicResult< CorrelationTracker >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "CorrelationTracker not fully implemented".to_string() ) )
  }

  /// Get correlation summary
  ///
  /// # Errors
  ///
  /// Returns an error if correlation summary retrieval is not yet implemented
  pub fn get_summary( _correlation_id : &str ) -> AnthropicResult< CorrelationSummary >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "CorrelationTracker not fully implemented".to_string() ) )
  }

  /// Get correlation ID
  #[ must_use ]
  pub fn correlation_id( &self ) -> &'static str
  {
    "test_correlation_id"
  }

  /// Get request sequence
  #[ must_use ]
  pub fn request_sequence( &self ) -> usize
  {
    1
  }

  /// Check if has related errors
  #[ must_use ]
  pub fn has_related_errors( &self ) -> bool
  {
    true
  }
}

impl CorrelationSummary
{
  /// Get total requests
  #[ must_use ]
  pub fn total_requests( &self ) -> u32
  {
    self.total_requests
  }

  /// Get failed requests
  #[ must_use ]
  pub fn failed_requests( &self ) -> u32
  {
    self.failed_requests
  }

  /// Get error patterns
  #[ must_use ]
  pub fn error_patterns( &self ) -> &Vec< String >
  {
    &self.error_patterns
  }
}

impl ErrorLocalizer
{
  /// Localize error message
  ///
  /// # Errors
  ///
  /// Returns an error if localization is not yet implemented
  pub fn localize( _error : &AnthropicError, _locale : &str ) -> AnthropicResult< LocalizedError >
  {
    // Simplified implementation
    Err( AnthropicError::NotImplemented( "ErrorLocalizer not fully implemented".to_string() ) )
  }
}

impl LocalizedError
{
  /// Get message
  #[ must_use ]
  pub fn message( &self ) -> &str
  {
    &self.message
  }

  /// Get locale
  #[ must_use ]
  pub fn locale( &self ) -> &str
  {
    &self.locale
  }
}