Skip to main content

zai_rs/batches/
cancel.rs

1use super::types::BatchItem;
2use crate::{ZaiResult, client::ZaiClient};
3
4/// Cancel a running batch (POST /paas/v4/batches/{batch_id}/cancel)
5pub struct BatchCancelRequest {
6    batch_id: String,
7}
8
9impl BatchCancelRequest {
10    /// Create a new cancel request for the given batch_id
11    pub fn new(batch_id: impl Into<String>) -> Self {
12        Self {
13            batch_id: batch_id.into(),
14        }
15    }
16
17    /// Send the request via a [`ZaiClient`] and parse typed response
18    pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<BatchCancelResponse> {
19        crate::client::validation::require_non_blank(&self.batch_id, "batch_id")?;
20        let route = crate::client::routes::BATCHES_CANCEL;
21        let url = client.endpoints().resolve_route(route, &[&self.batch_id])?;
22        client
23            .send_empty::<BatchCancelResponse>(route.method(), url)
24            .await
25    }
26}
27
28/// Response type: a single Batch object
29pub type BatchCancelResponse = BatchItem;