List environment files

Updated at:

Query files already on disk in an environment with directory pagination.

Endpoint

Queries live files in the specified environment. A successful call returns 200 and directory pagination. This endpoint verifies that files are on disk and does not return file content.

GET/agents/environments/{environment_id}/files

Path parameters

environment_idstringRequired

Environment ID, format env_<ULID>

Query parameters

pathstringOptional

Directory path, optional, restricts results to an existing absolute directory under /workspace/

limitintegerOptional

Number of items per page

pagestringOptional

Pagination cursor; omit on the first request, then pass the next returned by the previous page

The request parameter is page and the response cursor field is next; this is not the after cursor used by source files or artifacts.

Request example

curl -sS --get "$BASE_URL/agents/environments/ccarenv_xxx/files" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "OpenAI-Beta: agents=v1" \
  --data-urlencode "path=/workspace/input/" \
  --data-urlencode "limit=20"
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url=os.environ["BASE_URL"],
)

page = client.beta.agents.environments.files.list(
    "ccarenv_xxx",
    path="/workspace/input/",
    limit=20,
)
for environment_file in page.data:
    print(environment_file.path, environment_file.size_bytes)

Response fields

objectstring

Page object type, fixed as page

dataarray

Environment files on this page

nextstring / null

Cursor for the next page; null when there is no next page

has_moreboolean

Whether another page exists

Each item in data[] contains:

The response contains a data array for the current page and a cursor for the next page. When the directory is empty, data is an empty array.

data item

environment_idstring

Environment ID

objectstring

Environment file object type, fixed as agent.environment.file

pathstring

File path in the environment

size_bytesinteger

File size in bytes

Response example

{
  "object": "page",
  "data": [
    {
      "environment_id": "ccarenv_xxx",
      "object": "agent.environment.file",
      "path": "/workspace/input/input.txt",
      "size_bytes": 18
    }
  ],
  "next": null,
  "has_more": false
}

Error codes

HTTP statusError type / codeSolution
400invalid_request_error / invalid_request_errorPass an existing absolute directory under /workspace/
404not_found_error / not_found_errorUse an environment ID that exists and is visible in the current workspace

The error body has the shape {"error":{"type","code","message","param"}}. Gateway errors can use a different structure.