1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Batch processing service client.
//!
//! Provides gRPC clients for managing asynchronous batch processing of requests
//! at lower priority than the chat service, including creating batches, adding requests,
//! monitoring progress, and retrieving results.
pub mod client {
use crate::common;
use crate::common::interceptor::ClientInterceptor;
use crate::export::service::{Interceptor, interceptor::InterceptedService};
use crate::export::transport::{Channel, Error};
use crate::xai_api::batch_mgmt_client::BatchMgmtClient as XBatchMgmtClient;
pub type BatchClient = XBatchMgmtClient<InterceptedService<Channel, ClientInterceptor>>;
/// Creates a new authenticated `BatchClient` connected to the xAI API.
///
/// Establishes a secure TLS connection with Bearer token authentication.
///
/// # Arguments
/// * `api_key` - Valid xAI API key for authentication
///
/// # Returns
/// * `Result<BatchClient, Error>` - Connected client or transport error
///
pub async fn new(api_key: &str) -> Result<BatchClient, Error> {
let channel = common::channel::new().await?;
let auth_intercept = common::interceptor::auth(api_key);
let client = XBatchMgmtClient::with_interceptor(channel, auth_intercept);
Ok(client)
}
/// Creates a new authenticated `BatchClient` using an existing gRPC channel.
///
/// Useful for sharing connections across multiple service clients.
///
/// # Arguments
/// * `channel` - Existing TLS-secured gRPC channel to xAI API
/// * `api_key` - Valid xAI API key for authentication
///
/// # Returns
/// * `BatchClient` - Authenticated client using the provided channel
pub fn with_channel(channel: Channel, api_key: &str) -> BatchClient {
let auth_intercept = common::interceptor::auth(api_key);
let client = XBatchMgmtClient::with_interceptor(channel, auth_intercept);
client
}
/// Creates a new `BatchClient` with a custom interceptor.
///
/// Creates a new TLS connection but uses the provided interceptor instead of
/// the default authentication interceptor.
///
/// # Arguments
/// * `interceptor` - Custom request interceptor (must handle authentication)
///
/// # Returns
/// * `Result<BatchClient, Error>` - Intercepted client or connection error
///
pub async fn with_interceptor(
interceptor: impl Interceptor + Send + Sync + 'static,
) -> Result<BatchClient, Error> {
let channel = common::channel::new().await?;
let client =
XBatchMgmtClient::with_interceptor(channel, ClientInterceptor::new(interceptor));
Ok(client)
}
/// Creates a new `BatchClient` with an existing channel and custom interceptor.
///
/// Combines a shared channel with custom request interception.
///
/// # Arguments
/// * `channel` - Existing TLS-secured gRPC channel to xAI API
/// * `interceptor` - Custom request interceptor (must handle authentication)
///
/// # Returns
/// * `BatchClient` - Intercepted client using the provided channel
pub fn with_channel_and_interceptor(
channel: Channel,
interceptor: impl Interceptor + Send + Sync + 'static,
) -> BatchClient {
XBatchMgmtClient::with_interceptor(channel, ClientInterceptor::new(interceptor))
}
}