paladin-llm 0.4.2

LLM provider adapters for the Paladin framework — OpenAI, Anthropic, DeepSeek, and mock
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
//! Anthropic Claude Vision Extension
//!
//! Extends [`AnthropicAdapter`] with vision capabilities for Claude 3+ models.
//! Supports Claude 3 Opus, Sonnet, Haiku and Claude 3.5 variants with
//! multimodal content blocks.
//!
//! **Note**: Anthropic requires all images to be base64-encoded.
//! URL and file-path images are automatically downloaded/read and converted.

use async_trait::async_trait;
use base64::{Engine as _, engine::general_purpose};
use chrono::Utc;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use std::path::Path;
use tokio::fs;

use paladin_core::platform::container::vision::{VisionContent, VisionError, VisionRequest};
use paladin_ports::output::llm_port::{
    FinishReason, LlmError, LlmRequest, LlmResponse, TokenUsage,
};
use paladin_ports::output::vision_llm_port::VisionCapableLlm;
use paladin_ports::output::vision_port::{VisionPort, VisionResult, VisionTokenUsage};

use super::adapter::AnthropicAdapter;

// ── Vision config (defaults) ──────────────────────────────────────────────────

/// Maximum tokens for Anthropic vision responses when not configured elsewhere.
const DEFAULT_MAX_TOKENS: usize = 4096;
/// Maximum retry attempts for transient errors.
const DEFAULT_MAX_RETRIES: u32 = 3;
/// Initial backoff in milliseconds.
const DEFAULT_INITIAL_BACKOFF_MS: u64 = 1000;
/// Exponential backoff multiplier.
const DEFAULT_BACKOFF_MULTIPLIER: f64 = 2.0;

// ── Anthropic multimodal message types ───────────────────────────────────────

/// Anthropic content block for multimodal messages.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
enum ClaudeContentBlock {
    Text { text: String },
    Image { source: ClaudeImageSource },
}

/// Anthropic image source (base64 encoding only).
#[derive(Debug, Serialize, Deserialize, Clone)]
struct ClaudeImageSource {
    #[serde(rename = "type")]
    source_type: String, // always "base64"
    media_type: String,
    data: String,
}

/// Anthropic vision message.
#[derive(Debug, Serialize)]
struct ClaudeVisionMessage {
    role: String,
    content: Vec<ClaudeContentBlock>,
}

/// Anthropic vision API request.
#[derive(Debug, Serialize)]
struct ClaudeVisionApiRequest {
    model: String,
    messages: Vec<ClaudeVisionMessage>,
    max_tokens: usize,
}

/// Anthropic vision API response.
#[derive(Debug, Deserialize)]
struct ClaudeVisionApiResponse {
    #[allow(dead_code)]
    id: String,
    model: String,
    content: Vec<ClaudeResponseContent>,
    usage: ClaudeVisionUsage,
    stop_reason: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
enum ClaudeResponseContent {
    Text { text: String },
}

#[derive(Debug, Deserialize)]
struct ClaudeVisionUsage {
    input_tokens: u32,
    output_tokens: u32,
}

#[derive(Debug, Deserialize)]
struct ClaudeErrorResponse {
    error: ClaudeErrorDetails,
}

#[derive(Debug, Deserialize)]
struct ClaudeErrorDetails {
    message: String,
    #[allow(dead_code)]
    #[serde(rename = "type")]
    error_type: String,
}

/// Vision-capable Claude 3+ models.
const VISION_MODELS: &[&str] = &[
    "claude-3-opus-20240229",
    "claude-3-sonnet-20240229",
    "claude-3-haiku-20240307",
    "claude-3-5-sonnet-20240620",
    "claude-3-5-sonnet-20241022",
    "claude-3-5-haiku-20241022",
];

// ── AnthropicAdapter vision helper methods ────────────────────────────────────

impl AnthropicAdapter {
    /// Returns `true` if the given model supports vision.
    pub fn is_vision_model(model: &str) -> bool {
        VISION_MODELS.contains(&model)
    }

    fn calculate_backoff_delay(
        retry_attempt: u32,
        initial_backoff_ms: u64,
        backoff_multiplier: f64,
    ) -> u64 {
        let delay = initial_backoff_ms as f64 * backoff_multiplier.powi(retry_attempt as i32);
        delay as u64
    }

