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
platformIPlatformAdapterThe platform adapter (Google AI or Vertex AI).
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional logger.
Methods
CreateAsync(CredentialConfig, CancellationToken)
Creates a credential (POST /credentials).
public Task<Credential> CreateAsync(CredentialConfig config, CancellationToken cancellationToken = default)
Parameters
configCredentialConfigThe credential: EnvironmentVariableCredentialConfig, BearerTokenCredentialConfig or OAuth2CredentialConfig, with Id set.
cancellationTokenCancellationTokenA 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
idstringThe credential ID.
cancellationTokenCancellationTokenA 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
idstringThe credential ID.
cancellationTokenCancellationTokenA 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
pageSizeint?The page size.
cancellationTokenCancellationTokenA 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
pageSizeint?The maximum number of credentials per page.
pageTokenstringThe page token of a previous call.
cancellationTokenCancellationTokenA 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
idstringThe credential ID (a
credentials/prefix is accepted).updateCredentialConfigThe fields to update.
updateMaskstringOptional comma-separated list of fields to update (sent as
update_mask).cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<Credential>
The updated credential.