Table of Contents

Class CredentialsClient

Namespace
GenerativeAI.Clients
Assembly
GenerativeAI.dll

A client for the Credentials API (/credentials): store secrets (environment variables, bearer tokens, OAuth 2.0 refresh tokens) that agent environments can use without exposing them. Secrets are write-only. Follows python-genai's client.credentials (experimental).

public class CredentialsClient : AgentApiClientBase
Inheritance
CredentialsClient
Inherited Members
Extension Methods

Constructors

CredentialsClient(IPlatformAdapter, HttpClient?, ILogger?)

Initializes a new instance of the CredentialsClient class.

public CredentialsClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter

The platform adapter (Google AI or Vertex AI).

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional logger.

Methods

CreateAsync(CredentialConfig, CancellationToken)

Creates a credential (POST /credentials).

public Task<Credential> CreateAsync(CredentialConfig config, CancellationToken cancellationToken = default)

Parameters

config CredentialConfig

The credential: EnvironmentVariableCredentialConfig, BearerTokenCredentialConfig or OAuth2CredentialConfig, with Id set.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Credential>

The created credential (without the secret).

DeleteAsync(string, CancellationToken)

Deletes a credential (DELETE /credentials/{id}).

public Task DeleteAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The credential ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that completes when the credential has been deleted.

GetAsync(string, CancellationToken)

Gets a credential (GET /credentials/{id}).

public Task<Credential> GetAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The credential ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Credential>

The credential (without the secret).

ListAllAsync(int?, CancellationToken)

Lists all credentials, following page tokens.

public IAsyncEnumerable<Credential> ListAllAsync(int? pageSize = null, CancellationToken cancellationToken = default)

Parameters

pageSize int?

The page size.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<Credential>

The credentials.

ListAsync(int?, string?, CancellationToken)

Lists one page of credentials (GET /credentials).

public Task<ListCredentialsResponse> ListAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)

Parameters

pageSize int?

The maximum number of credentials per page.

pageToken string

The page token of a previous call.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<ListCredentialsResponse>

The page.

UpdateAsync(string, CredentialConfig, string?, CancellationToken)

Updates a credential (PATCH /credentials/{id}). The type must match the stored credential; Id is not sent.

public Task<Credential> UpdateAsync(string id, CredentialConfig update, string? updateMask = null, CancellationToken cancellationToken = default)

Parameters

id string

The credential ID (a credentials/ prefix is accepted).

update CredentialConfig

The fields to update.

updateMask string

Optional comma-separated list of fields to update (sent as update_mask).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Credential>

The updated credential.