    fn is_transient_error(status: StatusCode) -> bool {
        matches!(
            status,
            StatusCode::TOO_MANY_REQUESTS
                | StatusCode::INTERNAL_SERVER_ERROR
                | StatusCode::BAD_GATEWAY
                | StatusCode::SERVICE_UNAVAILABLE
                | StatusCode::GATEWAY_TIMEOUT
        )
    }

    fn map_status_to_vision_error(status: StatusCode, message: String) -> VisionError {
        match status {
            StatusCode::BAD_REQUEST => VisionError::InvalidImage(message),
            StatusCode::UNAUTHORIZED => VisionError::AuthenticationError(message),
            StatusCode::TOO_MANY_REQUESTS => VisionError::RateLimitExceeded(message),
            StatusCode::INTERNAL_SERVER_ERROR
            | StatusCode::BAD_GATEWAY
            | StatusCode::SERVICE_UNAVAILABLE
            | StatusCode::GATEWAY_TIMEOUT => VisionError::ProviderError(message),
            _ => VisionError::ProviderError(format!("HTTP {}: {}", status.as_u16(), message)),
        }
    }

    async fn execute_vision_request(
        &self,
        request_body: ClaudeVisionApiRequest,
    ) -> Result<ClaudeVisionApiResponse, VisionError> {
        let mut last_error: Option<VisionError> = None;

        for attempt in 0..=DEFAULT_MAX_RETRIES {
            let mut headers = reqwest::header::HeaderMap::new();
            headers.insert(
                "x-api-key",
                reqwest::header::HeaderValue::from_str(&self.config.api_key).map_err(|e| {
                    VisionError::AuthenticationError(format!("Invalid API key: {}", e))
                })?,
            );
            headers.insert(
                "anthropic-version",
                reqwest::header::HeaderValue::from_static("2023-06-01"),
            );
            headers.insert(
                "content-type",
                reqwest::header::HeaderValue::from_static("application/json"),
            );

            let response = self
                .client
                .post(format!("{}/messages", self.config.base_url))
                .headers(headers)
                .json(&request_body)
                .send()
                .await
                .map_err(|e| VisionError::NetworkError(format!("Request failed: {}", e)))?;

            let status = response.status();

            if status.is_success() {
                let api_response: ClaudeVisionApiResponse = response.json().await.map_err(|e| {
                    VisionError::ProviderError(format!("Failed to parse response: {}", e))
                })?;
                return Ok(api_response);
            }

            let error_text = response
                .text()
                .await
                .unwrap_or_else(|_| "Failed to read error response".to_string());

            let error_message =
                if let Ok(err) = serde_json::from_str::<ClaudeErrorResponse>(&error_text) {
                    err.error.message
                } else {
                    error_text
                };

            let error = Self::map_status_to_vision_error(status, error_message);

            if attempt < DEFAULT_MAX_RETRIES && Self::is_transient_error(status) {
                last_error = Some(error);
                let delay_ms = Self::calculate_backoff_delay(
                    attempt,
                    DEFAULT_INITIAL_BACKOFF_MS,
                    DEFAULT_BACKOFF_MULTIPLIER,
                );
                tokio::time::sleep(tokio::time::Duration::from_millis(delay_ms)).await;
                continue;
            }

            return Err(error);
        }

        Err(last_error.unwrap_or(VisionError::MaxRetriesExceeded(DEFAULT_MAX_RETRIES)))
    }

    async fn convert_vision_content(
        &self,
        content: &VisionContent,
    ) -> Result<ClaudeContentBlock, LlmError> {
        match content {
            VisionContent::ImageUrl { url, .. } => {
                let (data, media_type) = Self::download_and_encode_image(url).await?;
                Ok(ClaudeContentBlock::Image {
                    source: ClaudeImageSource {
                        source_type: "base64".to_string(),
                        media_type,
                        data,
                    },
                })
            }
            VisionContent::ImageBase64 {
                data, media_type, ..
            } => Ok(ClaudeContentBlock::Image {
                source: ClaudeImageSource {
                    source_type: "base64".to_string(),
                    media_type: media_type.clone(),
                    data: data.clone(),
                },
            }),
            VisionContent::ImageFile { path, .. } => {
                let image_data = fs::read(path).await.map_err(|e| {
                    LlmError::ProcessingError(format!("Failed to read image file: {}", e))
                })?;
                let media_type = Self::detect_mime_type(path)?;
                let base64_data = general_purpose::STANDARD.encode(&image_data);
                Ok(ClaudeContentBlock::Image {
                    source: ClaudeImageSource {
                        source_type: "base64".to_string(),
                        media_type,
                        data: base64_data,
                    },
                })
            }
        }
    }

