pub enum ApiEndpoint {
GoogleAI {
api_key: String,
},
GoogleAIToken {
access_token: AccessToken,
},
VertexAI(VertexConfig),
}Expand description
API endpoint selector — Google AI (direct), Google AI with OAuth token, or Vertex AI.
§Google AI with API Key (default)
Uses an API key passed as a query parameter. The WebSocket URL is
wss://generativelanguage.googleapis.com/ws/...?key={api_key} and model
URIs are models/{model}.
§Google AI with Access Token
Uses an OAuth2 access token (e.g. from gcloud auth print-access-token)
passed as a query parameter. Same endpoint as Google AI but with
access_token instead of key. This is the recommended approach when
using gcloud credentials without an API key.
§Vertex AI
Uses a regional endpoint with OAuth2 bearer-token authentication. The
WebSocket URL is
wss://{location}-aiplatform.googleapis.com/ws/google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent
and model URIs are
projects/{project}/locations/{location}/publishers/google/models/{model}.
let google_ai = ApiEndpoint::google_ai("MY_API_KEY");
let with_token = ApiEndpoint::google_ai_token("ya29.ACCESS_TOKEN");
let vertex = ApiEndpoint::vertex("my-project", "us-central1", "ACCESS_TOKEN");Variants§
GoogleAI
Google AI Studio – API-key authentication.
GoogleAIToken
Google AI with OAuth2 access token (e.g. from gcloud).
Fields
access_token: AccessTokenThe OAuth2 access token.
VertexAI(VertexConfig)
Vertex AI — project + location + OAuth2 bearer token.
Implementations§
Source§impl ApiEndpoint
impl ApiEndpoint
Sourcepub fn google_ai(api_key: impl Into<String>) -> Self
pub fn google_ai(api_key: impl Into<String>) -> Self
Shorthand for Google AI endpoint with API key.
Sourcepub fn google_ai_token(access_token: impl Into<AccessToken>) -> Self
pub fn google_ai_token(access_token: impl Into<AccessToken>) -> Self
Google AI endpoint with an OAuth2 access token.
Use this when authenticating with gcloud auth print-access-token
or any other OAuth2 flow instead of an API key.
Sourcepub fn vertex(
project: impl Into<String>,
location: impl Into<String>,
access_token: impl Into<AccessToken>,
) -> Self
pub fn vertex( project: impl Into<String>, location: impl Into<String>, access_token: impl Into<AccessToken>, ) -> Self
Shorthand for Vertex AI endpoint.
access_token is a fixed string or an AccessToken; for a token
that refreshes across reconnects see ApiEndpoint::vertex_refreshing.
Sourcepub fn vertex_refreshing(
project: impl Into<String>,
location: impl Into<String>,
token: impl Fn() -> String + Send + Sync + 'static,
) -> Self
pub fn vertex_refreshing( project: impl Into<String>, location: impl Into<String>, token: impl Fn() -> String + Send + Sync + 'static, ) -> Self
Vertex AI endpoint whose bearer token is fetched on every connection attempt, so a reconnect after the token’s ~1 h lifetime carries a live credential.
let endpoint = ApiEndpoint::vertex_refreshing("my-project", "us-central1", || {
std::env::var("GOOGLE_ACCESS_TOKEN").unwrap_or_default()
});Sourcepub fn vertex_with_host(
project: impl Into<String>,
location: impl Into<String>,
access_token: impl Into<AccessToken>,
api_host: impl Into<String>,
) -> Self
pub fn vertex_with_host( project: impl Into<String>, location: impl Into<String>, access_token: impl Into<AccessToken>, api_host: impl Into<String>, ) -> Self
Vertex AI endpoint with a custom API host (for private endpoints, VPC-SC, or testing).
Sourcepub fn from_env() -> Result<Self, EndpointEnvError>
pub fn from_env() -> Result<Self, EndpointEnvError>
Resolve an endpoint from standard environment variables.
Selects the platform from GOOGLE_GENAI_USE_VERTEXAI (true/1):
- Vertex AI (
GOOGLE_GENAI_USE_VERTEXAI=true): readsGOOGLE_CLOUD_PROJECT(required),GOOGLE_CLOUD_LOCATION(defaultus-central1), andGOOGLE_ACCESS_TOKEN(required — higher layers may fall back togcloud auth print-access-token). - Google AI (default): reads the first set of
GEMINI_API_KEY,GOOGLE_GENAI_API_KEY, orGOOGLE_API_KEY.
Returns a descriptive error naming the missing variable so the failure is actionable.
Trait Implementations§
Source§impl Clone for ApiEndpoint
impl Clone for ApiEndpoint
Source§fn clone(&self) -> ApiEndpoint
fn clone(&self) -> ApiEndpoint
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 ApiEndpoint
impl !RefUnwindSafe for ApiEndpoint
impl Send for ApiEndpoint
impl Sync for ApiEndpoint
impl Unpin for ApiEndpoint
impl !UnwindSafe for ApiEndpoint
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<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].