Skip to main content

fastly_api/apis/
ai_runtime_control_sessions_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`arc_get_session_logs`]
15#[derive(Clone, Debug, Default)]
16pub struct ArcGetSessionLogsParams {
17    /// Filter results to a specific virtual key ID.
18    pub key: Option<String>,
19    /// Filter results by AI provider connection ID.
20    pub provider: Option<String>,
21    /// Filter results by AI model identifier.
22    pub model: Option<String>,
23    /// The start of the time range, in RFC 3339 format.
24    pub from: Option<String>,
25    /// The end of the time range, in RFC 3339 format. Defaults to `now`.
26    pub to: Option<String>,
27    /// Cursor for pagination. Use the `next_cursor` value from a previous response to request the next page of results, or the `prev_cursor` value to request the previous page. 
28    pub cursor: Option<String>,
29    /// Limit how many results are returned.
30    pub limit: Option<i32>,
31    /// Sort field. Prefix with `-` for descending order (e.g., `sort=-created_at`). 
32    pub sort: Option<String>
33}
34
35
36/// struct for typed errors of method [`arc_get_session_logs`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum ArcGetSessionLogsError {
40    Status400(crate::models::ArcError),
41    Status401(crate::models::ArcError),
42    Status403(crate::models::ArcError),
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Returns session logs, including request and response data and metadata, for debugging and audit purposes.
48pub async fn arc_get_session_logs(configuration: &mut configuration::Configuration, params: ArcGetSessionLogsParams) -> Result<crate::models::ArcSessionsResponse, Error<ArcGetSessionLogsError>> {
49    let local_var_configuration = configuration;
50
51    // unbox the parameters
52    let key = params.key;
53    let provider = params.provider;
54    let model = params.model;
55    let from = params.from;
56    let to = params.to;
57    let cursor = params.cursor;
58    let limit = params.limit;
59    let sort = params.sort;
60
61
62    let local_var_client = &local_var_configuration.client;
63
64    let local_var_uri_str = format!("{}/ai-runtime-control/v1/sessions", local_var_configuration.base_path);
65    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
66
67    if let Some(ref local_var_str) = key {
68        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
69    }
70    if let Some(ref local_var_str) = provider {
71        local_var_req_builder = local_var_req_builder.query(&[("provider", &local_var_str.to_string())]);
72    }
73    if let Some(ref local_var_str) = model {
74        local_var_req_builder = local_var_req_builder.query(&[("model", &local_var_str.to_string())]);
75    }
76    if let Some(ref local_var_str) = from {
77        local_var_req_builder = local_var_req_builder.query(&[("from", &local_var_str.to_string())]);
78    }
79    if let Some(ref local_var_str) = to {
80        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
81    }
82    if let Some(ref local_var_str) = cursor {
83        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
84    }
85    if let Some(ref local_var_str) = limit {
86        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
87    }
88    if let Some(ref local_var_str) = sort {
89        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
90    }
91    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
92        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
93    }
94    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
95        let local_var_key = local_var_apikey.key.clone();
96        let local_var_value = match local_var_apikey.prefix {
97            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
98            None => local_var_key,
99        };
100        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
101    };
102
103    let local_var_req = local_var_req_builder.build()?;
104    let local_var_resp = local_var_client.execute(local_var_req).await?;
105
106    if "GET" != "GET" && "GET" != "HEAD" {
107      let headers = local_var_resp.headers();
108      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
109          Some(v) => v.to_str().unwrap().parse().unwrap(),
110          None => configuration::DEFAULT_RATELIMIT,
111      };
112      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
113          Some(v) => v.to_str().unwrap().parse().unwrap(),
114          None => 0,
115      };
116    }
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        serde_json::from_str(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<ArcGetSessionLogsError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129