cloud_api_client: Add create_llm_token
method (#35428)
This PR adds a `create_llm_token` method to the `CloudApiClient`. Release Notes: - N/A
This commit is contained in:
parent
c946b98ea1
commit
aea1d48184
1 changed files with 38 additions and 0 deletions
|
@ -80,4 +80,42 @@ impl CloudApiClient {
|
||||||
|
|
||||||
Ok(serde_json::from_str(&body)?)
|
Ok(serde_json::from_str(&body)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn create_llm_token(
|
||||||
|
&self,
|
||||||
|
system_id: Option<String>,
|
||||||
|
) -> Result<CreateLlmTokenResponse> {
|
||||||
|
let mut request_builder = Request::builder()
|
||||||
|
.method(Method::POST)
|
||||||
|
.uri(
|
||||||
|
self.http_client
|
||||||
|
.build_zed_cloud_url("/client/llm_tokens", &[])?
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Authorization", self.authorization_header()?);
|
||||||
|
|
||||||
|
if let Some(system_id) = system_id {
|
||||||
|
request_builder = request_builder.header(ZED_SYSTEM_ID_HEADER_NAME, system_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = request_builder.body(AsyncBody::default())?;
|
||||||
|
|
||||||
|
let mut response = self.http_client.send(request).await?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
let mut body = String::new();
|
||||||
|
response.body_mut().read_to_string(&mut body).await?;
|
||||||
|
|
||||||
|
anyhow::bail!(
|
||||||
|
"Failed to create LLM token.\nStatus: {:?}\nBody: {body}",
|
||||||
|
response.status()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut body = String::new();
|
||||||
|
response.body_mut().read_to_string(&mut body).await?;
|
||||||
|
|
||||||
|
Ok(serde_json::from_str(&body)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue