Class EnvironmentsClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
A client for the Environments API (/environments): sandbox environments used by agent interactions, with
mounted sources (e.g. your own GCS bucket, inline files, repositories) and workspace files that can be listed,
uploaded (resumable upload, optionally extracting a tar archive) and downloaded. Follows python-genai's
client.environments (experimental).
public class EnvironmentsClient : AgentApiClientBase
- Inheritance
-
EnvironmentsClient
- Inherited Members
- Extension Methods
Constructors
EnvironmentsClient(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the EnvironmentsClient class.
public EnvironmentsClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)
Parameters
platformIPlatformAdapterThe platform adapter (Google AI or Vertex AI).
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional logger.
Methods
CreateAsync(CreateEnvironmentRequest?, CancellationToken)
Creates an environment (POST /environments).
public Task<AgentEnvironment> CreateAsync(CreateEnvironmentRequest? request = null, CancellationToken cancellationToken = default)
Parameters
requestCreateEnvironmentRequestThe request (all fields optional).
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<AgentEnvironment>
The created environment.
DeleteAsync(string, CancellationToken)
Deletes an environment (DELETE /environments/{id}).
public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe environment ID.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task
A task that completes when the environment has been deleted.
DownloadFileAsync(string, string, CancellationToken)
Downloads a file from an environment workspace
(GET /environments/{environment}/files/{path}?alt=media).
public Task<byte[]> DownloadFileAsync(string environmentId, string path, CancellationToken cancellationToken = default)
Parameters
environmentIdstringThe environment ID.
pathstringThe file path relative to the workspace root.
cancellationTokenCancellationTokenA cancellation token.
Returns
GetAsync(string, CancellationToken)
Gets an environment (GET /environments/{id}).
public Task<AgentEnvironment> GetAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe environment ID (an
environments/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<AgentEnvironment>
The environment.
ListAllAsync(int?, CancellationToken)
Lists all environments, following page tokens.
public IAsyncEnumerable<AgentEnvironment> ListAllAsync(int? pageSize = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?The page size.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<AgentEnvironment>
The environments.
ListAllFilesAsync(string, string?, bool?, int?, CancellationToken)
Lists all entries under a path in an environment workspace, following page tokens.
public IAsyncEnumerable<EnvironmentFile> ListAllFilesAsync(string environmentId, string? path = null, bool? recursive = null, int? pageSize = null, CancellationToken cancellationToken = default)
Parameters
environmentIdstringThe environment ID.
pathstringThe path relative to the workspace root (empty for the root).
recursivebool?Whether to list subdirectories recursively.
pageSizeint?The page size.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<EnvironmentFile>
The entries.
ListAsync(int?, string?, CancellationToken)
Lists one page of environments (GET /environments).
public Task<ListEnvironmentsResponse> ListAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?The maximum number of environments per page.
pageTokenstringThe page token of a previous call.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<ListEnvironmentsResponse>
The page.
ListFilesAsync(string, string?, bool?, int?, string?, CancellationToken)
Lists one page of the contents of a directory (or a single file) in an environment workspace
(GET /environments/{environment}/files/{path}).
public Task<ListEnvironmentFilesResponse> ListFilesAsync(string environmentId, string? path = null, bool? recursive = null, int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
environmentIdstringThe environment ID.
pathstringThe path relative to the workspace root (empty for the root).
recursivebool?Whether to list subdirectories recursively.
pageSizeint?The maximum number of entries per page.
pageTokenstringThe page token of a previous call.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<ListEnvironmentFilesResponse>
The page.
UploadFileAsync(string, string, Stream, string?, bool?, bool?, Action<double>?, CancellationToken)
Uploads a file into an environment workspace with the resumable upload protocol: a start request to
PUT /upload/{version}/environments/{environment}/files/{path} followed by an upload, finalize
request with the bytes to the returned session URL.
public Task<ListEnvironmentFilesResponse> UploadFileAsync(string environmentId, string path, Stream content, string? mimeType = null, bool? overwrite = null, bool? extract = null, Action<double>? progressCallback = null, CancellationToken cancellationToken = default)
Parameters
environmentIdstringThe environment ID.
pathstringThe destination path relative to the workspace root.
contentStreamThe content, read from its current position. Like the other upload methods of this SDK, the stream is disposed once the upload request completes.
mimeTypestringThe MIME type (default
application/octet-stream).overwritebool?Whether to overwrite an existing file.
extractbool?Whether to treat the content as a tar/tar.gz archive and unpack it into
path.progressCallbackAction<double>Optional upload progress callback (percentage).
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<ListEnvironmentFilesResponse>
The uploaded file(s).
UploadFileAsync(string, string, string, string?, bool?, bool?, Action<double>?, CancellationToken)
Uploads a local file into an environment workspace (see UploadFileAsync(string, string, Stream, string?, bool?, bool?, Action<double>?, CancellationToken)).
public Task<ListEnvironmentFilesResponse> UploadFileAsync(string environmentId, string path, string filePath, string? mimeType = null, bool? overwrite = null, bool? extract = null, Action<double>? progressCallback = null, CancellationToken cancellationToken = default)
Parameters
environmentIdstringThe environment ID.
pathstringThe destination path relative to the workspace root.
filePathstringThe local file.
mimeTypestringThe MIME type (guessed from the file name when omitted).
overwritebool?Whether to overwrite an existing file.
extractbool?Whether to treat the file as a tar/tar.gz archive and unpack it into
path.progressCallbackAction<double>Optional upload progress callback (percentage).
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<ListEnvironmentFilesResponse>
The uploaded file(s).