    async fn download_and_encode_image(url: &str) -> Result<(String, String), LlmError> {
        let response = reqwest::get(url)
            .await
            .map_err(|e| LlmError::NetworkError(format!("Failed to download image: {}", e)))?;

        if !response.status().is_success() {
            return Err(LlmError::NetworkError(format!(
                "Image download failed with status: {}",
                response.status()
            )));
        }

        let media_type = response
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("image/jpeg")
            .to_string();

        if !media_type.starts_with("image/") {
            return Err(LlmError::InvalidPrompt(format!(
                "URL does not point to an image. Content-Type: {}",
                media_type
            )));
        }

        let image_bytes = response
            .bytes()
            .await
            .map_err(|e| LlmError::NetworkError(format!("Failed to read image data: {}", e)))?;

        Ok((general_purpose::STANDARD.encode(&image_bytes), media_type))
    }

    /// Detect MIME type from a file extension.
    pub fn detect_mime_type(path: &Path) -> Result<String, LlmError> {
        let extension = path
            .extension()
            .and_then(|ext| ext.to_str())
            .ok_or_else(|| LlmError::InvalidPrompt("Image file has no extension".to_string()))?
            .to_lowercase();

        match extension.as_str() {
            "jpg" | "jpeg" => Ok("image/jpeg".to_string()),
            "png" => Ok("image/png".to_string()),
            "gif" => Ok("image/gif".to_string()),
            "webp" => Ok("image/webp".to_string()),
            other => Err(LlmError::InvalidPrompt(format!(
                "Unsupported image format: {}",
                other
            ))),
        }
    }

    async fn build_vision_content_blocks(
        &self,
        request: &LlmRequest,
        vision: &VisionRequest,
    ) -> Result<Vec<ClaudeContentBlock>, LlmError> {
        if !Self::is_vision_model(&request.model) {
            return Err(LlmError::ModelNotAvailable(format!(
                "Model {} does not support vision. Supported models: {}",
                request.model,
                VISION_MODELS.join(", ")
            )));
        }

        let mut content_blocks = vec![];

        if !vision.text.is_empty() {
            content_blocks.push(ClaudeContentBlock::Text {
                text: vision.text.clone(),
            });
        }

        for image in &vision.images {
            content_blocks.push(self.convert_vision_content(image).await?);
        }

        Ok(content_blocks)
    }
}

// ── VisionCapableLlm impl ─────────────────────────────────────────────────────

#[async_trait]
impl VisionCapableLlm for AnthropicAdapter {
    async fn generate_with_vision(
        &self,
        request: LlmRequest,
        vision: VisionRequest,
    ) -> Result<LlmResponse, LlmError> {
        let content_blocks = self.build_vision_content_blocks(&request, &vision).await?;

        let request_body = ClaudeVisionApiRequest {
            model: request.model.clone(),
            messages: vec![ClaudeVisionMessage {
                role: "user".to_string(),
                content: content_blocks,
            }],
            max_tokens: DEFAULT_MAX_TOKENS,
        };

        let api_response =
            self.execute_vision_request(request_body)
                .await
                .map_err(|e| match e {
                    VisionError::InvalidImage(msg) => LlmError::InvalidPrompt(msg),
                    VisionError::AuthenticationError(msg) => LlmError::AuthenticationError(msg),
                    VisionError::RateLimitExceeded(msg) => {
                        LlmError::ProcessingError(format!("Rate limit exceeded: {}", msg))
                    }
                    VisionError::NetworkError(msg) => LlmError::NetworkError(msg),
                    VisionError::ProviderError(msg) | VisionError::UnsupportedProvider(msg) => {
                        LlmError::ProcessingError(msg)
                    }
                    VisionError::Timeout(seconds) => {
                        LlmError::Timeout(format!("{} seconds", seconds))
                    }
                    VisionError::MaxRetriesExceeded(attempts) => LlmError::ProcessingError(
                        format!("Max retries exceeded: {} attempts", attempts),
                    ),
                    _ => LlmError::ProcessingError(format!("Vision error: {}", e)),
                })?;

        let content = api_response
            .content
            .iter()
            .map(|block| match block {
                ClaudeResponseContent::Text { text } => text.clone(),
            })
            .next()
            .ok_or_else(|| LlmError::ProcessingError("No text content in response".to_string()))?;

        let finish_reason = api_response
            .stop_reason
            .as_deref()
            .map(|reason| match reason {
                "end_turn" | "stop_sequence" => FinishReason::Stop,
                "max_tokens" => FinishReason::Length,
                other => FinishReason::Error(other.to_string()),
            })
            .unwrap_or(FinishReason::Stop);

        Ok(LlmResponse {
            id: uuid::Uuid::new_v4(),
            request_id: request.id,
            model: api_response.model,
            content,
            finish_reason,
            usage: TokenUsage {
                prompt_tokens: api_response.usage.input_tokens,
                completion_tokens: api_response.usage.output_tokens,
                total_tokens: api_response.usage.input_tokens + api_response.usage.output_tokens,
            },
            created_at: Utc::now(),
            metadata: Default::default(),
            function_call: None,
        })
    }

