pub struct Client { /* private fields */ }Expand description
Unified Gemini API client.
Mirrors the GoogleGenAI class from @google/genai (js-genai).
Provides access to both Live (WebSocket) and REST APIs through a single
authenticated entry point.
§Construction
use gemini_genai_rs::Client;
// From API key (Google AI)
let client = Client::from_api_key("your-api-key");
// From Vertex AI credentials
let client = Client::from_vertex("project-id", "us-central1", "access-token");
// Live WebSocket session on the platform's default Live model
let session = client.live(None).connect().await?;Implementations§
Source§impl Client
impl Client
Sourcepub async fn list_batch_jobs(
&self,
) -> Result<ListBatchJobsResponse, BatchesError>
pub async fn list_batch_jobs( &self, ) -> Result<ListBatchJobsResponse, BatchesError>
List batch jobs.
Sourcepub async fn create_batch_job(
&self,
config: CreateBatchJobConfig,
) -> Result<BatchJob, BatchesError>
pub async fn create_batch_job( &self, config: CreateBatchJobConfig, ) -> Result<BatchJob, BatchesError>
Create a batch prediction job.
Sourcepub async fn create_batch_embeddings(
&self,
config: CreateBatchJobConfig,
) -> Result<BatchJob, BatchesError>
pub async fn create_batch_embeddings( &self, config: CreateBatchJobConfig, ) -> Result<BatchJob, BatchesError>
Create a batch embeddings job.
Sourcepub async fn get_batch_job(&self, name: &str) -> Result<BatchJob, BatchesError>
pub async fn get_batch_job(&self, name: &str) -> Result<BatchJob, BatchesError>
Get a batch job by name.
Sourcepub async fn cancel_batch_job(&self, name: &str) -> Result<(), BatchesError>
pub async fn cancel_batch_job(&self, name: &str) -> Result<(), BatchesError>
Cancel a batch job by name.
Sourcepub async fn delete_batch_job(&self, name: &str) -> Result<(), BatchesError>
pub async fn delete_batch_job(&self, name: &str) -> Result<(), BatchesError>
Delete a batch job by name.
Source§impl Client
impl Client
Sourcepub async fn list_cached_contents(
&self,
) -> Result<ListCachedContentsResponse, CachesError>
pub async fn list_cached_contents( &self, ) -> Result<ListCachedContentsResponse, CachesError>
List cached contents.
Sourcepub async fn create_cached_content(
&self,
config: CreateCachedContentConfig,
) -> Result<CachedContent, CachesError>
pub async fn create_cached_content( &self, config: CreateCachedContentConfig, ) -> Result<CachedContent, CachesError>
Create a new cached content.
Sourcepub async fn get_cached_content(
&self,
name: &str,
) -> Result<CachedContent, CachesError>
pub async fn get_cached_content( &self, name: &str, ) -> Result<CachedContent, CachesError>
Get a cached content by name.
Sourcepub async fn update_cached_content(
&self,
name: &str,
updates: UpdateCachedContentRequest,
) -> Result<CachedContent, CachesError>
pub async fn update_cached_content( &self, name: &str, updates: UpdateCachedContentRequest, ) -> Result<CachedContent, CachesError>
Update a cached content (TTL or expiration time).
Sourcepub async fn delete_cached_content(&self, name: &str) -> Result<(), CachesError>
pub async fn delete_cached_content(&self, name: &str) -> Result<(), CachesError>
Delete a cached content by name.
Source§impl Client
impl Client
Sourcepub fn chat(&self) -> ChatSessionBuilder<'_>
pub fn chat(&self) -> ChatSessionBuilder<'_>
Start a new chat session with the default model.
Source§impl Client
impl Client
Sourcepub fn from_api_key(api_key: impl Into<String>) -> Self
pub fn from_api_key(api_key: impl Into<String>) -> Self
Create a client with Google AI API key authentication.
Sourcepub fn from_access_token(access_token: impl Into<String>) -> Self
pub fn from_access_token(access_token: impl Into<String>) -> Self
Create a client with Google AI OAuth2 token authentication.
Sourcepub fn from_vertex(
project: impl Into<String>,
location: impl Into<String>,
access_token: impl Into<String>,
) -> Self
pub fn from_vertex( project: impl Into<String>, location: impl Into<String>, access_token: impl Into<String>, ) -> Self
Create a client with Vertex AI authentication.
Sourcepub fn from_vertex_refreshable(
project: impl Into<String>,
location: impl Into<String>,
refresher: impl Fn() -> String + Send + Sync + 'static,
) -> Self
pub fn from_vertex_refreshable( project: impl Into<String>, location: impl Into<String>, refresher: impl Fn() -> String + Send + Sync + 'static, ) -> Self
Create a client with Vertex AI authentication and dynamic token refresh.
The refresher closure is called on every REST API request and on
every Live connection attempt (including reconnects) to obtain a
fresh Bearer token. It should cache internally (see
GcloudTokenProvider in gemini-adk-rs for an example).
This is the right constructor for anything that outlives a token’s ~1 h lifetime.
Sourcepub fn http_config(self, config: HttpConfig) -> Self
pub fn http_config(self, config: HttpConfig) -> Self
Configure the HTTP client (timeouts, retries, etc.).
Sourcepub fn auth(&self) -> &dyn AuthProvider
pub fn auth(&self) -> &dyn AuthProvider
Get a reference to the underlying auth provider.
Sourcepub fn default_model(&self) -> &ModelId
pub fn default_model(&self) -> &ModelId
Get the default model.
Sourcepub fn rest_url(&self, endpoint: ServiceEndpoint) -> String
pub fn rest_url(&self, endpoint: ServiceEndpoint) -> String
Build the REST URL for a given service endpoint, using the default model.
Sourcepub fn rest_url_for(&self, endpoint: ServiceEndpoint, model: &ModelId) -> String
pub fn rest_url_for(&self, endpoint: ServiceEndpoint, model: &ModelId) -> String
Build the REST URL for a given service endpoint with a specific model.
Sourcepub async fn auth_headers(&self) -> Result<Vec<(String, String)>, AuthError>
pub async fn auth_headers(&self) -> Result<Vec<(String, String)>, AuthError>
Get auth headers for REST API calls.
Sourcepub fn live(&self, model: Option<ModelId>) -> ConnectBuilder
pub fn live(&self, model: Option<ModelId>) -> ConnectBuilder
A Live session on this client’s credentials.
None connects to the platform’s default Live model (the REST default
model is a text model and would not do). Tune the session with
ConnectBuilder::configure, then .connect().await.
Sourcepub fn http_client(&self) -> &HttpClient
pub fn http_client(&self) -> &HttpClient
Get a reference to the HTTP client for making REST API calls.
Sourcepub async fn rest_request(
&self,
endpoint: ServiceEndpoint,
body: &impl Serialize,
) -> Result<Value, HttpError>
pub async fn rest_request( &self, endpoint: ServiceEndpoint, body: &impl Serialize, ) -> Result<Value, HttpError>
Make a raw REST API request (low-level).
Higher-level module methods (e.g., generate_content()) should be preferred.
Source§impl Client
impl Client
Sourcepub async fn embed_content(
&self,
text: impl Into<String>,
) -> Result<EmbedContentResponse, EmbedError>
pub async fn embed_content( &self, text: impl Into<String>, ) -> Result<EmbedContentResponse, EmbedError>
Embed text content using the default model.
Sourcepub async fn embed_content_with(
&self,
config: EmbedContentConfig,
model: Option<&ModelId>,
) -> Result<EmbedContentResponse, EmbedError>
pub async fn embed_content_with( &self, config: EmbedContentConfig, model: Option<&ModelId>, ) -> Result<EmbedContentResponse, EmbedError>
Embed content with full configuration.
Source§impl Client
impl Client
Sourcepub async fn list_files(&self) -> Result<ListFilesResponse, FilesError>
pub async fn list_files(&self) -> Result<ListFilesResponse, FilesError>
List files.
Sourcepub async fn delete_file(&self, name: &str) -> Result<(), FilesError>
pub async fn delete_file(&self, name: &str) -> Result<(), FilesError>
Delete a file by name.
Sourcepub async fn upload_file(
&self,
data: Vec<u8>,
config: UploadFileConfig,
) -> Result<File, FilesError>
pub async fn upload_file( &self, data: Vec<u8>, config: UploadFileConfig, ) -> Result<File, FilesError>
Upload a file from a byte buffer.
Sourcepub async fn download_file(&self, name: &str) -> Result<Vec<u8>, FilesError>
pub async fn download_file(&self, name: &str) -> Result<Vec<u8>, FilesError>
Download a file’s content by name.
Sourcepub async fn register_files(
&self,
sources: Vec<FileSource>,
) -> Result<Vec<File>, FilesError>
pub async fn register_files( &self, sources: Vec<FileSource>, ) -> Result<Vec<File>, FilesError>
Register external files by URI (Vertex AI only).
Source§impl Client
impl Client
Sourcepub async fn generate_content(
&self,
prompt: impl Into<String>,
) -> Result<GenerateContentResponse, GenerateError>
pub async fn generate_content( &self, prompt: impl Into<String>, ) -> Result<GenerateContentResponse, GenerateError>
Generate content from a text prompt using the default model.
Sourcepub async fn generate_content_with(
&self,
config: GenerateContentConfig,
model: Option<&ModelId>,
) -> Result<GenerateContentResponse, GenerateError>
pub async fn generate_content_with( &self, config: GenerateContentConfig, model: Option<&ModelId>, ) -> Result<GenerateContentResponse, GenerateError>
Generate content with full configuration and optional model override.
Source§impl Client
impl Client
Sourcepub async fn list_models(&self) -> Result<ListModelsResponse, ModelsError>
pub async fn list_models(&self) -> Result<ListModelsResponse, ModelsError>
List available models.
Source§impl Client
impl Client
Sourcepub async fn count_tokens(
&self,
text: impl Into<String>,
) -> Result<CountTokensResponse, TokensError>
pub async fn count_tokens( &self, text: impl Into<String>, ) -> Result<CountTokensResponse, TokensError>
Count tokens for text content.
Sourcepub async fn count_tokens_for(
&self,
contents: Vec<Content>,
model: Option<&ModelId>,
) -> Result<CountTokensResponse, TokensError>
pub async fn count_tokens_for( &self, contents: Vec<Content>, model: Option<&ModelId>, ) -> Result<CountTokensResponse, TokensError>
Count tokens for content with optional model override.
Source§impl Client
impl Client
Sourcepub async fn list_tuning_jobs(
&self,
) -> Result<ListTuningJobsResponse, TuningsError>
pub async fn list_tuning_jobs( &self, ) -> Result<ListTuningJobsResponse, TuningsError>
List tuning jobs.
Sourcepub async fn get_tuning_job(
&self,
name: &str,
) -> Result<TuningJob, TuningsError>
pub async fn get_tuning_job( &self, name: &str, ) -> Result<TuningJob, TuningsError>
Get a tuning job by name.
Sourcepub async fn create_tuning_job(
&self,
config: CreateTuningJobConfig,
) -> Result<TuningJob, TuningsError>
pub async fn create_tuning_job( &self, config: CreateTuningJobConfig, ) -> Result<TuningJob, TuningsError>
Create a new tuning job.
Sourcepub async fn cancel_tuning_job(&self, name: &str) -> Result<(), TuningsError>
pub async fn cancel_tuning_job(&self, name: &str) -> Result<(), TuningsError>
Cancel a tuning job by name.
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].