List source files

Updated at:

List Agent API source files in the current workspace with cursor pagination.

Endpoint

Returns 200 and a list envelope. Only source files uploaded through the Agent API in the current workspace are returned; artifacts and live environment files are not included.

GET/agents/file

Query parameters

limitintegerOptional

Number of items per page, default 20; 1..100 is recommended

orderstringOptional

Sort direction, asc or desc, defaults to desc

afterstringOptional

The last_id from the previous page; the cursor item is excluded

beforestringOptional

The first_id from the previous page, for reverse pagination; cannot be used with after

Passing both after and before returns 400. A cursor that does not exist, has been deleted, or belongs to another workspace returns 404.

Request example

curl -sS "$BASE_URL/agents/file?limit=20&order=desc" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "OpenAI-Beta: agents=v1"
import os
import requests

resp = requests.get(
    f"{os.environ['BASE_URL']}/agents/file",
    params={"limit": 20, "order": "desc"},
    headers={"Authorization": f"Bearer {os.environ['DASHSCOPE_API_KEY']}"},
)
print(resp.status_code, resp.json())

Response fields

objectstring

List object type, fixed as list

dataarray

Source files on this page; [] when empty

first_idstring / null

First item ID on this page; null for an empty page

last_idstring / null

Last item ID on this page; null for an empty page; use it as after

has_moreboolean

Whether the current scan direction has another page

Each source file in data[] uses the same fields as the retrieve source file response.

Source file list items do not contain request_id; get the request identifier from the x-request-id response header.

data item

idstring

Source file ID

objectstring

Source file object type, fixed as file

bytesinteger

File size in bytes

created_atinteger

Creation time, Unix seconds

filenamestring

File name

statusstring

File status: uploaded, processed, or error. processed means the file is usable; uploaded means it is uploaded and undergoing content moderation; error means processing failed or content moderation did not pass

Response example

{
  "object": "list",
  "data": [
    {
      "id": "file_xxx",
      "object": "file",
      "bytes": 18,
      "created_at": 1794321796,
      "filename": "input.txt",
      "status": "processed"
    }
  ],
  "first_id": "file_xxx",
  "last_id": "file_xxx",
  "has_more": false
}

Error codes

HTTP statusError type / codeSolution
400invalid_request_error / invalid_request_errorFix limit, order, after, or before as described in the query parameters
401authentication_error / invalid_api_keySend a valid Authorization: Bearer $DASHSCOPE_API_KEY header
404not_found_error / not_found_errorUse a valid source file cursor in the current workspace
500server_error / server_errorRetry later. If it keeps failing, submit a ticket with x-request-id