    fn supports_vision(&self) -> bool {
        true
    }
}

// ── VisionPort impl ───────────────────────────────────────────────────────────

#[async_trait]
impl VisionPort for AnthropicAdapter {
    async fn analyze_image(
        &self,
        prompt: &str,
        images: Vec<VisionContent>,
        model: &str,
        max_tokens: Option<u32>,
    ) -> Result<VisionResult, VisionError> {
        if !Self::is_vision_model(model) {
            return Err(VisionError::ModelNotSupported(format!(
                "Model {} does not support vision",
                model
            )));
        }

        if images.is_empty() {
            return Err(VisionError::InvalidRequest(
                "At least one image must be provided".to_string(),
            ));
        }

        let mut content_blocks = vec![ClaudeContentBlock::Text {
            text: prompt.to_string(),
        }];

        for image in images {
            let block = self.convert_vision_content(&image).await.map_err(|e| {
                VisionError::InvalidRequest(format!("Failed to convert image: {}", e))
            })?;
            content_blocks.push(block);
        }

        let request_body = ClaudeVisionApiRequest {
            model: model.to_string(),
            messages: vec![ClaudeVisionMessage {
                role: "user".to_string(),
                content: content_blocks,
            }],
            max_tokens: max_tokens.unwrap_or(1000) as usize,
        };

        let response = self.execute_vision_request(request_body).await?;

        let content = response
            .content
            .iter()
            .map(|block| match block {
                ClaudeResponseContent::Text { text } => text.clone(),
            })
            .next()
            .ok_or_else(|| {
                VisionError::InvalidRequest("No text content in response".to_string())
            })?;

        Ok(VisionResult {
            content,
            model: response.model,
            token_usage: VisionTokenUsage {
                prompt_tokens: response.usage.input_tokens,
                completion_tokens: response.usage.output_tokens,
                total_tokens: response.usage.input_tokens + response.usage.output_tokens,
            },
            metadata: std::collections::HashMap::new(),
            timestamp: chrono::Utc::now(),
        })
    }

    fn is_vision_model(&self, model: &str) -> bool {
        Self::is_vision_model(model)
    }

    fn provider_name(&self) -> &str {
        "anthropic"
    }
}

// ── Tests ─────────────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;
    use paladin_core::platform::container::vision::ImageDetail;
    use std::path::Path;

    fn create_test_adapter() -> AnthropicAdapter {
        let config = super::super::adapter::AnthropicConfig::new(
            "sk-ant-test-key".to_string(),
            "https://api.anthropic.com/v1".to_string(),
            "claude-3-opus-20240229".to_string(),
            4096,
        );
        AnthropicAdapter::new(config).unwrap()
    }

    #[test]
    fn test_is_vision_model() {
        assert!(AnthropicAdapter::is_vision_model("claude-3-opus-20240229"));
        assert!(AnthropicAdapter::is_vision_model(
            "claude-3-sonnet-20240229"
        ));
        assert!(AnthropicAdapter::is_vision_model("claude-3-haiku-20240307"));
        assert!(AnthropicAdapter::is_vision_model(
            "claude-3-5-sonnet-20240620"
        ));
        assert!(AnthropicAdapter::is_vision_model(
            "claude-3-5-sonnet-20241022"
        ));
        assert!(AnthropicAdapter::is_vision_model(
            "claude-3-5-haiku-20241022"
        ));
        assert!(!AnthropicAdapter::is_vision_model("claude-2.1"));
        assert!(!AnthropicAdapter::is_vision_model("claude-instant-1.2"));
    }

