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§
Source§impl SessionConfig
impl SessionConfig
Sourcepub 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.
Sourcepub 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.
Source§impl SessionConfig
impl SessionConfig
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
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.
Sourcepub fn from_access_token(access_token: impl Into<String>) -> Self
pub fn from_access_token(access_token: impl Into<String>) -> Self
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");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 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",
);Sourcepub fn from_endpoint(endpoint: ApiEndpoint) -> Self
pub fn from_endpoint(endpoint: ApiEndpoint) -> Self
Create a session configuration from an explicit ApiEndpoint.
Sourcepub fn model(self, model: GeminiModel) -> Self
pub fn model(self, model: GeminiModel) -> Self
Set the Gemini model.
Sourcepub fn system_instruction(self, instruction: impl Into<String>) -> Self
pub fn system_instruction(self, instruction: impl Into<String>) -> Self
Set the system instruction.
Sourcepub fn response_modalities(self, modalities: Vec<Modality>) -> Self
pub fn response_modalities(self, modalities: Vec<Modality>) -> Self
Set response modalities.
Sourcepub fn with_url_context(self) -> Self
pub fn with_url_context(self) -> Self
Enable URL context tool.
Sourcepub fn with_google_search(self) -> Self
pub fn with_google_search(self) -> Self
Enable Google Search grounding.
Sourcepub fn with_code_execution(self) -> Self
pub fn with_code_execution(self) -> Self
Enable code execution.
Sourcepub fn tool_config(self, config: ToolConfig) -> Self
pub fn tool_config(self, config: ToolConfig) -> Self
Set tool configuration.
Sourcepub fn enable_input_transcription(self) -> Self
pub fn enable_input_transcription(self) -> Self
Enable input audio transcription.
Sourcepub fn enable_output_transcription(self) -> Self
pub fn enable_output_transcription(self) -> Self
Enable output audio transcription.
Sourcepub fn temperature(self, temp: f32) -> Self
pub fn temperature(self, temp: f32) -> Self
Set the temperature for generation.
Sourcepub fn server_vad(self, detection: AutomaticActivityDetection) -> Self
pub fn server_vad(self, detection: AutomaticActivityDetection) -> Self
Configure server-side VAD.
Sourcepub fn activity_handling(self, handling: ActivityHandling) -> Self
pub fn activity_handling(self, handling: ActivityHandling) -> Self
Set how incoming audio interacts with model output (barge-in behavior).
Sourcepub fn turn_coverage(self, coverage: TurnCoverage) -> Self
pub fn turn_coverage(self, coverage: TurnCoverage) -> Self
Set which input counts toward a user’s conversation turn.
Sourcepub fn voice_realtime_defaults(self) -> Self
pub fn voice_realtime_defaults(self) -> Self
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.
Sourcepub fn session_resumption(self, handle: Option<String>) -> Self
pub fn session_resumption(self, handle: Option<String>) -> Self
Enable session resumption.
Sourcepub fn context_window_compression(self, target_tokens: u32) -> Self
pub fn context_window_compression(self, target_tokens: u32) -> Self
Configure context window compression for long sessions.
Sourcepub fn context_window_trigger_tokens(self, tokens: u32) -> Self
pub fn context_window_trigger_tokens(self, tokens: u32) -> Self
Set the token threshold that triggers context window compression.
Sourcepub fn proactive_audio(self, enabled: bool) -> Self
pub fn proactive_audio(self, enabled: bool) -> Self
Enable proactive model responses.
Sourcepub fn thinking(self, budget: u32) -> Self
pub fn thinking(self, budget: u32) -> Self
Enable thinking/reasoning with a token budget (Gemini 2.5+).
Sourcepub fn include_thoughts(self) -> Self
pub fn include_thoughts(self) -> Self
Include the model’s thought process in responses.
Sourcepub fn affective_dialog(self, enabled: bool) -> Self
pub fn affective_dialog(self, enabled: bool) -> Self
Enable affective dialog (emotionally expressive responses).
Sourcepub fn media_resolution(self, res: MediaResolution) -> Self
pub fn media_resolution(self, res: MediaResolution) -> Self
Set the media resolution for image/video inputs.
Sourcepub fn input_audio(self, format: AudioFormat, sample_rate: u32) -> Self
pub fn input_audio(self, format: AudioFormat, sample_rate: u32) -> Self
Set input audio format and sample rate.
Sourcepub fn output_audio(self, format: AudioFormat, sample_rate: u32) -> Self
pub fn output_audio(self, format: AudioFormat, sample_rate: u32) -> Self
Set output audio format and sample rate.
Sourcepub 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
Sourcepub 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}
Sourcepub 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.
Sourcepub 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.
Sourcepub 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§
Source§impl Clone for SessionConfig
impl Clone for SessionConfig
Source§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