Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
cloud_api_client: Add `create_llm_token` method (#35428)
Marshall Bowersaea1d481844f
diff --git a/crates/cloud_api_client/src/cloud_api_client.rs b/crates/cloud_api_client/src/cloud_api_client.rsindex 2d017cf2eea..5a768810c0f 100644--- a/crates/cloud_api_client/src/cloud_api_client.rs+++ b/crates/cloud_api_client/src/cloud_api_client.rs@@ -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)?)+ }}