pub struct VertexAIAuth { /* private fields */ }Expand description
Vertex AI Bearer token authentication.
Uses a project/location pair to construct the Vertex AI WebSocket URL,
and a Bearer token for the Authorization header.
Supports two token modes:
- Fixed (
new): token is set once at construction. Best for WebSocket connections where the token is only needed at connect time. - Refreshable (
with_token_refresher): a closure is called on everyauth_headers()invocation, ensuring fresh tokens for long-running HTTP clients (e.g., generate API calls).
Implementations§
Source§impl VertexAIAuth
impl VertexAIAuth
Sourcepub fn new(
project: impl Into<String>,
location: impl Into<String>,
token: impl Into<String>,
) -> Self
pub fn new( project: impl Into<String>, location: impl Into<String>, token: impl Into<String>, ) -> Self
Create a new Vertex AI auth provider with a fixed token.
The token is stored and reused for all requests. Use this for WebSocket connections where the token is only needed at connect time.
Sourcepub fn with_token_refresher(
project: impl Into<String>,
location: impl Into<String>,
refresher: impl Fn() -> String + Send + Sync + 'static,
) -> Self
pub fn with_token_refresher( project: impl Into<String>, location: impl Into<String>, refresher: impl Fn() -> String + Send + Sync + 'static, ) -> Self
Create a Vertex AI auth provider with a dynamic token refresher.
The refresher closure is called on every auth_headers() invocation,
allowing token refresh for long-running HTTP clients. The closure
should handle caching internally to avoid unnecessary overhead.
Trait Implementations§
Source§impl AuthProvider for VertexAIAuth
impl AuthProvider for VertexAIAuth
Source§fn ws_url(&self, model: &GeminiModel) -> String
fn ws_url(&self, model: &GeminiModel) -> String
Build the WebSocket URL for the given model.
Source§fn rest_url(
&self,
endpoint: ServiceEndpoint,
model: Option<&GeminiModel>,
) -> String
fn rest_url( &self, endpoint: ServiceEndpoint, model: Option<&GeminiModel>, ) -> String
Build a REST API URL for the given service endpoint and model. Read more
Source§fn auth_headers<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<(String, String)>, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn auth_headers<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<(String, String)>, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
HTTP headers for the WebSocket upgrade request (e.g., Bearer token).
Auto Trait Implementations§
impl !Freeze for VertexAIAuth
impl !RefUnwindSafe for VertexAIAuth
impl Send for VertexAIAuth
impl Sync for VertexAIAuth
impl Unpin for VertexAIAuth
impl !UnwindSafe for VertexAIAuth
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
Mutably borrows from an owned value. Read more