List environments

Updated at:

List managed environments in the current workspace with cursor pagination.

Endpoint

Lists managed environments in the current workspace with cursor pagination. A successful call returns 200 and a list envelope.

GET/agents/environments

Query parameters

limitintegerOptional

Number of items per page, default 20, range 1–100

orderstringOptional

Sort direction, asc or desc, default desc

afterstringOptional

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

typestringOptional

Environment type; openai_hosted or bailian_hosted; the value is validated but does not filter results, so do not rely on it to distinguish managed environments

before currently returns 400.

Request example

curl -sS --get "$BASE_URL/agents/environments" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "OpenAI-Beta: agents=v1" \
  --data-urlencode "limit=20" \
  --data-urlencode "order=desc"
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.list(limit=20, order="desc")
while True:
    for environment in page.data:
        print(environment.id, environment.status)
    if not page.has_more:
        break
    page = page.get_next_page()

Response fields

objectstring

List object type, fixed as list

dataarray

Environments on the current page; can be empty

first_idstring / null

ID of the first item on the page; null for an empty page

last_idstring / null

ID of the last item on the page; null for an empty page

has_moreboolean

Whether the current direction has another page

An empty list:

Response example

{
  "object": "list",
  "data": [{
    "id": "ccarenv_xxx",
    "object": "agent.environment",
    "type": "openai_hosted",
    "status": "ready",
    "files": [],
    "skills": [],
    "plugins": []
  }],
  "first_id": "ccarenv_xxx",
  "last_id": "ccarenv_xxx",
  "has_more": false
}

Error codes

HTTP statusError type / codeSolution
400invalid_request_error / invalid_request_errorFix limit and order as described in the query parameters, and remove before
401invalid_request_error / workspace_required or user_requiredUse an API key for the current workspace

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