OpenAI 创建容器

2026-11-12 14:58 更新

创建容器

post /containers

创建容器。

请求体参数

内容类型:application/json

  • name: string

要创建的容器的名称。

  • expires_after: optional object { anchor, minutes }

相对于 anchor 时间的容器过期设置。原文此处写“秒”,但本对象使用 minutes 字段;依照下方字段定义,该值的单位为分钟。

  • anchor: "last_active_at"

计算过期时间所用的时间基点。目前仅支持 last_active_at。

  • "last_active_at"

  • minutes: integer

  • file_ids: optional array of string

要复制到容器中的文件 ID。

  • memory_limit: optional "1g" or "4g" or "16g" or "64g"

容器的可选内存上限,默认为 1g。

  • "1g"

  • "4g"

  • "16g"

  • "64g"

  • network_policy: optional ContainerNetworkPolicyDisabled or ContainerNetworkPolicyAllowlist

容器的网络访问策略。

  • ContainerNetworkPolicyDisabled object { type }

  • type: "disabled" (default: "disabled")

禁用出站网络访问。此分支的值始终为 disabled。

  • "disabled"

  • ContainerNetworkPolicyAllowlist object { allowed_domains, type, domain_secrets }

  • allowed_domains: array of string

type 为 allowlist 时允许访问的域名列表。

minItems: 1

  • type: "allowlist" (default: "allowlist")

仅允许出站访问指定域名。此分支的值始终为 allowlist。

  • "allowlist"

  • domain_secrets: optional array of ContainerNetworkPolicyDomainSecret

可选的域名级密钥,用于允许列表中的域名。

minItems: 1

  • domain: string

与此密钥关联的域名。

minLength: 1

  • name: string

要为该域名注入的密钥名称。

minLength: 1

  • value: string

要为该域名注入的密钥值。

minLength: 1, maxLength: 10485760

  • skills: optional array of SkillReference or InlineSkill

可选的技能列表,支持通过 ID 引用或直接内联数据。

  • SkillReference object { skill_id, type, version }

  • skill_id: string

所引用技能的 ID。

minLength: 1, maxLength: 64

  • type: "skill_reference" (default: "skill_reference")

引用通过 /v1/skills 端点创建的技能。

  • "skill_reference"

  • version: optional string

可选的技能版本。使用正整数或 latest;省略时使用默认版本。

  • InlineSkill object { description, name, source, type }

  • description: string

技能的描述。

  • name: string

技能的名称。

  • source: InlineSkillSource

内联技能载荷。

  • data: string

以 Base64 编码的技能 ZIP 包。

minLength: 1, maxLength: 70254592

  • media_type: "application/zip" (default: "application/zip")

内联技能载荷的媒体类型,必须为 application/zip。

  • "application/zip"

  • type: "base64" (default: "base64")

内联技能来源的类型,必须为 base64。

  • "base64"

  • type: "inline" (default: "inline")

为本次请求定义内联技能。

  • "inline"

返回值

  • id: string

容器的唯一标识符。

  • created_at: integer

创建容器时的 Unix 时间戳,单位为秒。

format: unixtime

  • name: string

容器的名称。

  • object: string

此对象的类型。

  • status: string

容器的状态,例如 active(活动)或 deleted(已删除)。

  • expires_after: optional object { anchor, minutes }

容器将在此时间段后过期。 anchor 是计算过期时间的基准时刻。 minutes 表示自基准时刻起、容器过期前经过的分钟数。

  • anchor: optional "last_active_at"

计算过期时间的基准时刻。

  • "last_active_at"

  • minutes: optional integer

自基准时刻起、容器过期前经过的分钟数。

  • last_active_at: optional integer

容器最近一次活动的 Unix 时间戳,单位为秒。

format: unixtime

  • memory_limit: optional "1g" or "4g" or "16g" or "64g"

为容器配置的内存上限。

  • "1g"

  • "4g"

  • "16g"

  • "64g"

  • network_policy: optional object { type, allowed_domains }

容器的网络访问策略。

  • type: "allowlist" or "disabled"

网络策略模式。

  • "allowlist"

  • "disabled"

  • allowed_domains: optional array of string

type 为 allowlist 时允许出站访问的域名。

示例

## 从环境变量读取 API 密钥;运行前替换容器、文件和技能等示例 ID。
curl https://api.openai.com/v1/containers \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
          "name": "name"
        }'

200 响应示例

{
  "id": "id",
  "created_at": 0,
  "name": "name",
  "object": "object",
  "status": "status",
  "expires_after": {
    "anchor": "last_active_at",
    "minutes": 0
  },
  "last_active_at": 0,
  "memory_limit": "1g",
  "network_policy": {
    "type": "allowlist",
    "allowed_domains": [
      "string"
    ]
  }
}

示例

## 从环境变量读取 API 密钥;运行前替换容器、文件和技能等示例 ID。
curl https://api.openai.com/v1/containers \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "name": "示例容器",
        "memory_limit": "4g",
        "skills": [
          {
            "type": "skill_reference",
            "skill_id": "skill_4db6f1a2c9e73508b41f9da06e2c7b5f"
          },
          {
            "type": "skill_reference",
            "skill_id": "openai-spreadsheets",
            "version": "latest"
          }
        ],
        "network_policy": {
          "type": "allowlist",
          "allowed_domains": ["api.buildkite.com"]
        }
      }'

响应示例

{
    "id": "cntr_682e30645a488191b6363a0cbefc0f0a025ec61b66250591",
    "object": "container",
    "created_at": 1747857508,
    "status": "running",
    "expires_after": {
        "anchor": "last_active_at",
        "minutes": 20
    },
    "last_active_at": 1747857508,
    "network_policy": {
        "type": "allowlist",
        "allowed_domains": ["api.buildkite.com"]
    },
    "memory_limit": "4g",
    "name": "示例容器"
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号