SessionConfig

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: ApiEndpoint

API endpoint and credentials (Google AI key or Vertex AI project/token).

§model: GeminiModel

Which Gemini model to use.

§generation_config: GenerationConfig

Generation 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: AudioFormat

Audio format for input (default: PCM16).

§output_audio_format: AudioFormat

Audio format for output (default: PCM16).

§input_sample_rate: u32

Input audio sample rate in Hz (default: 16000).

§output_sample_rate: u32

Output audio sample rate in Hz (default: 24000).

Implementations§

§

impl SessionConfig

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

Pre-serialize the setup message to JSON. Called once at connection time.

§

impl 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

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

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

Create a session configuration from an explicit ApiEndpoint.

pub fn model(self, model: GeminiModel) -> SessionConfig

Set the Gemini model.

pub fn voice(self, voice: Voice) -> SessionConfig

Set the output voice.

pub fn system_instruction(self, instruction: impl Into<String>) -> SessionConfig

Set the system instruction.

pub fn response_modalities(self, modalities: Vec<Modality>) -> SessionConfig

Set response modalities.

pub fn text_only(self) -> SessionConfig

Configure for text-only mode (no audio output).

pub fn add_tool(self, tool: Tool) -> SessionConfig

Add a tool declaration.

pub fn with_url_context(self) -> SessionConfig

Enable URL context tool.

Enable Google Search grounding.

pub fn with_code_execution(self) -> SessionConfig

Enable code execution.

pub fn tool_config(self, config: ToolConfig) -> SessionConfig

Set tool configuration.

pub fn enable_input_transcription(self) -> SessionConfig

Enable input audio transcription.

pub fn enable_output_transcription(self) -> SessionConfig

Enable output audio transcription.

pub fn temperature(self, temp: f32) -> SessionConfig

Set the temperature for generation.

pub fn server_vad(self, detection: AutomaticActivityDetection) -> SessionConfig

Configure server-side VAD.

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

Set which input counts toward a user’s conversation turn.

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

Enable session resumption.

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

Set the token threshold that triggers context window compression.

pub fn proactive_audio(self, enabled: bool) -> SessionConfig

Enable proactive model responses.

pub fn thinking(self, budget: u32) -> SessionConfig

Enable thinking/reasoning with a token budget (Gemini 2.5+).

pub fn include_thoughts(self) -> SessionConfig

Include the model’s thought process in responses.

pub fn affective_dialog(self, enabled: bool) -> SessionConfig

Enable affective dialog (emotionally expressive responses).

pub fn media_resolution(self, res: MediaResolution) -> SessionConfig

Set the media resolution for image/video inputs.

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

Set input audio format and sample rate.

pub fn output_audio( self, format: AudioFormat, sample_rate: u32, ) -> SessionConfig

Set output audio format and sample rate.

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/... or wss://aiplatform.googleapis.com/ws/... for global

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>

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 is_vertex(&self) -> bool

Returns true if this config targets Vertex AI.

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

Returns true if this config uses an access token (either GoogleAIToken or VertexAI).

Trait Implementations§

§

impl Clone for SessionConfig

§

fn clone(&self) -> SessionConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for SessionConfig

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more