pub struct SessionConfig {Show 15 fields
pub endpoint: ApiEndpoint,
pub model: Option<ModelId>,
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 audio_pacing: Option<BackpressureConfig>,
pub wire_recorder: Option<WireRecorderHandle>,
}Expand description
Complete session configuration — the builder entrypoint.
Fields§
§endpoint: ApiEndpointAPI endpoint and credentials (Google AI key or Vertex AI project/token).
model: Option<ModelId>Which Gemini model to use.
The Live model. None means “the platform’s current default”, resolved
at connect time by SessionConfig::resolved_model; set it only when a
specific model is required.
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: AudioFormatEncoding of the audio sent with send_audio (default: PCM16 at
LIVE_INPUT_SAMPLE_RATE).
The output format is not configurable: the API returns 24 kHz PCM16.
audio_pacing: Option<BackpressureConfig>Optional send pacing for outbound audio (token-bucket backpressure).
None (default) sends audio as fast as the command queue accepts it.
When set, SessionHandle::send_audio
paces the producer: a caller pushing audio faster than
refill_rate_bps waits, instead of overflowing the send queue.
wire_recorder: Option<WireRecorderHandle>Optional wire recorder. When set, connect
and ConnectBuilder wrap the codec in a
RecordingCodec so every wire byte
(both directions) is delivered to the recorder. See
SessionConfig::record_wire.
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>) -> 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.
Sourcepub fn from_access_token(access_token: impl Into<AccessToken>) -> SessionConfig
pub fn from_access_token(access_token: impl Into<AccessToken>) -> 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");Sourcepub fn from_vertex(
project: impl Into<String>,
location: impl Into<String>,
access_token: impl Into<AccessToken>,
) -> SessionConfig
pub fn from_vertex( project: impl Into<String>, location: impl Into<String>, access_token: impl Into<AccessToken>, ) -> 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",
);Sourcepub fn from_endpoint(endpoint: ApiEndpoint) -> SessionConfig
pub fn from_endpoint(endpoint: ApiEndpoint) -> SessionConfig
Create a session configuration from an explicit ApiEndpoint.
Sourcepub fn model(self, model: impl Into<ModelId>) -> SessionConfig
pub fn model(self, model: impl Into<ModelId>) -> SessionConfig
Set the Gemini model.
Sourcepub fn resolved_model(&self) -> ModelId
pub fn resolved_model(&self) -> ModelId
The model this session will ask for: the configured one, else the
platform default (see ModelId::live_default).
Sourcepub fn record_wire(self, recorder: Arc<dyn WireRecorder>) -> SessionConfig
pub fn record_wire(self, recorder: Arc<dyn WireRecorder>) -> SessionConfig
Record every wire byte (both directions) to the given recorder.
Both connect paths (connect and
ConnectBuilder) honor this by
wrapping the codec in a RecordingCodec.
Use FileWireRecorder for a
durable JSONL log that can be replayed offline with
ReplayTransport.
Sourcepub fn voice(self, voice: Voice) -> SessionConfig
pub fn voice(self, voice: Voice) -> SessionConfig
Set the output voice.
Sourcepub fn system_instruction(self, instruction: impl Into<String>) -> SessionConfig
pub fn system_instruction(self, instruction: impl Into<String>) -> SessionConfig
Set the system instruction.
Sourcepub fn response_modalities(self, modalities: Vec<Modality>) -> SessionConfig
pub fn response_modalities(self, modalities: Vec<Modality>) -> SessionConfig
Set response modalities.
Sourcepub fn text_only(self) -> SessionConfig
pub fn text_only(self) -> SessionConfig
Configure for text-only mode (no audio output).
Sourcepub fn add_tool(self, tool: Tool) -> SessionConfig
pub fn add_tool(self, tool: Tool) -> SessionConfig
Add a tool declaration.
Sourcepub fn with_url_context(self) -> SessionConfig
pub fn with_url_context(self) -> SessionConfig
Enable URL context tool.
Sourcepub fn with_google_search(self) -> SessionConfig
pub fn with_google_search(self) -> SessionConfig
Enable Google Search grounding.
Sourcepub fn with_code_execution(self) -> SessionConfig
pub fn with_code_execution(self) -> SessionConfig
Enable code execution.
Sourcepub fn tool_config(self, config: ToolConfig) -> SessionConfig
pub fn tool_config(self, config: ToolConfig) -> SessionConfig
Set tool configuration.
Sourcepub fn input_transcription(self, enabled: bool) -> SessionConfig
pub fn input_transcription(self, enabled: bool) -> SessionConfig
Whether the server transcribes the user’s audio
(SessionEvent::InputTranscription).
Sourcepub fn output_transcription(self, enabled: bool) -> SessionConfig
pub fn output_transcription(self, enabled: bool) -> SessionConfig
Whether the server transcribes the model’s audio
(SessionEvent::OutputTranscription).
Sourcepub fn temperature(self, temp: f32) -> SessionConfig
pub fn temperature(self, temp: f32) -> SessionConfig
Set the temperature for generation.
Sourcepub fn automatic_activity_detection_enabled(&self) -> bool
pub fn automatic_activity_detection_enabled(&self) -> bool
Whether the server is detecting speech boundaries.
True unless the caller explicitly disabled automatic detection, because
that is the API’s own default: omitting realtimeInputConfig entirely
leaves server VAD on.
This gates explicit activityStart / activityEnd signalling. The two
are mutually exclusive on the wire — sending an activity signal while
automatic detection is on draws a close frame, code 1007, “Explicit
activity control is not supported when automatic activity detection is
enabled”, and the session dies mid-utterance.
Sourcepub fn server_vad(self, detection: AutomaticActivityDetection) -> SessionConfig
pub fn server_vad(self, detection: AutomaticActivityDetection) -> SessionConfig
Configure server-side VAD.
Sourcepub 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).
Sourcepub 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.
Sourcepub fn audio_pacing(self, config: BackpressureConfig) -> SessionConfig
pub fn audio_pacing(self, config: BackpressureConfig) -> SessionConfig
Pace outbound audio with a token bucket (producer-side backpressure).
See SessionConfig::audio_pacing. Use
BackpressureConfig::default
for 16 kHz PCM16 rates with a ~250 ms burst allowance.
Sourcepub 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.
Sourcepub fn session_resumption(self) -> SessionConfig
pub fn session_resumption(self) -> SessionConfig
Enable session resumption: the server issues resumption handles
(SessionEvent::SessionResumeUpdate) that a later session can pass to
resume_from.
Sourcepub fn resume_from(self, handle: impl Into<String>) -> SessionConfig
pub fn resume_from(self, handle: impl Into<String>) -> SessionConfig
Resume an earlier session from a handle the server issued for it.
Implies session_resumption.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn proactive_audio(self, enabled: bool) -> SessionConfig
pub fn proactive_audio(self, enabled: bool) -> SessionConfig
Enable proactive model responses.
Sourcepub fn thinking(self, budget: u32) -> SessionConfig
pub fn thinking(self, budget: u32) -> SessionConfig
Enable thinking/reasoning with a token budget (Gemini 2.5+).
Sourcepub fn include_thoughts(self, enabled: bool) -> SessionConfig
pub fn include_thoughts(self, enabled: bool) -> SessionConfig
Whether thought summaries are delivered (SessionEvent::Thought).
Google AI only; see supports_thinking.
Sourcepub fn affective_dialog(self, enabled: bool) -> SessionConfig
pub fn affective_dialog(self, enabled: bool) -> SessionConfig
Enable affective dialog (emotionally expressive responses).
Sourcepub fn media_resolution(self, res: MediaResolution) -> SessionConfig
pub fn media_resolution(self, res: MediaResolution) -> SessionConfig
Set the media resolution for image/video inputs.
Sourcepub fn seed(self, seed: u32) -> SessionConfig
pub fn seed(self, seed: u32) -> SessionConfig
Set the random seed for deterministic generation.
Sourcepub fn input_audio_format(self, format: AudioFormat) -> SessionConfig
pub fn input_audio_format(self, format: AudioFormat) -> SessionConfig
Set the encoding of the audio sent with send_audio.
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<String>
pub fn bearer_token(&self) -> Option<String>
The current bearer token when using Vertex AI, None for Google AI.
The transport calls this on every connection attempt to set the
Authorization header for the WebSocket upgrade, so a refreshing
AccessToken is honoured on reconnect. Google AI endpoints pass the
credential 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 supports_thinking(&self) -> bool
pub fn supports_thinking(&self) -> bool
Returns true if the platform accepts thinkingConfig in the setup
message. Vertex AI does not: the whole config is stripped there, so
thinking(..) and include_thoughts(..) are silent no-ops on Vertex.
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 moreAuto Trait Implementations§
impl Freeze for SessionConfig
impl !RefUnwindSafe for SessionConfig
impl Send for SessionConfig
impl Sync for SessionConfig
impl Unpin for SessionConfig
impl !UnwindSafe for SessionConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§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].