Table of Contents

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

platform IPlatformAdapter

The platform adapter (Google AI or Vertex AI).

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional logger.

Methods

CreateAsync(CreateEnvironmentRequest?, CancellationToken)

Creates an environment (POST /environments).

public Task<AgentEnvironment> CreateAsync(CreateEnvironmentRequest? request = null, CancellationToken cancellationToken = default)

Parameters

request CreateEnvironmentRequest

The request (all fields optional).

cancellationToken CancellationToken

A 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

id string

The environment ID.

cancellationToken CancellationToken

A 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

environmentId string

The environment ID.

path string

The file path relative to the workspace root.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<byte[]>

The file content.

GetAsync(string, CancellationToken)

Gets an environment (GET /environments/{id}).

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

Parameters

id string

The environment ID (an environments/ prefix is accepted).

cancellationToken CancellationToken

A 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

pageSize int?

The page size.

cancellationToken CancellationToken

A 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

environmentId string

The environment ID.

path string

The path relative to the workspace root (empty for the root).

recursive bool?

Whether to list subdirectories recursively.

pageSize int?

The page size.

cancellationToken CancellationToken

A 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

pageSize int?

The maximum number of environments per page.

pageToken string

The page token of a previous call.

cancellationToken CancellationToken

A 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

environmentId string

The environment ID.

path string

The path relative to the workspace root (empty for the root).

recursive bool?

Whether to list subdirectories recursively.

pageSize int?

The maximum number of entries per page.

pageToken string

The page token of a previous call.

cancellationToken CancellationToken

A 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

environmentId string

The environment ID.

path string

The destination path relative to the workspace root.

content Stream

The content, read from its current position. Like the other upload methods of this SDK, the stream is disposed once the upload request completes.

mimeType string

The MIME type (default application/octet-stream).

overwrite bool?

Whether to overwrite an existing file.

extract bool?

Whether to treat the content as a tar/tar.gz archive and unpack it into path.

progressCallback Action<double>

Optional upload progress callback (percentage).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<ListEnvironmentFilesResponse>

The uploaded file(s).

UploadFileAsync(string, string, string, 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

environmentId string

The environment ID.

path string

The destination path relative to the workspace root.

filePath string

The local file.

mimeType string

The MIME type (guessed from the file name when omitted).

overwrite bool?

Whether to overwrite an existing file.

extract bool?

Whether to treat the file as a tar/tar.gz archive and unpack it into path.

progressCallback Action<double>

Optional upload progress callback (percentage).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<ListEnvironmentFilesResponse>

The uploaded file(s).