> ## AI Agent Context > Get the complete documentation index at: https://aistudio.google.com/llms.txt > Use this file to discover all available pages. > For the full documentation in a single file, fetch: https://aistudio.google.com/llms-full.txt # Getting environment files {% callout type="note" %} This API is in Beta. Endpoints are under `/v1beta/`. {% /callout %} {% mark class="http-get" %}{% icon name="south_west" /%}`GET`{% /mark %} `https://generativelanguage.googleapis.com/v1beta/environments/{environment}/files/{path}` Retrieves file metadata or directory contents from an environment's snapshot. To download file content, use the download URL returned in the response. {% two-column-layout %} {% left-column %} ## Parameters {% class="hide-from-toc" id="parameters" %} {% section class="api-ref-property-list" %} **page_size**: `integer` Optional. Maximum number of entries to return per page (for directory listing). {% hr /%} **page_token**: `string` Optional. Pagination token for directory listing. {% hr /%} **recursive**: `boolean` Optional. If true and the path is a directory, recursively lists all files. {% /section %} {% /left-column %} {% right-column class="sticky" %} **Example request** {% class="example-heading" %} {% tabs %} {% tab label="List Files" %} {% tabs %} {% tab label="REST" %} ```sh curl -X GET 'https://generativelanguage.googleapis.com/v1beta/environments/env_abc123/files/src' \ -H "x-goog-api-key: $GEMINI_API_KEY" ``` {% /tab %} {% tab label="Python" %} ```python from google import genai client = genai.Client() response = client.environments.files.list( environment=created.id, path="src", ) for file in response.files or []: print(file.name, file.type, file.size_bytes) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import {GoogleGenAI} from '@google/genai'; const ai = new GoogleGenAI({}); const response = await ai.environments.files.list({ environment: created.id, path: 'src', }); for (const file of response.files ?? []) { console.log(file.name, file.type, file.size_bytes); } ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.environments.EnvironmentFile; import com.google.genai.gaos.models.operations.GetEnvironmentFilesRequest; import com.google.genai.gaos.models.environments.GetEnvironmentFilesResponse; Client client = new Client(); com.google.genai.gaos.models.operations.GetEnvironmentFilesResponse response = client .environments .files() .list(GetEnvironmentFilesRequest.builder().environment(envId).path("src").build()); GetEnvironmentFilesResponse filesResponse = response.getEnvironmentFilesResponse().orElseThrow(); for (EnvironmentFile file : filesResponse.files().orElse(List.of())) { System.out.println( file.name().orElse("") + " " + file.type().map(Object::toString).orElse("") + " " + file.sizeBytes().orElse("")); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "fmt" "log" "google.golang.org/genai" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Environments.Files.List(ctx, operations.GetEnvironmentFilesRequest{ Environment: envID, Path: "src", }) if err != nil { log.Fatal(err) } if res.GetEnvironmentFilesResponse != nil { for _, file := range res.GetEnvironmentFilesResponse.Files { name := "" if file.Name != nil { name = *file.Name } fileType := "" if file.Type != nil { fileType = string(*file.Type) } var size int64 if file.SizeBytes != nil { size = *file.SizeBytes } fmt.Println(name, fileType, size) } } } ``` {% /tab %} {% /tabs %} {% /tab %} {% tab label="Get File" %} {% tabs %} {% tab label="REST" %} ```sh curl -X GET 'https://generativelanguage.googleapis.com/v1beta/environments/env_abc123/files/main.py' \ -H "x-goog-api-key: $GEMINI_API_KEY" ``` {% /tab %} {% tab label="Python" %} ```python from google import genai client = genai.Client() response = client.environments.files.get( environment=created.id, path="main.py", ) for file in response.files or []: print(file.name, file.size_bytes) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import {GoogleGenAI} from '@google/genai'; const ai = new GoogleGenAI({}); const response = await ai.environments.files.list({ environment: created.id, path: 'main.py', }); for (const file of response.files ?? []) { console.log(file.name, file.size_bytes); } ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.environments.EnvironmentFile; import com.google.genai.gaos.models.operations.GetEnvironmentFilesRequest; import com.google.genai.gaos.models.environments.GetEnvironmentFilesResponse; Client client = new Client(); com.google.genai.gaos.models.operations.GetEnvironmentFilesResponse response = client .environments .files() .list(GetEnvironmentFilesRequest.builder().environment(envId).path("main.py").build()); GetEnvironmentFilesResponse filesResponse = response.getEnvironmentFilesResponse().orElseThrow(); for (EnvironmentFile file : filesResponse.files().orElse(List.of())) { System.out.println(file.name().orElse("") + " " + file.sizeBytes().orElse("")); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "fmt" "log" "google.golang.org/genai" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Environments.Files.List(ctx, operations.GetEnvironmentFilesRequest{ Environment: envID, Path: "main.py", }) if err != nil { log.Fatal(err) } if res.GetEnvironmentFilesResponse != nil { for _, file := range res.GetEnvironmentFilesResponse.Files { name := "" if file.Name != nil { name = *file.Name } var size int64 if file.SizeBytes != nil { size = *file.SizeBytes } fmt.Println(name, size) } } } ``` {% /tab %} {% /tabs %} {% /tab %} {% tab label="Download File" %} {% tabs %} {% tab label="REST" %} ```sh curl -X GET 'https://generativelanguage.googleapis.com/v1beta/environments/env_abc123/files/src/main.py?alt=media' \ -H "x-goog-api-key: $GEMINI_API_KEY" \ --output main.py ``` {% /tab %} {% tab label="Python" %} ```python from google import genai client = genai.Client() content = client.environments.files.download( environment=created.id, path="src/main.py", ) print(content.decode("utf-8")) ``` {% /tab %} {% /tabs %} {% /tab %} {% /tabs %} {% /right-column %} {% /two-column-layout %} ## Response {% class="hide-from-toc" id="response" %} {% section class="api-ref-property-list" %} {% details %} {% summary %} **files**: `EnvironmentFile array` If the requested path is a directory, this contains its contents. If the requested path is a file, this contains a single entry with the file's metadata. If alt=media was specified, this is empty (content is served via `blob`). {% /summary %} **name**: `string` Output only. The name of the file or directory (e.g., "main.py" or "src"). **path**: `string` Output only. The full relative path within the environment (e.g., "workspace/src/main.py"). {% details %} {% summary %} **type**: `string enum` Output only. The type of the entry. {% /summary %} Possible values: - `file`: A regular file. - `directory`: A directory. {% /details %} **size_bytes**: `string` Output only. The size of the file/directory in bytes. NOLINT **mime_type**: `string` Output only. The MIME type of the file (e.g., "text/python", "image/png"). Empty for directories. NOLINT **created**: `string` Output only. The creation time of the file/directory. **modified**: `string` Output only. The modification time of the file/directory. {% /details %} {% hr /%} **next_page_token**: `string` Pagination token for directory listing. NOLINT {% /section %}