List environment files
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.
/agents/environments/{environment_id}/filesPath parameters
environment_idstringRequiredEnvironment ID, format env_<ULID>
Query parameters
pathstringOptionalDirectory path, optional, restricts results to an existing absolute directory under /workspace/
limitintegerOptionalNumber of items per page
pagestringOptionalPagination 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
objectstringPage object type, fixed as page
dataarrayEnvironment files on this page
nextstring / nullCursor for the next page; null when there is no next page
has_morebooleanWhether 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_idstringEnvironment ID
objectstringEnvironment file object type, fixed as agent.environment.file
pathstringFile path in the environment
size_bytesintegerFile 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 status | Error type / code | Solution |
|---|---|---|
400 | invalid_request_error / invalid_request_error | Pass an existing absolute directory under /workspace/ |
404 | not_found_error / not_found_error | Use 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.