Class AuthTokensClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
Creates ephemeral auth tokens for the Live API, so client-side apps (browsers, mobile apps)
can open Live sessions without holding your API key. Gemini API only; uses the v1alpha API.
public class AuthTokensClient : BaseClient
- Inheritance
-
AuthTokensClient
- Inherited Members
- Extension Methods
Examples
var tokens = new AuthTokensClient(new GoogleAIPlatformAdapter(apiKey));
var token = await tokens.CreateAsync(new CreateAuthTokenConfig { Uses = 1 });
// On the client side:
var live = new MultiModalLiveClient(new GoogleAIPlatformAdapter(token.Name), GoogleAIModels.Gemini38Live);
Constructors
AuthTokensClient(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the AuthTokensClient class.
public AuthTokensClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)
Parameters
platformIPlatformAdapterThe platform adapter. Must be a Gemini API (Google AI) platform.
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional logger.
Methods
BuildRequest(CreateAuthTokenConfig)
Builds the request body for config, applying the same field-mask rules as the official SDKs.
public static CreateAuthTokenRequest BuildRequest(CreateAuthTokenConfig config)
Parameters
configCreateAuthTokenConfigToken options.
Returns
- CreateAuthTokenRequest
The request body that CreateAsync(CreateAuthTokenConfig, CancellationToken) sends.
CreateAsync(CreateAuthTokenConfig, CancellationToken)
Creates an ephemeral auth token, building the field mask from LockAdditionalFields.
public Task<AuthToken> CreateAsync(CreateAuthTokenConfig config, CancellationToken cancellationToken = default)
Parameters
configCreateAuthTokenConfigToken options.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
CreateAsync(CreateAuthTokenRequest, CancellationToken)
Creates an ephemeral auth token from a raw request body.
public Task<AuthToken> CreateAsync(CreateAuthTokenRequest request, CancellationToken cancellationToken = default)
Parameters
requestCreateAuthTokenRequestThe request body.
cancellationTokenCancellationTokenA token to cancel the operation.