Table of Contents

Class VertextPlatformAdapter

Namespace
GenerativeAI
Assembly
GenerativeAI.dll

The VertextPlatformAdapter class provides authentication, configuration, and utility methods for interacting with Vertex AI.

public class VertextPlatformAdapter : IPlatformAdapter
Inheritance
VertextPlatformAdapter
Implements
Inherited Members
Extension Methods

Constructors

VertextPlatformAdapter(string, string, IGoogleAuthenticator, string?, bool, ILogger?)

Constructor for setting mandatory fields for Vertex AI operations.

public VertextPlatformAdapter(string projectId, string region, IGoogleAuthenticator authenticator, string? apiVersion = null, bool validateAccessToken = true, ILogger? logger = null)

Parameters

projectId string

The Google Cloud Project ID.

region string

The region for Vertex AI.

authenticator IGoogleAuthenticator

The authenticator to be used for authentication.

apiVersion string

The API version to use. Defaults to GOOGLE_GENAI_API_VERSION if set, otherwise v1beta1.

validateAccessToken bool

Boolean flag for validating the access token.

logger ILogger

Optional logger instance for diagnostics.

VertextPlatformAdapter(string?, string?, bool, string?, string?, string?, IGoogleAuthenticator?, string?, bool, ILogger?)

Constructor for initializing the adapter using environment variables or manual parameters.

public VertextPlatformAdapter(string? projectId = null, string? region = null, bool expressMode = false, string? apiKey = null, string? accessToken = null, string? apiVersion = null, IGoogleAuthenticator? authenticator = null, string? credentialsFile = null, bool validateAccessToken = true, ILogger? logger = null)

Parameters

projectId string

The Google Cloud Project ID.

region string

The region for Vertex AI.

expressMode bool

Flag to denote if Express Mode should be used.

apiKey string

Optional API key for authentication.

accessToken string

Optional access token for authentication.

apiVersion string

The API version to use. Defaults to GOOGLE_GENAI_API_VERSION if set, otherwise v1beta1.

authenticator IGoogleAuthenticator

Optional authenticator instance for custom token management.

credentialsFile string

Path to the credentials file.

validateAccessToken bool

Whether access tokens should be validated before use.

logger ILogger

Optional logger instance for diagnostics.

Properties

Authenticator

The authenticator interface responsible for obtaining access tokens.

public IGoogleAuthenticator? Authenticator { get; set; }

Property Value

IGoogleAuthenticator

CredentialFile

The path to the credentials file.

public string? CredentialFile { get; set; }

Property Value

string

Credentials

The credentials object containing API key and access token.

public GoogleAICredentials? Credentials { get; set; }

Property Value

GoogleAICredentials

DefaultApiVersion

The default API version to use when making requests.

public string DefaultApiVersion { get; set; }

Property Value

string

ExpressMode

Indicates whether Express Mode is enabled.

public bool? ExpressMode { get; }

Property Value

bool?

ProjectId

The Google Cloud Project ID.

public string? ProjectId { get; }

Property Value

string

Publisher

Publisher information, defaulting to "google".

public string Publisher { get; set; }

Property Value

string

Region

The region in which the Vertex AI service is hosted.

public string Region { get; }

Property Value

string

Methods

AddAuthorizationAsync(HttpRequestMessage, bool, CancellationToken)

Adds authorization headers to an HTTP request.

public Task AddAuthorizationAsync(HttpRequestMessage request, bool requireAccessToken, CancellationToken cancellationToken = default)

Parameters

request HttpRequestMessage

The HTTP request message to be modified.

requireAccessToken bool

Indicates if an access token is required.

cancellationToken CancellationToken

Optional cancellation token for task cancellation.

Returns

Task

AuthorizeAsync(CancellationToken)

Authorizes the request by generating or refreshing the access token.

public Task AuthorizeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token for task cancellation.

Returns

Task

CreateUrlForModel(string, string)

Generates the URL for a specific model and task.

public string CreateUrlForModel(string modelId, string task)

Parameters

modelId string

The model ID.

task string

The specific task to perform.

Returns

string

The constructed URL as a string.

CreateUrlForTunedModel(string, string)

Generates the URL for a specific tuned model and task.

public string CreateUrlForTunedModel(string modelId, string task)

Parameters

modelId string

The tuned model ID.

task string

The specific task to perform.

Returns

string

The constructed URL as a string.

GetAccessTokenAsync(CancellationToken)

Retrieves the access token required for making authenticated API requests.

public Task<AuthTokens?> GetAccessTokenAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token to cancel the operation if needed.

Returns

Task<AuthTokens>

A task that represents the asynchronous operation, containing the authentication tokens.

GetApiVersion()

Retrieves the current API version used by the platform.

public string GetApiVersion()

Returns

string

The API version as a string.

GetApiVersionForFile()

Retrieves the API version specifically for file operations.

public string GetApiVersionForFile()

Returns

string

The API version as an object (v1Beta by default).

GetBaseUrl(bool, bool, bool, bool)

Constructs the base URL for API requests with optional components. Pattern: https://{region}-aiplatform.googleapis.com/{version}/projects/{projectId}/locations/{region}/publishers/{publisher}

public string GetBaseUrl(bool appendVersion = true, bool appendPublisher = true, bool appendLocation = true, bool appendProject = true)

Parameters

appendVersion bool

Indicates whether to append the version to the URL.

appendPublisher bool

Indicates whether to append the publisher to the URL.

appendLocation bool

Indicates whether to include the location/region in the URL.

appendProject bool

Indicates whether to include the project ID in the URL.

Returns

string

The constructed base URL string.

GetBaseUrlForFile()

Gets the base URL specifically for file-related operations.

public string GetBaseUrlForFile()

Returns

string

The constructed base URL string for file operations.

GetFullyQualifiedModelName(string, bool)

Gets the formatted model name for multi-modal live sessions.

public string? GetFullyQualifiedModelName(string modelName, bool appendLocation = true)

Parameters

modelName string

The base model name to format.

appendLocation bool

Whether to include the location segment in the qualified name.

Returns

string

The formatted model name for multi-modal live sessions, or null if not applicable.

GetMultiModalLiveUrl(string)

Gets the WebSocket URL for multi-modal live sessions.

public string GetMultiModalLiveUrl(string version = "v1alpha")

Parameters

version string

The API version to use (default: "v1alpha").

Returns

string

The WebSocket URL for multi-modal live sessions.

SetAuthenticator(IGoogleAuthenticator)

Sets the Google authenticator responsible for managing authentication processes for Google services.

public void SetAuthenticator(IGoogleAuthenticator authenticator)

Parameters

authenticator IGoogleAuthenticator

The Google authenticator to be used for handling authentication operations.

ValidateCredentialsAsync(CancellationToken)

Validates the credentials and refreshes the token if necessary.

public Task ValidateCredentialsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token for task cancellation.

Returns

Task