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:
Marshall Bowers 2025-07-31 17:01:21 -04:00 committed by GitHub
parent c946b98ea1
commit aea1d48184
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -80,4 +80,42 @@ impl CloudApiClient {
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)?)
}
}