zai_rs/batches/
retrieve.rs

1use super::types::BatchItem;
2use crate::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 encoding.
18        let url = format!(
19            "https://open.bigmodel.cn/api/paas/v4/batches/{}",
20            batch_id.as_ref()
21        );
22        Self {
23            key,
24            url,
25            _body: (),
26        }
27    }
28
29    /// Send request and parse typed response as a single BatchItem
30    pub async fn send(&self) -> anyhow::Result<BatchesRetrieveResponse> {
31        let resp: reqwest::Response = self.get().await?;
32        let parsed = resp.json::<BatchesRetrieveResponse>().await?;
33        Ok(parsed)
34    }
35}
36
37impl HttpClient for BatchesRetrieveRequest {
38    type Body = ();
39    type ApiUrl = String;
40    type ApiKey = String;
41
42    fn api_url(&self) -> &Self::ApiUrl {
43        &self.url
44    }
45    fn api_key(&self) -> &Self::ApiKey {
46        &self.key
47    }
48    fn body(&self) -> &Self::Body {
49        &self._body
50    }
51}
52
53/// Response type: a single Batch object
54pub type BatchesRetrieveResponse = BatchItem;