Struct SessionConfig
pub struct SessionConfig {Show 16 fields
pub endpoint: ApiEndpoint,
pub model: GeminiModel,
pub generation_config: GenerationConfig,
pub system_instruction: Option<Content>,
pub tools: Vec<Tool>,
pub tool_config: Option<ToolConfig>,
pub input_audio_transcription: Option<InputAudioTranscription>,
pub output_audio_transcription: Option<OutputAudioTranscription>,
pub realtime_input_config: Option<RealtimeInputConfig>,
pub session_resumption: Option<SessionResumptionConfig>,
pub context_window_compression: Option<ContextWindowCompressionConfig>,
pub proactivity: Option<ProactivityConfig>,
pub input_audio_format: AudioFormat,
pub output_audio_format: AudioFormat,
pub input_sample_rate: u32,
pub output_sample_rate: u32,
}Expand description
Complete session configuration — the builder entrypoint.
Fields§
§endpoint: ApiEndpointAPI endpoint and credentials (Google AI key or Vertex AI project/token).
model: GeminiModelWhich Gemini model to use.
generation_config: GenerationConfigGeneration parameters (modalities, temperature, etc.).
system_instruction: Option<Content>System instruction content.
tools: Vec<Tool>Tool declarations for function calling, search, etc.
tool_config: Option<ToolConfig>Tool usage configuration.
input_audio_transcription: Option<InputAudioTranscription>Input audio transcription configuration.
output_audio_transcription: Option<OutputAudioTranscription>Output audio transcription configuration.
realtime_input_config: Option<RealtimeInputConfig>Realtime input configuration (VAD, activity handling).
session_resumption: Option<SessionResumptionConfig>Session resumption configuration.
context_window_compression: Option<ContextWindowCompressionConfig>Context window compression configuration.
proactivity: Option<ProactivityConfig>Proactivity configuration.
input_audio_format: AudioFormatAudio format for input (default: PCM16).
output_audio_format: AudioFormatAudio format for output (default: PCM16).
input_sample_rate: u32Input audio sample rate in Hz (default: 16000).
output_sample_rate: u32Output audio sample rate in Hz (default: 24000).
Implementations§
§impl SessionConfig
impl SessionConfig
pub fn to_setup_message(&self) -> SetupMessage
pub fn to_setup_message(&self) -> SetupMessage
Build the setup message from this configuration.
When targeting Vertex AI, FunctionCallingBehavior is stripped from
tool declarations since Vertex AI does not support async tool calling.
pub fn to_setup_json(&self) -> String
pub fn to_setup_json(&self) -> String
Pre-serialize the setup message to JSON. Called once at connection time.
§impl SessionConfig
impl SessionConfig
pub fn new(api_key: impl Into<String>) -> SessionConfig
pub fn new(api_key: impl Into<String>) -> SessionConfig
Create a new session configuration with a Google AI API key.
This is the simplest way to get started. For Vertex AI, use
SessionConfig::from_vertex or SessionConfig::from_endpoint.
pub fn from_access_token(access_token: impl Into<String>) -> SessionConfig
pub fn from_access_token(access_token: impl Into<String>) -> SessionConfig
Create a session configuration with an OAuth2 access token.
Uses the Google AI endpoint (generativelanguage.googleapis.com) with
an access token instead of an API key. This is the recommended approach
when using gcloud auth print-access-token credentials.
let config = SessionConfig::from_access_token("ya29.ACCESS_TOKEN");pub fn from_vertex(
project: impl Into<String>,
location: impl Into<String>,
access_token: impl Into<String>,
) -> SessionConfig
pub fn from_vertex( project: impl Into<String>, location: impl Into<String>, access_token: impl Into<String>, ) -> SessionConfig
Create a session configuration for Vertex AI.
Uses the regional Vertex AI endpoint ({location}-aiplatform.googleapis.com).
For the global endpoint, consider using SessionConfig::from_access_token
instead.
let config = SessionConfig::from_vertex(
"my-project-123",
"us-central1",
"ya29.ACCESS_TOKEN",
);pub fn from_endpoint(endpoint: ApiEndpoint) -> SessionConfig
pub fn from_endpoint(endpoint: ApiEndpoint) -> SessionConfig
Create a session configuration from an explicit ApiEndpoint.
pub fn model(self, model: GeminiModel) -> SessionConfig
pub fn model(self, model: GeminiModel) -> SessionConfig
Set the Gemini model.
pub fn voice(self, voice: Voice) -> SessionConfig
pub fn voice(self, voice: Voice) -> SessionConfig
Set the output voice.
pub fn system_instruction(self, instruction: impl Into<String>) -> SessionConfig
pub fn system_instruction(self, instruction: impl Into<String>) -> SessionConfig
Set the system instruction.
pub fn response_modalities(self, modalities: Vec<Modality>) -> SessionConfig
pub fn response_modalities(self, modalities: Vec<Modality>) -> SessionConfig
Set response modalities.
pub fn text_only(self) -> SessionConfig
pub fn text_only(self) -> SessionConfig
Configure for text-only mode (no audio output).
pub fn add_tool(self, tool: Tool) -> SessionConfig
pub fn add_tool(self, tool: Tool) -> SessionConfig
Add a tool declaration.
pub fn with_url_context(self) -> SessionConfig
pub fn with_url_context(self) -> SessionConfig
Enable URL context tool.
pub fn with_google_search(self) -> SessionConfig
pub fn with_google_search(self) -> SessionConfig
Enable Google Search grounding.
pub fn with_code_execution(self) -> SessionConfig
pub fn with_code_execution(self) -> SessionConfig
Enable code execution.
pub fn tool_config(self, config: ToolConfig) -> SessionConfig
pub fn tool_config(self, config: ToolConfig) -> SessionConfig
Set tool configuration.
pub fn enable_input_transcription(self) -> SessionConfig
pub fn enable_input_transcription(self) -> SessionConfig
Enable input audio transcription.
pub fn enable_output_transcription(self) -> SessionConfig
pub fn enable_output_transcription(self) -> SessionConfig
Enable output audio transcription.
pub fn temperature(self, temp: f32) -> SessionConfig
pub fn temperature(self, temp: f32) -> SessionConfig
Set the temperature for generation.
pub fn server_vad(self, detection: AutomaticActivityDetection) -> SessionConfig
pub fn server_vad(self, detection: AutomaticActivityDetection) -> SessionConfig
Configure server-side VAD.
pub fn activity_handling(self, handling: ActivityHandling) -> SessionConfig
pub fn activity_handling(self, handling: ActivityHandling) -> SessionConfig
Set how incoming audio interacts with model output (barge-in behavior).
pub fn turn_coverage(self, coverage: TurnCoverage) -> SessionConfig
pub fn turn_coverage(self, coverage: TurnCoverage) -> SessionConfig
Set which input counts toward a user’s conversation turn.
pub fn voice_realtime_defaults(self) -> SessionConfig
pub fn voice_realtime_defaults(self) -> SessionConfig
Apply recommended realtime input defaults for voice conversations.
This preserves any values the caller already set. In particular, it sets
TURN_INCLUDES_ONLY_ACTIVITY so long pauses/silence in a continuous mic
stream are not included in the user’s semantic turn.
pub fn session_resumption(self, handle: Option<String>) -> SessionConfig
pub fn session_resumption(self, handle: Option<String>) -> SessionConfig
Enable session resumption.
pub fn context_window_compression(self, target_tokens: u32) -> SessionConfig
pub fn context_window_compression(self, target_tokens: u32) -> SessionConfig
Configure context window compression for long sessions.
pub fn context_window_trigger_tokens(self, tokens: u32) -> SessionConfig
pub fn context_window_trigger_tokens(self, tokens: u32) -> SessionConfig
Set the token threshold that triggers context window compression.
pub fn proactive_audio(self, enabled: bool) -> SessionConfig
pub fn proactive_audio(self, enabled: bool) -> SessionConfig
Enable proactive model responses.
pub fn thinking(self, budget: u32) -> SessionConfig
pub fn thinking(self, budget: u32) -> SessionConfig
Enable thinking/reasoning with a token budget (Gemini 2.5+).
pub fn include_thoughts(self) -> SessionConfig
pub fn include_thoughts(self) -> SessionConfig
Include the model’s thought process in responses.
pub fn affective_dialog(self, enabled: bool) -> SessionConfig
pub fn affective_dialog(self, enabled: bool) -> SessionConfig
Enable affective dialog (emotionally expressive responses).
pub fn media_resolution(self, res: MediaResolution) -> SessionConfig
pub fn media_resolution(self, res: MediaResolution) -> SessionConfig
Set the media resolution for image/video inputs.
pub fn seed(self, seed: u32) -> SessionConfig
pub fn seed(self, seed: u32) -> SessionConfig
Set the random seed for deterministic generation.
pub fn input_audio(self, format: AudioFormat, sample_rate: u32) -> SessionConfig
pub fn input_audio(self, format: AudioFormat, sample_rate: u32) -> SessionConfig
Set input audio format and sample rate.
pub fn output_audio(
self,
format: AudioFormat,
sample_rate: u32,
) -> SessionConfig
pub fn output_audio( self, format: AudioFormat, sample_rate: u32, ) -> SessionConfig
Set output audio format and sample rate.
pub fn ws_url(&self) -> String
pub fn ws_url(&self) -> String
Build the WebSocket URL for connecting to the Gemini Live API.
- Google AI (key):
wss://generativelanguage.googleapis.com/ws/...?key={key} - Google AI (token):
wss://generativelanguage.googleapis.com/ws/...?access_token={token} - Vertex AI:
wss://{location}-aiplatform.googleapis.com/ws/...orwss://aiplatform.googleapis.com/ws/...for global
pub fn model_uri(&self) -> String
pub fn model_uri(&self) -> String
Build the model URI used in the setup message.
- Google AI / Google AI Token:
models/{model} - Vertex AI:
projects/{project}/locations/{location}/publishers/google/models/{model}
pub fn bearer_token(&self) -> Option<&str>
pub fn bearer_token(&self) -> Option<&str>
Returns the bearer token when using Vertex AI, None for Google AI.
Used by the transport layer to set the Authorization HTTP header
during the WebSocket upgrade handshake. Google AI endpoints pass the
token as a query parameter instead.
pub fn supports_async_tools(&self) -> bool
pub fn supports_async_tools(&self) -> bool
Returns true if the platform supports async (non-blocking) tool calling.
Google AI supports FunctionCallingBehavior::NonBlocking on declarations
and FunctionResponseScheduling on responses. Vertex AI does not — these
fields are automatically stripped from the wire messages when targeting
Vertex AI so callers can set them unconditionally.
pub fn uses_access_token(&self) -> bool
pub fn uses_access_token(&self) -> bool
Returns true if this config uses an access token (either GoogleAIToken or VertexAI).
Trait Implementations§
§impl Clone for SessionConfig
impl Clone for SessionConfig
§fn clone(&self) -> SessionConfig
fn clone(&self) -> SessionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more