    #[test]
    fn test_detect_mime_type() {
        assert_eq!(
            AnthropicAdapter::detect_mime_type(Path::new("test.jpg")).unwrap(),
            "image/jpeg"
        );
        assert_eq!(
            AnthropicAdapter::detect_mime_type(Path::new("test.jpeg")).unwrap(),
            "image/jpeg"
        );
        assert_eq!(
            AnthropicAdapter::detect_mime_type(Path::new("test.png")).unwrap(),
            "image/png"
        );
        assert_eq!(
            AnthropicAdapter::detect_mime_type(Path::new("test.gif")).unwrap(),
            "image/gif"
        );
        assert_eq!(
            AnthropicAdapter::detect_mime_type(Path::new("test.webp")).unwrap(),
            "image/webp"
        );
        assert!(AnthropicAdapter::detect_mime_type(Path::new("test.txt")).is_err());
        assert!(AnthropicAdapter::detect_mime_type(Path::new("test.bmp")).is_err());
    }

    #[tokio::test]
    async fn test_convert_vision_content_base64() {
        let adapter = create_test_adapter();
        let content = VisionContent::ImageBase64 {
            data: "abc123".to_string(),
            media_type: "image/png".to_string(),
            detail: ImageDetail::High,
        };
        let result = adapter.convert_vision_content(&content).await.unwrap();
        match result {
            ClaudeContentBlock::Image { source } => {
                assert_eq!(source.source_type, "base64");
                assert_eq!(source.media_type, "image/png");
                assert_eq!(source.data, "abc123");
            }
            _ => panic!("Expected Image content block"),
        }
    }

    #[tokio::test]
    async fn test_build_vision_content_blocks_non_vision_model() {
        let adapter = create_test_adapter();

        use paladin_core::platform::container::prompt::{PromptItem, PromptType, TextPrompt};
        use paladin_ports::output::llm_port::LlmRequest;
        use std::collections::HashMap;
        use uuid::Uuid;

        let llm_request = LlmRequest {
            id: Uuid::new_v4(),
            model: "claude-2.1".to_string(),
            prompt: PromptItem::new(PromptType::Text(TextPrompt {
                content: "test".to_string(),
                role: paladin_core::platform::container::prompt::PromptRole::User,
            }))
            .unwrap(),
            attachments: vec![],
            stream: false,
            metadata: HashMap::new(),
        };

        let vision = VisionRequest::new(
            "Describe this".to_string(),
            vec![VisionContent::ImageBase64 {
                data: "abc123".to_string(),
                media_type: "image/png".to_string(),
                detail: ImageDetail::Auto,
            }],
        )
        .unwrap();

        let result = adapter
            .build_vision_content_blocks(&llm_request, &vision)
            .await;
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            LlmError::ModelNotAvailable(_)
        ));
    }

    #[test]
    fn test_supports_vision() {
        let adapter = create_test_adapter();
        assert!(adapter.supports_vision());
    }

    #[test]
    fn test_calculate_backoff_delay() {
        assert_eq!(
            AnthropicAdapter::calculate_backoff_delay(0, 1000, 2.0),
            1000
        );
        assert_eq!(
            AnthropicAdapter::calculate_backoff_delay(1, 1000, 2.0),
            2000
        );
        assert_eq!(
            AnthropicAdapter::calculate_backoff_delay(2, 1000, 2.0),
            4000
        );
    }

    #[test]
    fn test_is_transient_error() {
        assert!(AnthropicAdapter::is_transient_error(
            StatusCode::TOO_MANY_REQUESTS
        ));
        assert!(AnthropicAdapter::is_transient_error(
            StatusCode::INTERNAL_SERVER_ERROR
        ));
        assert!(AnthropicAdapter::is_transient_error(
            StatusCode::SERVICE_UNAVAILABLE
        ));
        assert!(!AnthropicAdapter::is_transient_error(
            StatusCode::BAD_REQUEST
        ));
        assert!(!AnthropicAdapter::is_transient_error(
            StatusCode::UNAUTHORIZED
        ));
        assert!(!AnthropicAdapter::is_transient_error(StatusCode::OK));
    }
}