SessionConfig

Struct SessionConfig 

Source
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§

Source§

impl SessionConfig

Source

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.

Source

pub fn to_setup_json(&self) -> String

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

Source§

impl SessionConfig

Source

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.

Source

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");
Source

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",
);
Source

pub fn from_endpoint(endpoint: ApiEndpoint) -> Self

Create a session configuration from an explicit ApiEndpoint.

Source

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

Set the Gemini model.

Source

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

Set the output voice.

Source

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

Set the system instruction.

Source

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

Set response modalities.

Source

pub fn text_only(self) -> Self

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

Source

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

Add a tool declaration.

Source

pub fn with_url_context(self) -> Self

Enable URL context tool.

Enable Google Search grounding.

Source

pub fn with_code_execution(self) -> Self

Enable code execution.

Source

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

Set tool configuration.

Source

pub fn enable_input_transcription(self) -> Self

Enable input audio transcription.

Source

pub fn enable_output_transcription(self) -> Self

Enable output audio transcription.

Source

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

Set the temperature for generation.

Source

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

Configure server-side VAD.

Source

pub fn activity_handling(self, handling: ActivityHandling) -> Self

Set how incoming audio interacts with model output (barge-in behavior).

Source

pub fn turn_coverage(self, coverage: TurnCoverage) -> Self

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

Source

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.

Source

pub fn session_resumption(self, handle: Option<String>) -> Self

Enable session resumption.

Source

pub fn context_window_compression(self, target_tokens: u32) -> Self

Configure context window compression for long sessions.

Source

pub fn context_window_trigger_tokens(self, tokens: u32) -> Self

Set the token threshold that triggers context window compression.

Source

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

Enable proactive model responses.

Source

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

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

Source

pub fn include_thoughts(self) -> Self

Include the model’s thought process in responses.

Source

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

Enable affective dialog (emotionally expressive responses).

Source

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

Set the media resolution for image/video inputs.

Source

pub fn seed(self, seed: u32) -> Self

Set the random seed for deterministic generation.

Source

pub fn input_audio(self, format: AudioFormat, sample_rate: u32) -> Self

Set input audio format and sample rate.

Source

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

Set output audio format and sample rate.

Source

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
Source

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}
Source

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.

Source

pub fn is_vertex(&self) -> bool

Returns true if this config targets Vertex AI.

Source

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.

Source

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

Source§

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
Source§

impl Debug for SessionConfig

Source§

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

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