Table of Contents

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

platform IPlatformAdapter

The platform adapter. Must be a Gemini API (Google AI) platform.

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional 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

config CreateAuthTokenConfig

Token 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

config CreateAuthTokenConfig

Token options.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<AuthToken>

The created token; use Name as the API key of a Live client.

CreateAsync(CreateAuthTokenRequest, CancellationToken)

Creates an ephemeral auth token from a raw request body.

public Task<AuthToken> CreateAsync(CreateAuthTokenRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateAuthTokenRequest

The request body.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<AuthToken>

The created token.