Skip to main content

rust_genai_types/
http.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4/// A wrapper class for the HTTP response (SDK only).
5///
6/// This is populated by the SDK (not returned by the backend API).
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct HttpResponse {
10    /// Processed HTTP headers.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub headers: Option<HashMap<String, String>>,
13    /// The raw HTTP response body, in JSON format (when available).
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub body: Option<String>,
16}
17
18/// HTTP retry options to be used in each of the requests.
19#[derive(Debug, Clone, Serialize, Deserialize, Default)]
20#[serde(rename_all = "camelCase")]
21pub struct HttpRetryOptions {
22    /// Maximum number of attempts, including the original request.
23    /// If 0 or 1, it means no retries. If not specified, defaults to 5.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub attempts: Option<u32>,
26    /// Initial delay before the first retry, in seconds. Defaults to 1.0.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub initial_delay: Option<f64>,
29    /// Maximum delay between retries, in seconds. Defaults to 60.0.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub max_delay: Option<f64>,
32    /// Multiplier by which the delay increases after each attempt. Defaults to 2.0.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub exp_base: Option<f64>,
35    /// Randomness factor for the delay, in seconds. Defaults to 1.0.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub jitter: Option<f64>,
38    /// List of HTTP status codes that should trigger a retry.
39    ///
40    /// If not specified, a default set of retryable codes (408, 429, and select 5xx) is used.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub http_status_codes: Option<Vec<u16>>,
43}
44
45/// HTTP options to be used in each of the requests.
46#[derive(Debug, Clone, Serialize, Deserialize, Default)]
47#[serde(rename_all = "camelCase")]
48pub struct HttpOptions {
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub base_url: Option<String>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub api_version: Option<String>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub headers: Option<HashMap<String, String>>,
55    /// Timeout for the request in milliseconds.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub timeout: Option<u64>,
58    /// Extra parameters to add to the request body.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub extra_body: Option<serde_json::Value>,
61    /// HTTP retry options for the request.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub retry_options: Option<HttpRetryOptions>,
64}