Skip to main content

fastly_api/apis/
ai_runtime_control_providers_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_models_for_provider`]
15#[derive(Clone, Debug, Default)]
16pub struct ArcGetModelsForProviderParams {
17    /// The ID of the provider.
18    pub provider_id: String
19}
20
21
22/// struct for typed errors of method [`arc_get_bedrock_setup`]
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum ArcGetBedrockSetupError {
26    Status401(crate::models::ArcError),
27    Status403(crate::models::ArcError),
28    Status404(crate::models::ArcError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`arc_get_models_for_provider`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ArcGetModelsForProviderError {
36    Status401(crate::models::ArcError),
37    Status403(crate::models::ArcError),
38    Status404(crate::models::ArcError),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`arc_get_supported_providers`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ArcGetSupportedProvidersError {
46    Status401(crate::models::ArcError),
47    Status403(crate::models::ArcError),
48    UnknownValue(serde_json::Value),
49}
50
51
52/// Returns the AI Runtime Control IAM role Amazon Resource Name (ARN) and external ID to reference in your AWS account's IAM trust policy before creating an `aws-iam` [provider connection](https://www.fastly.com/documentation/reference/api/ai-runtime-control/provider-connections#arc-create-provider-connection) to Amazon Bedrock.  Requires AWS IAM authentication to be enabled on your account. If it isn't, this endpoint returns a 404 response. 
53pub async fn arc_get_bedrock_setup(configuration: &mut configuration::Configuration) -> Result<crate::models::ArcBedrockSetupResponse, Error<ArcGetBedrockSetupError>> {
54    let local_var_configuration = configuration;
55
56    // unbox the parameters
57
58
59    let local_var_client = &local_var_configuration.client;
60
61    let local_var_uri_str = format!("{}/ai-runtime-control/v1/providers/bedrock/setup", local_var_configuration.base_path);
62    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
63
64    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
65        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
66    }
67    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
68        let local_var_key = local_var_apikey.key.clone();
69        let local_var_value = match local_var_apikey.prefix {
70            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
71            None => local_var_key,
72        };
73        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
74    };
75
76    let local_var_req = local_var_req_builder.build()?;
77    let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79    if "GET" != "GET" && "GET" != "HEAD" {
80      let headers = local_var_resp.headers();
81      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
82          Some(v) => v.to_str().unwrap().parse().unwrap(),
83          None => configuration::DEFAULT_RATELIMIT,
84      };
85      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
86          Some(v) => v.to_str().unwrap().parse().unwrap(),
87          None => 0,
88      };
89    }
90
91    let local_var_status = local_var_resp.status();
92    let local_var_content = local_var_resp.text().await?;
93
94    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95        serde_json::from_str(&local_var_content).map_err(Error::from)
96    } else {
97        let local_var_entity: Option<ArcGetBedrockSetupError> = serde_json::from_str(&local_var_content).ok();
98        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102
103/// Returns the models available for a specific provider.
104pub async fn arc_get_models_for_provider(configuration: &mut configuration::Configuration, params: ArcGetModelsForProviderParams) -> Result<crate::models::ArcModelsResponse, Error<ArcGetModelsForProviderError>> {
105    let local_var_configuration = configuration;
106
107    // unbox the parameters
108    let provider_id = params.provider_id;
109
110
111    let local_var_client = &local_var_configuration.client;
112
113    let local_var_uri_str = format!("{}/ai-runtime-control/v1/providers/{provider_id}/models", local_var_configuration.base_path, provider_id=crate::apis::urlencode(provider_id));
114    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
115
116    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
117        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118    }
119    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
120        let local_var_key = local_var_apikey.key.clone();
121        let local_var_value = match local_var_apikey.prefix {
122            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
123            None => local_var_key,
124        };
125        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
126    };
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    if "GET" != "GET" && "GET" != "HEAD" {
132      let headers = local_var_resp.headers();
133      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
134          Some(v) => v.to_str().unwrap().parse().unwrap(),
135          None => configuration::DEFAULT_RATELIMIT,
136      };
137      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
138          Some(v) => v.to_str().unwrap().parse().unwrap(),
139          None => 0,
140      };
141    }
142
143    let local_var_status = local_var_resp.status();
144    let local_var_content = local_var_resp.text().await?;
145
146    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
147        serde_json::from_str(&local_var_content).map_err(Error::from)
148    } else {
149        let local_var_entity: Option<ArcGetModelsForProviderError> = serde_json::from_str(&local_var_content).ok();
150        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
151        Err(Error::ResponseError(local_var_error))
152    }
153}
154
155/// Returns the AI providers supported by AI Runtime Control, with each provider's available models nested within.
156pub async fn arc_get_supported_providers(configuration: &mut configuration::Configuration) -> Result<crate::models::ArcProvidersResponse, Error<ArcGetSupportedProvidersError>> {
157    let local_var_configuration = configuration;
158
159    // unbox the parameters
160
161
162    let local_var_client = &local_var_configuration.client;
163
164    let local_var_uri_str = format!("{}/ai-runtime-control/v1/providers", local_var_configuration.base_path);
165    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
166
167    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169    }
170    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
171        let local_var_key = local_var_apikey.key.clone();
172        let local_var_value = match local_var_apikey.prefix {
173            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
174            None => local_var_key,
175        };
176        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
177    };
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    if "GET" != "GET" && "GET" != "HEAD" {
183      let headers = local_var_resp.headers();
184      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
185          Some(v) => v.to_str().unwrap().parse().unwrap(),
186          None => configuration::DEFAULT_RATELIMIT,
187      };
188      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
189          Some(v) => v.to_str().unwrap().parse().unwrap(),
190          None => 0,
191      };
192    }
193
194    let local_var_status = local_var_resp.status();
195    let local_var_content = local_var_resp.text().await?;
196
197    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198        serde_json::from_str(&local_var_content).map_err(Error::from)
199    } else {
200        let local_var_entity: Option<ArcGetSupportedProvidersError> = serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
202        Err(Error::ResponseError(local_var_error))
203    }
204}
205