Skip to main content

zai_rs/batches/
retrieve.rs

1use super::types::BatchItem;
2use crate::{ZaiResult, client::http::HttpClient};
3
4/// Retrieve a batch task by ID (GET /paas/v4/batches/{batch_id})
5pub struct BatchesRetrieveRequest {
6    /// Bearer API key
7    pub key: String,
8    /// Full URL with path parameter bound
9    url: String,
10    /// No body for GET
11    _body: (),
12}
13
14impl BatchesRetrieveRequest {
15    /// Create a new retrieve request with required path parameter `batch_id`.
16    pub fn new(key: String, batch_id: impl AsRef<str>) -> Self {
17        // Batch IDs are expected to be safe; if special chars appear, consider
18        // encoding.
19        let url = format!(
20            "https://open.bigmodel.cn/api/paas/v4/batches/{}",
21            batch_id.as_ref()
22        );
23        Self {
24            key,
25            url,
26            _body: (),
27        }
28    }
29
30    /// Send request and parse typed response as a single BatchItem
31    pub async fn send(&self) -> ZaiResult<BatchesRetrieveResponse> {
32        let resp: reqwest::Response = self.get().await?;
33        let parsed = resp.json::<BatchesRetrieveResponse>().await?;
34        Ok(parsed)
35    }
36}
37
38impl HttpClient for BatchesRetrieveRequest {
39    type Body = ();
40    type ApiUrl = String;
41    type ApiKey = String;
42
43    fn api_url(&self) -> &Self::ApiUrl {
44        &self.url
45    }
46    fn api_key(&self) -> &Self::ApiKey {
47        &self.key
48    }
49    fn body(&self) -> &Self::Body {
50        &self._body
51    }
52}
53
54/// Response type: a single Batch object
55pub type BatchesRetrieveResponse = BatchItem;