---
title: "创建 Environment"
method: POST
path: "/agent/managed/v1/environments"
tags: ["Managed Agents - Environment"]
---

# 创建 Environment

`POST /agent/managed/v1/environments`

## Request

- Base URL: `https://agent-api.bigmodel.cn/api`
- URL: `https://agent-api.bigmodel.cn/api/agent/managed/v1/environments`
- Auth: HTTP bearer

创建供 Managed Session 和 Deployment 使用的云端 Environment。可配置预装软件包和网络策略；省略配置时使用平台默认设置。

## Headers

- `zai-version` '2026-05-26', required
- `zai-beta` string, required

## Request body

- ManagedEnvironmentCreateRequest: 创建 Environment。config 内出现未支持的字段时请求会被拒绝。
  - `name` string, required: Environment 名称，长度 1–256 个字符。
  - `description` string, nullable: 用途说明；省略或传 null 时不设置。
  - `metadata` ManagedMetadata: 客户端自定义元数据；省略时默认为空对象。最多 16 个键，键名长度不超过 64 字符，值必须是长度不超过 512 字符的字符串。
  - `scope` 'organization', nullable: 公开 API 仅支持 organization；省略或传 null 时也使用 organization。
  - `config` ManagedEnvironmentConfigInput
    - `type` 'cloud', required: 当前只支持 cloud；self_hosted 会被拒绝。
    - `packages` ManagedEnvironmentPackagesInput: 声明需要预装的包；六类包管理器均可省略，省略或 null 会规范化为空数组。
      - `type` 'packages': 可选判别字段；提供时只能为 packages。
      - `apt` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
      - `cargo` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
      - `gem` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
      - `go` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
      - `npm` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
      - `pip` string[], nullable: 最多 200 个不同包名；null/省略视为空数组，重复项会去重。每项 trim 后不能为空、不能包含空白或控制字符，也不能以 - 开头。
    - `networking` union: 网络策略。省略整个 networking 时默认为 unrestricted；所有模式的出站端口均限 HTTP/HTTPS 80/443。
      - object
        - `type` 'unrestricted', required
      - object
        - `type` 'limited', required
        - `allowed_hosts` string[], nullable: 最多 256 个不同 host；null/省略视为空数组，重复项会去重。只接受 hostname 或 *.example.com 通配形式，不得包含协议、端口或路径。
        - `allow_package_managers` boolean, nullable: 是否允许包管理器联网；省略或传 null 时为 false。limited 模式声明 packages 时必须显式设为 true。
        - `allow_mcp_servers` boolean, nullable: 是否允许已配置的 MCP Server 联网；省略或传 null 时为 false。

## Response `200`

请求成功。

- ManagedEnvironment
  - `id` string, required: Environment ID。
  - `type` 'environment', required
  - `name` string, required
  - `description` string, nullable, required: 用途说明。
  - `metadata` ManagedMetadata, required: 客户端自定义元数据；省略时默认为空对象。最多 16 个键，键名长度不超过 64 字符，值必须是长度不超过 512 字符的字符串。
  - `config` ManagedEnvironmentConfigResponse, required
    - `type` 'cloud', required
    - `packages` ManagedEnvironmentPackagesResponse, required
      - `type` 'packages', required
      - `apt` string[], required
      - `cargo` string[], required
      - `gem` string[], required
      - `go` string[], required
      - `npm` string[], required
      - `pip` string[], required
    - `networking` union, required
      - object
        - `type` 'unrestricted', required
      - object
        - `type` 'limited', required
        - `allowed_hosts` string[], required
        - `allow_package_managers` boolean, required
        - `allow_mcp_servers` boolean, required
  - `scope` 'organization', required
  - `state` 'active' | 'archived', required
  - `archived_at` string, nullable, required: 归档时间。
  - `created_at` string, date-time, required: 创建时间。
  - `updated_at` string, date-time, required: 更新时间。

## Other responses

- `default`: 请求失败。

## Changes

- **2026-11-03** `7fd61aa7f811`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/bigmodel/apis/zhipu-ai-api/changes/agent/managed/v1/environments/post.md)

---

[API](https://skmtc.dev/bigmodel/apis/zhipu-ai-api.md) - [All operations](https://skmtc.dev/bigmodel/apis/zhipu-ai-api/llms.txt) - [OpenAPI document](https://skmtc.dev/bigmodel/apis/zhipu-ai-api/revisions/f2be7c0fcbb9?raw)
