pub struct BatchApi { /* private fields */ }Expand description
Batch API client.
Implementations§
Source§impl BatchApi
impl BatchApi
Sourcepub async fn create(&self, name: impl Into<String>) -> Result<Batch>
pub async fn create(&self, name: impl Into<String>) -> Result<Batch>
Create a new batch.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let batch = client.batch().create("my-batch").await?;
println!("Created batch: {}", batch.id);Sourcepub async fn get(&self, batch_id: impl AsRef<str>) -> Result<Batch>
pub async fn get(&self, batch_id: impl AsRef<str>) -> Result<Batch>
Get batch information by ID.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let batch = client.batch().get("batch-123").await?;
println!("Status: {:?}", batch.status);Sourcepub async fn list(&self) -> Result<BatchListResponse>
pub async fn list(&self) -> Result<BatchListResponse>
List all batches.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let response = client.batch().list().await?;
for batch in response.data {
println!("{}: {:?}", batch.name, batch.status);
}Sourcepub async fn list_with_options(
&self,
limit: Option<u32>,
next_token: Option<&str>,
) -> Result<BatchListResponse>
pub async fn list_with_options( &self, limit: Option<u32>, next_token: Option<&str>, ) -> Result<BatchListResponse>
List batches with pagination options.
Sourcepub async fn cancel(&self, batch_id: impl AsRef<str>) -> Result<Batch>
pub async fn cancel(&self, batch_id: impl AsRef<str>) -> Result<Batch>
Cancel a batch.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let batch = client.batch().cancel("batch-123").await?;
println!("Cancelled: {:?}", batch.status);Sourcepub async fn add_requests(
&self,
batch_id: impl AsRef<str>,
requests: Vec<BatchRequest>,
) -> Result<()>
pub async fn add_requests( &self, batch_id: impl AsRef<str>, requests: Vec<BatchRequest>, ) -> Result<()>
Add requests to a batch.
§Example
use xai_rust::{XaiClient, BatchRequest};
use xai_rust::chat::{user, system};
let client = XaiClient::from_env()?;
let requests = vec![
BatchRequest::new("req-1", "grok-4")
.message(user("Hello!")),
BatchRequest::new("req-2", "grok-4")
.message(user("How are you?")),
];
client.batch().add_requests("batch-123", requests).await?;Sourcepub async fn list_requests(
&self,
batch_id: impl AsRef<str>,
) -> Result<BatchRequestListResponse>
pub async fn list_requests( &self, batch_id: impl AsRef<str>, ) -> Result<BatchRequestListResponse>
List requests in a batch.
Sourcepub async fn list_requests_with_options(
&self,
batch_id: impl AsRef<str>,
limit: Option<u32>,
next_token: Option<&str>,
) -> Result<BatchRequestListResponse>
pub async fn list_requests_with_options( &self, batch_id: impl AsRef<str>, limit: Option<u32>, next_token: Option<&str>, ) -> Result<BatchRequestListResponse>
List requests in a batch with pagination options.
Sourcepub async fn list_results(
&self,
batch_id: impl AsRef<str>,
) -> Result<BatchResultListResponse>
pub async fn list_results( &self, batch_id: impl AsRef<str>, ) -> Result<BatchResultListResponse>
List results of a batch.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let results = client.batch().list_results("batch-123").await?;
for result in results.data {
if result.is_success() {
println!("{}: {}", result.custom_id, result.text().unwrap_or_default());
} else {
println!("{}: Error - {:?}", result.custom_id, result.error_message);
}
}Sourcepub async fn list_results_with_options(
&self,
batch_id: impl AsRef<str>,
limit: Option<u32>,
next_token: Option<&str>,
) -> Result<BatchResultListResponse>
pub async fn list_results_with_options( &self, batch_id: impl AsRef<str>, limit: Option<u32>, next_token: Option<&str>, ) -> Result<BatchResultListResponse>
List results of a batch with pagination options.
Sourcepub async fn get_result(
&self,
batch_id: impl AsRef<str>,
request_id: impl AsRef<str>,
) -> Result<BatchResult>
pub async fn get_result( &self, batch_id: impl AsRef<str>, request_id: impl AsRef<str>, ) -> Result<BatchResult>
Get a specific result by request ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchApi
impl !RefUnwindSafe for BatchApi
impl Send for BatchApi
impl Sync for BatchApi
impl Unpin for BatchApi
impl UnsafeUnpin for BatchApi
impl !UnwindSafe for BatchApi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more