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
// 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
let session = client.live("gemini-2.5-flash").connect().await?;Implementations§
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 to obtain
a fresh Bearer token. It should handle caching internally to avoid
unnecessary overhead (see GcloudTokenProvider in rs-adk for an example).
This is the recommended constructor for long-running HTTP clients (e.g., extraction LLMs) where tokens may expire during the session.
Sourcepub fn model(self, model: impl Into<GeminiModel>) -> Self
pub fn model(self, model: impl Into<GeminiModel>) -> Self
Set the default model for all API calls.
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) -> &GeminiModel
pub fn default_model(&self) -> &GeminiModel
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: &GeminiModel,
) -> String
pub fn rest_url_for( &self, endpoint: ServiceEndpoint, model: &GeminiModel, ) -> 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: GeminiModel) -> LiveSessionBuilder
pub fn live(&self, model: GeminiModel) -> LiveSessionBuilder
Start a Live WebSocket session builder.
Returns a LiveSessionBuilder that can be customized before connecting.